1*4882a593Smuzhiyunlibtraceevent(3) 2*4882a593Smuzhiyun================ 3*4882a593Smuzhiyun 4*4882a593SmuzhiyunNAME 5*4882a593Smuzhiyun---- 6*4882a593Smuzhiyuntep_register_print_function,tep_unregister_print_function - 7*4882a593SmuzhiyunRegisters / Unregisters a helper function. 8*4882a593Smuzhiyun 9*4882a593SmuzhiyunSYNOPSIS 10*4882a593Smuzhiyun-------- 11*4882a593Smuzhiyun[verse] 12*4882a593Smuzhiyun-- 13*4882a593Smuzhiyun*#include <event-parse.h>* 14*4882a593Smuzhiyun 15*4882a593Smuzhiyunenum *tep_func_arg_type* { 16*4882a593Smuzhiyun TEP_FUNC_ARG_VOID, 17*4882a593Smuzhiyun TEP_FUNC_ARG_INT, 18*4882a593Smuzhiyun TEP_FUNC_ARG_LONG, 19*4882a593Smuzhiyun TEP_FUNC_ARG_STRING, 20*4882a593Smuzhiyun TEP_FUNC_ARG_PTR, 21*4882a593Smuzhiyun TEP_FUNC_ARG_MAX_TYPES 22*4882a593Smuzhiyun}; 23*4882a593Smuzhiyun 24*4882a593Smuzhiyuntypedef unsigned long long (*pass:[*]tep_func_handler*)(struct trace_seq pass:[*]s, unsigned long long pass:[*]args); 25*4882a593Smuzhiyun 26*4882a593Smuzhiyunint *tep_register_print_function*(struct tep_handle pass:[*]_tep_, tep_func_handler _func_, enum tep_func_arg_type _ret_type_, char pass:[*]_name_, _..._); 27*4882a593Smuzhiyunint *tep_unregister_print_function*(struct tep_handle pass:[*]_tep_, tep_func_handler _func_, char pass:[*]_name_); 28*4882a593Smuzhiyun-- 29*4882a593Smuzhiyun 30*4882a593SmuzhiyunDESCRIPTION 31*4882a593Smuzhiyun----------- 32*4882a593SmuzhiyunSome events may have helper functions in the print format arguments. 33*4882a593SmuzhiyunThis allows a plugin to dynamically create a way to process one of 34*4882a593Smuzhiyunthese functions. 35*4882a593Smuzhiyun 36*4882a593SmuzhiyunThe _tep_register_print_function()_ registers such helper function. The _tep_ 37*4882a593Smuzhiyunargument is the trace event parser context. The _func_ argument is a pointer 38*4882a593Smuzhiyunto the helper function. The _ret_type_ argument is the return type of the 39*4882a593Smuzhiyunhelper function, value from the _tep_func_arg_type_ enum. The _name_ is the name 40*4882a593Smuzhiyunof the helper function, as seen in the print format arguments. The _..._ is a 41*4882a593Smuzhiyunvariable list of _tep_func_arg_type_ enums, the _func_ function arguments. 42*4882a593SmuzhiyunThis list must end with _TEP_FUNC_ARG_VOID_. See 'EXAMPLE' section. 43*4882a593Smuzhiyun 44*4882a593SmuzhiyunThe _tep_unregister_print_function()_ unregisters a helper function, previously 45*4882a593Smuzhiyunregistered with _tep_register_print_function()_. The _tep_ argument is the 46*4882a593Smuzhiyuntrace event parser context. The _func_ and _name_ arguments are the same, used 47*4882a593Smuzhiyunwhen the helper function was registered. 48*4882a593Smuzhiyun 49*4882a593SmuzhiyunThe _tep_func_handler_ is the type of the helper function. The _s_ argument is 50*4882a593Smuzhiyunthe trace sequence, it can be used to create a custom string. 51*4882a593SmuzhiyunThe _args_ is a list of arguments, defined when the helper function was 52*4882a593Smuzhiyunregistered. 53*4882a593Smuzhiyun 54*4882a593SmuzhiyunRETURN VALUE 55*4882a593Smuzhiyun------------ 56*4882a593SmuzhiyunThe _tep_register_print_function()_ function returns 0 in case of success. 57*4882a593SmuzhiyunIn case of an error, TEP_ERRNO_... code is returned. 58*4882a593Smuzhiyun 59*4882a593SmuzhiyunThe _tep_unregister_print_function()_ returns 0 in case of success, or -1 in 60*4882a593Smuzhiyuncase of an error. 61*4882a593Smuzhiyun 62*4882a593SmuzhiyunEXAMPLE 63*4882a593Smuzhiyun------- 64*4882a593SmuzhiyunSome events have internal functions calls, that appear in the print format 65*4882a593Smuzhiyunoutput. For example "tracefs/events/i915/g4x_wm/format" has: 66*4882a593Smuzhiyun[source,c] 67*4882a593Smuzhiyun-- 68*4882a593Smuzhiyunprint fmt: "pipe %c, frame=%u, scanline=%u, wm %d/%d/%d, sr %s/%d/%d/%d, hpll %s/%d/%d/%d, fbc %s", 69*4882a593Smuzhiyun ((REC->pipe) + 'A'), REC->frame, REC->scanline, REC->primary, 70*4882a593Smuzhiyun REC->sprite, REC->cursor, yesno(REC->cxsr), REC->sr_plane, 71*4882a593Smuzhiyun REC->sr_cursor, REC->sr_fbc, yesno(REC->hpll), REC->hpll_plane, 72*4882a593Smuzhiyun REC->hpll_cursor, REC->hpll_fbc, yesno(REC->fbc) 73*4882a593Smuzhiyun-- 74*4882a593SmuzhiyunNotice the call to function _yesno()_ in the print arguments. In the kernel 75*4882a593Smuzhiyuncontext, this function has the following implementation: 76*4882a593Smuzhiyun[source,c] 77*4882a593Smuzhiyun-- 78*4882a593Smuzhiyunstatic const char *yesno(int x) 79*4882a593Smuzhiyun{ 80*4882a593Smuzhiyun static const char *yes = "yes"; 81*4882a593Smuzhiyun static const char *no = "no"; 82*4882a593Smuzhiyun 83*4882a593Smuzhiyun return x ? yes : no; 84*4882a593Smuzhiyun} 85*4882a593Smuzhiyun-- 86*4882a593SmuzhiyunThe user space event parser has no idea how to handle this _yesno()_ function. 87*4882a593SmuzhiyunThe _tep_register_print_function()_ API can be used to register a user space 88*4882a593Smuzhiyunhelper function, mapped to the kernel's _yesno()_: 89*4882a593Smuzhiyun[source,c] 90*4882a593Smuzhiyun-- 91*4882a593Smuzhiyun#include <event-parse.h> 92*4882a593Smuzhiyun#include <trace-seq.h> 93*4882a593Smuzhiyun... 94*4882a593Smuzhiyunstruct tep_handle *tep = tep_alloc(); 95*4882a593Smuzhiyun... 96*4882a593Smuzhiyunstatic const char *yes_no_helper(int x) 97*4882a593Smuzhiyun{ 98*4882a593Smuzhiyun return x ? "yes" : "no"; 99*4882a593Smuzhiyun} 100*4882a593Smuzhiyun... 101*4882a593Smuzhiyun if ( tep_register_print_function(tep, 102*4882a593Smuzhiyun yes_no_helper, 103*4882a593Smuzhiyun TEP_FUNC_ARG_STRING, 104*4882a593Smuzhiyun "yesno", 105*4882a593Smuzhiyun TEP_FUNC_ARG_INT, 106*4882a593Smuzhiyun TEP_FUNC_ARG_VOID) != 0) { 107*4882a593Smuzhiyun /* Failed to register yes_no_helper function */ 108*4882a593Smuzhiyun } 109*4882a593Smuzhiyun 110*4882a593Smuzhiyun/* 111*4882a593Smuzhiyun Now, when the event parser encounters this yesno() function, it will know 112*4882a593Smuzhiyun how to handle it. 113*4882a593Smuzhiyun*/ 114*4882a593Smuzhiyun... 115*4882a593Smuzhiyun if (tep_unregister_print_function(tep, yes_no_helper, "yesno") != 0) { 116*4882a593Smuzhiyun /* Failed to unregister yes_no_helper function */ 117*4882a593Smuzhiyun } 118*4882a593Smuzhiyun-- 119*4882a593Smuzhiyun 120*4882a593SmuzhiyunFILES 121*4882a593Smuzhiyun----- 122*4882a593Smuzhiyun[verse] 123*4882a593Smuzhiyun-- 124*4882a593Smuzhiyun*event-parse.h* 125*4882a593Smuzhiyun Header file to include in order to have access to the library APIs. 126*4882a593Smuzhiyun*trace-seq.h* 127*4882a593Smuzhiyun Header file to include in order to have access to trace sequences 128*4882a593Smuzhiyun related APIs. Trace sequences are used to allow a function to call 129*4882a593Smuzhiyun several other functions to create a string of data to use. 130*4882a593Smuzhiyun*-ltraceevent* 131*4882a593Smuzhiyun Linker switch to add when building a program that uses the library. 132*4882a593Smuzhiyun-- 133*4882a593Smuzhiyun 134*4882a593SmuzhiyunSEE ALSO 135*4882a593Smuzhiyun-------- 136*4882a593Smuzhiyun_libtraceevent(3)_, _trace-cmd(1)_ 137*4882a593Smuzhiyun 138*4882a593SmuzhiyunAUTHOR 139*4882a593Smuzhiyun------ 140*4882a593Smuzhiyun[verse] 141*4882a593Smuzhiyun-- 142*4882a593Smuzhiyun*Steven Rostedt* <rostedt@goodmis.org>, author of *libtraceevent*. 143*4882a593Smuzhiyun*Tzvetomir Stoyanov* <tz.stoyanov@gmail.com>, author of this man page. 144*4882a593Smuzhiyun-- 145*4882a593SmuzhiyunREPORTING BUGS 146*4882a593Smuzhiyun-------------- 147*4882a593SmuzhiyunReport bugs to <linux-trace-devel@vger.kernel.org> 148*4882a593Smuzhiyun 149*4882a593SmuzhiyunLICENSE 150*4882a593Smuzhiyun------- 151*4882a593Smuzhiyunlibtraceevent is Free Software licensed under the GNU LGPL 2.1 152*4882a593Smuzhiyun 153*4882a593SmuzhiyunRESOURCES 154*4882a593Smuzhiyun--------- 155*4882a593Smuzhiyunhttps://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 156