1LIBTRACEEVENT(3)             libtraceevent Manual             LIBTRACEEVENT(3)
2
3
4

NAME

6       tep_register_print_function, tep_unregister_print_function - Registers
7       / Unregisters a helper function.
8

SYNOPSIS

10       #include <event-parse.h>
11
12       enum tep_func_arg_type {
13               TEP_FUNC_ARG_VOID,
14               TEP_FUNC_ARG_INT,
15               TEP_FUNC_ARG_LONG,
16               TEP_FUNC_ARG_STRING,
17               TEP_FUNC_ARG_PTR,
18               TEP_FUNC_ARG_MAX_TYPES
19       };
20
21       typedef unsigned long long (*tep_func_handler)(struct trace_seq *s, unsigned long long *args);
22
23       int tep_register_print_function(struct tep_handle *tep, tep_func_handler func, enum tep_func_arg_type ret_type, char *name, ...);
24       int tep_unregister_print_function(struct tep_handle *tep, tep_func_handler func, char *name);
25

DESCRIPTION

27       Some events may have helper functions in the print format arguments.
28       This allows a plugin to dynamically create a way to process one of
29       these functions.
30
31       The tep_register_print_function() registers such helper function. The
32       tep argument is the trace event parser context. The func argument is a
33       pointer to the helper function. The ret_type argument is the return
34       type of the helper function, value from the tep_func_arg_type enum. The
35       name is the name of the helper function, as seen in the print format
36       arguments. The ... is a variable list of tep_func_arg_type enums, the
37       func function arguments. This list must end with TEP_FUNC_ARG_VOID. See
38       EXAMPLE section.
39
40       The tep_unregister_print_function() unregisters a helper function,
41       previously registered with tep_register_print_function(). The tep
42       argument is the trace event parser context. The func and name arguments
43       are the same, used when the helper function was registered.
44
45       The tep_func_handler is the type of the helper function. The s argument
46       is the trace sequence, it can be used to create a custom string. The
47       args is a list of arguments, defined when the helper function was
48       registered.
49

RETURN VALUE

51       The tep_register_print_function() function returns 0 in case of
52       success. In case of an error, TEP_ERRNO_... code is returned.
53
54       The tep_unregister_print_function() returns 0 in case of success, or -1
55       in case of an error.
56

EXAMPLE

58       Some events have internal functions calls, that appear in the print
59       format output. For example "tracefs/events/i915/g4x_wm/format" has:
60
61           print fmt: "pipe %c, frame=%u, scanline=%u, wm %d/%d/%d, sr %s/%d/%d/%d, hpll %s/%d/%d/%d, fbc %s",
62                       ((REC->pipe) + 'A'), REC->frame, REC->scanline, REC->primary,
63                       REC->sprite, REC->cursor, yesno(REC->cxsr), REC->sr_plane,
64                       REC->sr_cursor, REC->sr_fbc, yesno(REC->hpll), REC->hpll_plane,
65                       REC->hpll_cursor, REC->hpll_fbc, yesno(REC->fbc)
66
67       Notice the call to function yesno() in the print arguments. In the
68       kernel context, this function has the following implementation:
69
70           static const char *yesno(int x)
71           {
72                   static const char *yes = "yes";
73                   static const char *no = "no";
74
75                   return x ? yes : no;
76           }
77
78       The user space event parser has no idea how to handle this yesno()
79       function. The tep_register_print_function() API can be used to register
80       a user space helper function, mapped to the kernel’s yesno():
81
82           #include <event-parse.h>
83           #include <trace-seq.h>
84           ...
85           struct tep_handle *tep = tep_alloc();
86           ...
87           static const char *yes_no_helper(int x)
88           {
89                   return x ? "yes" : "no";
90           }
91           ...
92                   if ( tep_register_print_function(tep,
93                                               yes_no_helper,
94                                               TEP_FUNC_ARG_STRING,
95                                               "yesno",
96                                               TEP_FUNC_ARG_INT,
97                                               TEP_FUNC_ARG_VOID) != 0) {
98                           /* Failed to register yes_no_helper function */
99                   }
100
101           /*
102              Now, when the event parser encounters this yesno() function, it will know
103              how to handle it.
104           */
105           ...
106                   if (tep_unregister_print_function(tep, yes_no_helper, "yesno") != 0) {
107                           /* Failed to unregister yes_no_helper function */
108                   }
109

FILES

111           event-parse.h
112                   Header file to include in order to have access to the library APIs.
113           trace-seq.h
114                   Header file to include in order to have access to trace sequences
115                   related APIs. Trace sequences are used to allow a function to call
116                   several other functions to create a string of data to use.
117           -ltraceevent
118                   Linker switch to add when building a program that uses the library.
119

SEE ALSO

121       libtraceevent(3), trace-cmd(1)
122

AUTHOR

124           Steven Rostedt <rostedt@goodmis.org[1]>, author of libtraceevent.
125           Tzvetomir Stoyanov <tz.stoyanov@gmail.com[2]>, author of this man page.
126

REPORTING BUGS

128       Report bugs to <linux-trace-devel@vger.kernel.org[3]>
129

LICENSE

131       libtraceevent is Free Software licensed under the GNU LGPL 2.1
132

RESOURCES

134       https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/
135

NOTES

137        1. rostedt@goodmis.org
138           mailto:rostedt@goodmis.org
139
140        2. tz.stoyanov@gmail.com
141           mailto:tz.stoyanov@gmail.com
142
143        3. linux-trace-devel@vger.kernel.org
144           mailto:linux-trace-devel@vger.kernel.org
145
146
147
148libtraceevent 1.5.3               04/15/2022                  LIBTRACEEVENT(3)
Impressum