tracef: minor fixes
[lttng-docs.git] / contents / using-lttng / instrumenting / c-application / tracef.md
CommitLineData
5e0cbfb0
PP
1---
2id: tracef
86384750 3since: 2.5
5e0cbfb0
PP
4---
5
6`tracef()` is a small LTTng-UST API to avoid defining your own
7tracepoints and tracepoint providers. The signature of `tracef()` is
8the same as `printf()`'s.
9
10The `tracef()` utility function was developed to make user space tracing
11super simple, albeit with notable disadvantages compared to custom,
12full-fledged tracepoint providers:
13
14 * All generated events have the same provider/event names, respectively
222d5975 15 `lttng_ust_tracef` and `event`.
5e0cbfb0
PP
16 * There's no static type checking.
17 * The only event field you actually get, named `msg`, is a string
18 potentially containing the values you passed to the function
19 using your own format. This also means that you cannot use filtering
20 using a custom expression at runtime because there are no isolated
21 fields.
22 * Since `tracef()` uses C standard library's `vasprintf()` function
23 in the background to format the strings at runtime, its
24 expected performance is lower than using custom tracepoint providers
25 with typed fields, which do not require a conversion to a string.
26
27Thus, `tracef()` is useful for quick prototyping and debugging, but
28should not be considered for any permanent/serious application
29instrumentation.
30
31To use `tracef()`, first include `<lttng/tracef.h>` in the C source file
32where you need to insert probes:
33
34~~~ c
35#include <lttng/tracef.h>
36~~~
37
4d46e8c0
PP
38Use `tracef()` like you would use `printf()` in your source code, for
39example:
5e0cbfb0
PP
40
41~~~ c
42 /* ... */
43
44 tracef("my message, my integer: %d", my_integer);
45
46 /* ... */
47~~~
48
49Link your application with `liblttng-ust`:
50
51<pre class="term">
52gcc -o app app.c <strong>-llttng-ust</strong>
53</pre>
54
55Execute the application as usual:
56
57<pre class="term">
58./app
59</pre>
60
61VoilĂ ! Use the `lttng` command line tool to
222d5975
PP
62[control tracing](#doc-controlling-tracing). You can enable `tracef()`
63events like this:
64
65<pre class="term">
66lttng enable-event --userspace 'lttng_ust_tracef:*'
67</pre>
This page took 0.025072 seconds and 4 git commands to generate.