Initial import
[lttng-docs.git] / contents / using-lttng / instrumenting / prebuilt-ust-helpers / liblttng-ust-cyg-profile.md
CommitLineData
5e0cbfb0
PP
1---
2id: liblttng‑ust‑cyg‑profile
3---
4
5Function tracing is the recording of which functions are entered and
6left during the execution of an application. Like with any LTTng event,
7the precise time at which this happens is also kept.
8
9GCC and clang have an option named
10<a href="https://gcc.gnu.org/onlinedocs/gcc-4.9.1/gcc/Code-Gen-Options.html" class="ext"><code>-finstrument-functions</code></a>
11which generates instrumentation calls for entry and exit to functions.
12The LTTng-UST function tracing helpers, `liblttng-ust-cyg-profile.so`
13and `liblttng-ust-cyg-profile-fast.so`, take advantage of this feature
14to add instrumentation to the two generated functions (which contain
15`cyg_profile` in their names, hence the shared object's name).
16
17In order to use LTTng-UST function tracing, the translation units to
18instrument must be built using the `-finstrument-functions` compiler
19flag.
20
21LTTng-UST function tracing comes in two flavors, each providing
22different trade-offs: `liblttng-ust-cyg-profile-fast.so` and
23`liblttng-ust-cyg-profile.so`.
24
25**`liblttng-ust-cyg-profile-fast.so`** is a lightweight variant that
26should only be used where it can be _guaranteed_ that the complete event
27stream is recorded without any missing events. Any kind of duplicate
28information is left out. This version registers the following
29tracepoints:
30
31<table class="func-desc">
32 <thead>
33 <tr>
34 <th><abbr title="Tracepoint">TP</abbr> provider name</th>
35 <th><abbr title="Tracepoint">TP</abbr> name</th>
36 <th>Description/fields</th>
37 </tr>
38 </thead>
39 <tbody>
40 <tr>
41 <td rowspan="2">
42 <code class="no-bg">lttng_ust_cyg_profile_fast</code>
43 </td>
44 <td>
45 <code class="no-bg">func_entry</code>
46 </td>
47 <td>
48 <p>Function entry</p>
49
50 <ul>
51 <li>
52 <code class="arg">addr</code>&nbsp;address of the
53 called function
54 </li>
55 </ul>
56 </td>
57 </tr>
58 <tr>
59 <td>
60 <code class="no-bg">func_exit</code>
61 </td>
62 <td>
63 <p>Function exit</p>
64 </td>
65 </tr>
66 </tbody>
67</table>
68
69Assuming no event is lost, having only the function addresses on entry
70is enough for creating a call graph (remember that a recorded event
71always contains the ID of the CPU that generated it). A tool like
72<a href="https://sourceware.org/binutils/docs/binutils/addr2line.html" class="ext"><code>addr2line</code></a>
73may be used to convert function addresses back to source files names
74and line numbers.
75
76The other helper,
77**`liblttng-ust-cyg-profile.so`**,
78is a more robust variant which also works for use cases where
79events might get discarded or not recorded from application startup.
80In these cases, the trace analyzer needs extra information to be
81able to reconstruct the program flow. This version registers the
82following tracepoints:
83
84<table class="func-desc">
85 <thead>
86 <tr>
87 <th><abbr title="Tracepoint">TP</abbr> provider name</th>
88 <th><abbr title="Tracepoint">TP</abbr> name</th>
89 <th>Description/fields</th>
90 </tr>
91 </thead>
92 <tbody>
93 <tr>
94 <td rowspan="2">
95 <code class="no-bg">lttng_ust_cyg_profile</code>
96 </td>
97 <td>
98 <code class="no-bg">func_entry</code>
99 </td>
100 <td>
101 <p>Function entry</p>
102
103 <ul>
104 <li>
105 <code class="arg">addr</code>&nbsp;address of the
106 called function
107 </li>
108 <li>
109 <code class="arg">call_site</code>&nbsp;call site
110 address
111 </li>
112 </ul>
113 </td>
114 </tr>
115 <tr>
116 <td>
117 <code class="no-bg">func_exit</code>
118 </td>
119 <td>
120 <p>Function exit</p>
121
122 <ul>
123 <li>
124 <code class="arg">addr</code>&nbsp;address of the
125 called function
126 </li>
127 <li>
128 <code class="arg">call_site</code>&nbsp;call site
129 address
130 </li>
131 </ul>
132 </td>
133 </tr>
134 </tbody>
135</table>
136
137To use one or the other variant with any user application, assuming at
138least one translation unit of the latter is compiled with the
139`-finstrument-functions` option, do:
140
141<pre class="term">
142LD_PRELOAD=liblttng-ust-cyg-profile-fast.so my-app
143</pre>
144
145or
146
147<pre class="term">
148LD_PRELOAD=liblttng-ust-cyg-profile.so my-app
149</pre>
150
151It might be necessary to limit the number of source files where
152`-finstrument-functions` is used to prevent excessive amount of trace
153data to be generated at runtime.
154
155<div class="tip">
156<p>
157 <span class="t">Tip:</span> When using GCC, at least, you may use
158 the
159 <code>-finstrument-functions-exclude-function-list</code>
160 option to avoid instrumenting entries and exits of specific
161 symbol names.
162</p>
163</div>
164
165All events generated from LTTng-UST function tracing are provided on
166log level `TRACE_DEBUG_FUNCTION`, which is useful to easily enable
167function tracing events in your tracing session using the
168`--loglevel-only` option of `lttng enable-event`
169(see [Controlling tracing](#doc-controlling-tracing)).
This page took 0.027385 seconds and 4 git commands to generate.