2 id: probing-the-application-source-code
5 Once tracepoints are properly defined within a tracepoint provider,
6 they may be inserted into the user application to be instrumented
7 using the `tracepoint()` macro. Its first argument is the tracepoint
8 provider name and its second is the tracepoint name. The next, optional
9 arguments are defined by the `TP_ARGS()` part of the definition of
10 the tracepoint to use.
12 As an example, let us again take the following tracepoint definition:
16 /* tracepoint provider name */
19 /* tracepoint/event name */
22 /* list of tracepoint arguments */
28 /* list of fields of eventual event */
30 ctf_string(my_string_field, my_string_arg)
31 ctf_integer(int, my_integer_field, my_integer_arg)
36 Assuming this is part of a file named `tp.h` which defines the tracepoint
37 provider and which is included by `tp.c`, here's a complete C application
38 calling this tracepoint (multiple times):
41 #define TRACEPOINT_DEFINE
44 int main(int argc, char* argv[])
48 tracepoint(my_provider, my_first_tracepoint, 23, "Hello, World!");
50 for (i = 0; i < argc; ++i) {
51 tracepoint(my_provider, my_first_tracepoint, i, argv[i]);
58 `TRACEPOINT_DEFINE` must be defined into exactly one translation unit (C
59 source file) of the user application, before including the tracepoint provider
60 header file. `TRACEPOINT_DEFINE` is discussed further in
61 [Building/linking tracepoint providers and the user application](#doc-building-tracepoint-providers-and-user-application).
63 As another example, remember this definition we wrote in a previous
64 section (comments are stripped):
68 #include <sys/types.h>
81 ctf_integer(int, my_constant_field, 23 + 17)
82 ctf_integer(int, my_int_arg_field, my_int_arg)
83 ctf_integer(int, my_int_arg_field2, my_int_arg * my_int_arg)
84 ctf_integer(int, sum4_field, my_str_arg[0] + my_str_arg[1] +
85 my_str_arg[2] + my_str_arg[3])
86 ctf_string(my_str_arg_field, my_str_arg)
87 ctf_integer_hex(off_t, size_field, st->st_size)
88 ctf_float(double, size_dbl_field, (double) st->st_size)
89 ctf_sequence_text(char, half_my_str_arg_field, my_str_arg,
90 size_t, strlen(my_str_arg) / 2)
95 Here's an example of calling it:
98 #define TRACEPOINT_DEFINE
105 stat("/etc/fstab", &s);
107 tracepoint(my_provider, my_tracepoint, 23, "Hello, World!", &s);
113 When viewing the trace, assuming the file size of `/etc/fstab` is
114 301 bytes, the event generated by the execution of this tracepoint
115 should have the following fields, in this order:
120 my_int_arg_field2 529
122 my_str_arg_field "Hello, World!"
125 half_my_str_arg_field "Hello,"