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