1*4882a593Smuzhiyunlibtraceevent(3) 2*4882a593Smuzhiyun================ 3*4882a593Smuzhiyun 4*4882a593SmuzhiyunNAME 5*4882a593Smuzhiyun---- 6*4882a593Smuzhiyuntep_register_event_handler, tep_unregister_event_handler - Register / 7*4882a593Smuzhiyununregisters a callback function to parse an event information. 8*4882a593Smuzhiyun 9*4882a593SmuzhiyunSYNOPSIS 10*4882a593Smuzhiyun-------- 11*4882a593Smuzhiyun[verse] 12*4882a593Smuzhiyun-- 13*4882a593Smuzhiyun*#include <event-parse.h>* 14*4882a593Smuzhiyun 15*4882a593Smuzhiyunenum *tep_reg_handler* { 16*4882a593Smuzhiyun _TEP_REGISTER_SUCCESS_, 17*4882a593Smuzhiyun _TEP_REGISTER_SUCCESS_OVERWRITE_, 18*4882a593Smuzhiyun}; 19*4882a593Smuzhiyun 20*4882a593Smuzhiyunint *tep_register_event_handler*(struct tep_handle pass:[*]_tep_, int _id_, const char pass:[*]_sys_name_, const char pass:[*]_event_name_, tep_event_handler_func _func_, void pass:[*]_context_); 21*4882a593Smuzhiyunint *tep_unregister_event_handler*(struct tep_handle pass:[*]tep, int id, const char pass:[*]sys_name, const char pass:[*]event_name, tep_event_handler_func func, void pass:[*]_context_); 22*4882a593Smuzhiyun 23*4882a593Smuzhiyuntypedef int (*pass:[*]tep_event_handler_func*)(struct trace_seq pass:[*]s, struct tep_record pass:[*]record, struct tep_event pass:[*]event, void pass:[*]context); 24*4882a593Smuzhiyun-- 25*4882a593Smuzhiyun 26*4882a593SmuzhiyunDESCRIPTION 27*4882a593Smuzhiyun----------- 28*4882a593SmuzhiyunThe _tep_register_event_handler()_ function registers a handler function, 29*4882a593Smuzhiyunwhich is going to be called to parse the information for a given event. 30*4882a593SmuzhiyunThe _tep_ argument is the trace event parser context. The _id_ argument is 31*4882a593Smuzhiyunthe id of the event. The _sys_name_ argument is the name of the system, 32*4882a593Smuzhiyunthe event belongs to. The _event_name_ argument is the name of the event. 33*4882a593SmuzhiyunIf _id_ is >= 0, it is used to find the event, otherwise _sys_name_ and 34*4882a593Smuzhiyun_event_name_ are used. The _func_ is a pointer to the function, which is going 35*4882a593Smuzhiyunto be called to parse the event information. The _context_ argument is a pointer 36*4882a593Smuzhiyunto the context data, which will be passed to the _func_. If a handler function 37*4882a593Smuzhiyunfor the same event is already registered, it will be overridden with the new 38*4882a593Smuzhiyunone. This mechanism allows a developer to override the parsing of a given event. 39*4882a593SmuzhiyunIf for some reason the default print format is not sufficient, the developer 40*4882a593Smuzhiyuncan register a function for an event to be used to parse the data instead. 41*4882a593Smuzhiyun 42*4882a593SmuzhiyunThe _tep_unregister_event_handler()_ function unregisters the handler function, 43*4882a593Smuzhiyunpreviously registered with _tep_register_event_handler()_. The _tep_ argument 44*4882a593Smuzhiyunis the trace event parser context. The _id_, _sys_name_, _event_name_, _func_, 45*4882a593Smuzhiyunand _context_ are the same arguments, as when the callback function _func_ was 46*4882a593Smuzhiyunregistered. 47*4882a593Smuzhiyun 48*4882a593SmuzhiyunThe _tep_event_handler_func_ is the type of the custom event handler 49*4882a593Smuzhiyunfunction. The _s_ argument is the trace sequence, it can be used to create a 50*4882a593Smuzhiyuncustom string, describing the event. A _record_ to get the event from is passed 51*4882a593Smuzhiyunas input parameter and also the _event_ - the handle to the record's event. The 52*4882a593Smuzhiyun_context_ is custom context, set when the custom event handler is registered. 53*4882a593Smuzhiyun 54*4882a593SmuzhiyunRETURN VALUE 55*4882a593Smuzhiyun------------ 56*4882a593SmuzhiyunThe _tep_register_event_handler()_ function returns _TEP_REGISTER_SUCCESS_ 57*4882a593Smuzhiyunif the new handler is registered successfully or 58*4882a593Smuzhiyun_TEP_REGISTER_SUCCESS_OVERWRITE_ if an existing handler is overwritten. 59*4882a593SmuzhiyunIf there is not enough memory to complete the registration, 60*4882a593SmuzhiyunTEP_ERRNO__MEM_ALLOC_FAILED is returned. 61*4882a593Smuzhiyun 62*4882a593SmuzhiyunThe _tep_unregister_event_handler()_ function returns 0 if _func_ was removed 63*4882a593Smuzhiyunsuccessful or, -1 if the event was not found. 64*4882a593Smuzhiyun 65*4882a593SmuzhiyunThe _tep_event_handler_func_ should return -1 in case of an error, 66*4882a593Smuzhiyunor 0 otherwise. 67*4882a593Smuzhiyun 68*4882a593SmuzhiyunEXAMPLE 69*4882a593Smuzhiyun------- 70*4882a593Smuzhiyun[source,c] 71*4882a593Smuzhiyun-- 72*4882a593Smuzhiyun#include <event-parse.h> 73*4882a593Smuzhiyun#include <trace-seq.h> 74*4882a593Smuzhiyun... 75*4882a593Smuzhiyunstruct tep_handle *tep = tep_alloc(); 76*4882a593Smuzhiyun... 77*4882a593Smuzhiyunint timer_expire_handler(struct trace_seq *s, struct tep_record *record, 78*4882a593Smuzhiyun struct tep_event *event, void *context) 79*4882a593Smuzhiyun{ 80*4882a593Smuzhiyun trace_seq_printf(s, "hrtimer="); 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun if (tep_print_num_field(s, "0x%llx", event, "timer", record, 0) == -1) 83*4882a593Smuzhiyun tep_print_num_field(s, "0x%llx", event, "hrtimer", record, 1); 84*4882a593Smuzhiyun 85*4882a593Smuzhiyun trace_seq_printf(s, " now="); 86*4882a593Smuzhiyun 87*4882a593Smuzhiyun tep_print_num_field(s, "%llu", event, "now", record, 1); 88*4882a593Smuzhiyun 89*4882a593Smuzhiyun tep_print_func_field(s, " function=%s", event, "function", record, 0); 90*4882a593Smuzhiyun 91*4882a593Smuzhiyun return 0; 92*4882a593Smuzhiyun} 93*4882a593Smuzhiyun... 94*4882a593Smuzhiyun int ret; 95*4882a593Smuzhiyun 96*4882a593Smuzhiyun ret = tep_register_event_handler(tep, -1, "timer", "hrtimer_expire_entry", 97*4882a593Smuzhiyun timer_expire_handler, NULL); 98*4882a593Smuzhiyun if (ret < 0) { 99*4882a593Smuzhiyun char buf[32]; 100*4882a593Smuzhiyun 101*4882a593Smuzhiyun tep_strerror(tep, ret, buf, 32) 102*4882a593Smuzhiyun printf("Failed to register handler for hrtimer_expire_entry: %s\n", buf); 103*4882a593Smuzhiyun } else { 104*4882a593Smuzhiyun switch (ret) { 105*4882a593Smuzhiyun case TEP_REGISTER_SUCCESS: 106*4882a593Smuzhiyun printf ("Registered handler for hrtimer_expire_entry\n"); 107*4882a593Smuzhiyun break; 108*4882a593Smuzhiyun case TEP_REGISTER_SUCCESS_OVERWRITE: 109*4882a593Smuzhiyun printf ("Overwrote handler for hrtimer_expire_entry\n"); 110*4882a593Smuzhiyun break; 111*4882a593Smuzhiyun } 112*4882a593Smuzhiyun } 113*4882a593Smuzhiyun... 114*4882a593Smuzhiyun ret = tep_unregister_event_handler(tep, -1, "timer", "hrtimer_expire_entry", 115*4882a593Smuzhiyun timer_expire_handler, NULL); 116*4882a593Smuzhiyun if ( ret ) 117*4882a593Smuzhiyun printf ("Failed to unregister handler for hrtimer_expire_entry\n"); 118*4882a593Smuzhiyun 119*4882a593Smuzhiyun-- 120*4882a593Smuzhiyun 121*4882a593SmuzhiyunFILES 122*4882a593Smuzhiyun----- 123*4882a593Smuzhiyun[verse] 124*4882a593Smuzhiyun-- 125*4882a593Smuzhiyun*event-parse.h* 126*4882a593Smuzhiyun Header file to include in order to have access to the library APIs. 127*4882a593Smuzhiyun*trace-seq.h* 128*4882a593Smuzhiyun Header file to include in order to have access to trace sequences 129*4882a593Smuzhiyun related APIs. Trace sequences are used to allow a function to call 130*4882a593Smuzhiyun several other functions to create a string of data to use. 131*4882a593Smuzhiyun*-ltraceevent* 132*4882a593Smuzhiyun Linker switch to add when building a program that uses the library. 133*4882a593Smuzhiyun-- 134*4882a593Smuzhiyun 135*4882a593SmuzhiyunSEE ALSO 136*4882a593Smuzhiyun-------- 137*4882a593Smuzhiyun_libtraceevent(3)_, _trace-cmd(1)_ 138*4882a593Smuzhiyun 139*4882a593SmuzhiyunAUTHOR 140*4882a593Smuzhiyun------ 141*4882a593Smuzhiyun[verse] 142*4882a593Smuzhiyun-- 143*4882a593Smuzhiyun*Steven Rostedt* <rostedt@goodmis.org>, author of *libtraceevent*. 144*4882a593Smuzhiyun*Tzvetomir Stoyanov* <tz.stoyanov@gmail.com>, author of this man page. 145*4882a593Smuzhiyun-- 146*4882a593SmuzhiyunREPORTING BUGS 147*4882a593Smuzhiyun-------------- 148*4882a593SmuzhiyunReport bugs to <linux-trace-devel@vger.kernel.org> 149*4882a593Smuzhiyun 150*4882a593SmuzhiyunLICENSE 151*4882a593Smuzhiyun------- 152*4882a593Smuzhiyunlibtraceevent is Free Software licensed under the GNU LGPL 2.1 153*4882a593Smuzhiyun 154*4882a593SmuzhiyunRESOURCES 155*4882a593Smuzhiyun--------- 156*4882a593Smuzhiyunhttps://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 157