1*436bf2bcSAndroid Build Coastguard Workerlibtraceevent(3) 2*436bf2bcSAndroid Build Coastguard Worker================ 3*436bf2bcSAndroid Build Coastguard Worker 4*436bf2bcSAndroid Build Coastguard WorkerNAME 5*436bf2bcSAndroid Build Coastguard Worker---- 6*436bf2bcSAndroid Build Coastguard Workertep_register_event_handler, tep_unregister_event_handler - Register / 7*436bf2bcSAndroid Build Coastguard Workerunregisters a callback function to parse an event information. 8*436bf2bcSAndroid Build Coastguard Worker 9*436bf2bcSAndroid Build Coastguard WorkerSYNOPSIS 10*436bf2bcSAndroid Build Coastguard Worker-------- 11*436bf2bcSAndroid Build Coastguard Worker[verse] 12*436bf2bcSAndroid Build Coastguard Worker-- 13*436bf2bcSAndroid Build Coastguard Worker*#include <event-parse.h>* 14*436bf2bcSAndroid Build Coastguard Worker 15*436bf2bcSAndroid Build Coastguard Workerenum *tep_reg_handler* { 16*436bf2bcSAndroid Build Coastguard Worker _TEP_REGISTER_SUCCESS_, 17*436bf2bcSAndroid Build Coastguard Worker _TEP_REGISTER_SUCCESS_OVERWRITE_, 18*436bf2bcSAndroid Build Coastguard Worker}; 19*436bf2bcSAndroid Build Coastguard Worker 20*436bf2bcSAndroid Build Coastguard Workerint *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*436bf2bcSAndroid Build Coastguard Workerint *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*436bf2bcSAndroid Build Coastguard Worker 23*436bf2bcSAndroid Build Coastguard Workertypedef 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*436bf2bcSAndroid Build Coastguard Worker-- 25*436bf2bcSAndroid Build Coastguard Worker 26*436bf2bcSAndroid Build Coastguard WorkerDESCRIPTION 27*436bf2bcSAndroid Build Coastguard Worker----------- 28*436bf2bcSAndroid Build Coastguard WorkerThe *tep_register_event_handler()* function registers a handler function, 29*436bf2bcSAndroid Build Coastguard Workerwhich is going to be called to parse the information for a given event. 30*436bf2bcSAndroid Build Coastguard WorkerThe _tep_ argument is the trace event parser context. The _id_ argument is 31*436bf2bcSAndroid Build Coastguard Workerthe id of the event. The _sys_name_ argument is the name of the system, 32*436bf2bcSAndroid Build Coastguard Workerthe event belongs to. The _event_name_ argument is the name of the event. 33*436bf2bcSAndroid Build Coastguard WorkerIf _id_ is >= 0, it is used to find the event, otherwise _sys_name_ and 34*436bf2bcSAndroid Build Coastguard Worker_event_name_ are used. The _func_ is a pointer to the function, which is going 35*436bf2bcSAndroid Build Coastguard Workerto be called to parse the event information. The _context_ argument is a pointer 36*436bf2bcSAndroid Build Coastguard Workerto the context data, which will be passed to the _func_. If a handler function 37*436bf2bcSAndroid Build Coastguard Workerfor the same event is already registered, it will be overridden with the new 38*436bf2bcSAndroid Build Coastguard Workerone. This mechanism allows a developer to override the parsing of a given event. 39*436bf2bcSAndroid Build Coastguard WorkerIf for some reason the default print format is not sufficient, the developer 40*436bf2bcSAndroid Build Coastguard Workercan register a function for an event to be used to parse the data instead. 41*436bf2bcSAndroid Build Coastguard Worker 42*436bf2bcSAndroid Build Coastguard WorkerThe *tep_unregister_event_handler()* function unregisters the handler function, 43*436bf2bcSAndroid Build Coastguard Workerpreviously registered with *tep_register_event_handler()*. The _tep_ argument 44*436bf2bcSAndroid Build Coastguard Workeris the trace event parser context. The _id_, _sys_name_, _event_name_, _func_, 45*436bf2bcSAndroid Build Coastguard Workerand _context_ are the same arguments, as when the callback function _func_ was 46*436bf2bcSAndroid Build Coastguard Workerregistered. 47*436bf2bcSAndroid Build Coastguard Worker 48*436bf2bcSAndroid Build Coastguard WorkerThe _tep_event_handler_func_ is the type of the custom event handler 49*436bf2bcSAndroid Build Coastguard Workerfunction. The _s_ argument is the trace sequence, it can be used to create a 50*436bf2bcSAndroid Build Coastguard Workercustom string, describing the event. A _record_ to get the event from is passed 51*436bf2bcSAndroid Build Coastguard Workeras input parameter and also the _event_ - the handle to the record's event. The 52*436bf2bcSAndroid Build Coastguard Worker_context_ is custom context, set when the custom event handler is registered. 53*436bf2bcSAndroid Build Coastguard Worker 54*436bf2bcSAndroid Build Coastguard WorkerRETURN VALUE 55*436bf2bcSAndroid Build Coastguard Worker------------ 56*436bf2bcSAndroid Build Coastguard WorkerThe *tep_register_event_handler()* function returns _TEP_REGISTER_SUCCESS_ 57*436bf2bcSAndroid Build Coastguard Workerif the new handler is registered successfully or 58*436bf2bcSAndroid Build Coastguard Worker_TEP_REGISTER_SUCCESS_OVERWRITE_ if an existing handler is overwritten. 59*436bf2bcSAndroid Build Coastguard WorkerIf there is not enough memory to complete the registration, 60*436bf2bcSAndroid Build Coastguard WorkerTEP_ERRNO__MEM_ALLOC_FAILED is returned. 61*436bf2bcSAndroid Build Coastguard Worker 62*436bf2bcSAndroid Build Coastguard WorkerThe *tep_unregister_event_handler()* function returns 0 if _func_ was removed 63*436bf2bcSAndroid Build Coastguard Workersuccessful or, -1 if the event was not found. 64*436bf2bcSAndroid Build Coastguard Worker 65*436bf2bcSAndroid Build Coastguard WorkerThe _tep_event_handler_func_ should return -1 in case of an error, 66*436bf2bcSAndroid Build Coastguard Workeror 0 otherwise. 67*436bf2bcSAndroid Build Coastguard Worker 68*436bf2bcSAndroid Build Coastguard WorkerEXAMPLE 69*436bf2bcSAndroid Build Coastguard Worker------- 70*436bf2bcSAndroid Build Coastguard Worker[source,c] 71*436bf2bcSAndroid Build Coastguard Worker-- 72*436bf2bcSAndroid Build Coastguard Worker#include <event-parse.h> 73*436bf2bcSAndroid Build Coastguard Worker#include <trace-seq.h> 74*436bf2bcSAndroid Build Coastguard Worker... 75*436bf2bcSAndroid Build Coastguard Workerstruct tep_handle *tep = tep_alloc(); 76*436bf2bcSAndroid Build Coastguard Worker... 77*436bf2bcSAndroid Build Coastguard Workerint timer_expire_handler(struct trace_seq *s, struct tep_record *record, 78*436bf2bcSAndroid Build Coastguard Worker struct tep_event *event, void *context) 79*436bf2bcSAndroid Build Coastguard Worker{ 80*436bf2bcSAndroid Build Coastguard Worker trace_seq_printf(s, "hrtimer="); 81*436bf2bcSAndroid Build Coastguard Worker 82*436bf2bcSAndroid Build Coastguard Worker if (tep_print_num_field(s, "0x%llx", event, "timer", record, 0) == -1) 83*436bf2bcSAndroid Build Coastguard Worker tep_print_num_field(s, "0x%llx", event, "hrtimer", record, 1); 84*436bf2bcSAndroid Build Coastguard Worker 85*436bf2bcSAndroid Build Coastguard Worker trace_seq_printf(s, " now="); 86*436bf2bcSAndroid Build Coastguard Worker 87*436bf2bcSAndroid Build Coastguard Worker tep_print_num_field(s, "%llu", event, "now", record, 1); 88*436bf2bcSAndroid Build Coastguard Worker 89*436bf2bcSAndroid Build Coastguard Worker tep_print_func_field(s, " function=%s", event, "function", record, 0); 90*436bf2bcSAndroid Build Coastguard Worker 91*436bf2bcSAndroid Build Coastguard Worker return 0; 92*436bf2bcSAndroid Build Coastguard Worker} 93*436bf2bcSAndroid Build Coastguard Worker... 94*436bf2bcSAndroid Build Coastguard Worker int ret; 95*436bf2bcSAndroid Build Coastguard Worker 96*436bf2bcSAndroid Build Coastguard Worker ret = tep_register_event_handler(tep, -1, "timer", "hrtimer_expire_entry", 97*436bf2bcSAndroid Build Coastguard Worker timer_expire_handler, NULL); 98*436bf2bcSAndroid Build Coastguard Worker if (ret < 0) { 99*436bf2bcSAndroid Build Coastguard Worker char buf[32]; 100*436bf2bcSAndroid Build Coastguard Worker 101*436bf2bcSAndroid Build Coastguard Worker tep_strerror(tep, ret, buf, 32) 102*436bf2bcSAndroid Build Coastguard Worker printf("Failed to register handler for hrtimer_expire_entry: %s\n", buf); 103*436bf2bcSAndroid Build Coastguard Worker } else { 104*436bf2bcSAndroid Build Coastguard Worker switch (ret) { 105*436bf2bcSAndroid Build Coastguard Worker case TEP_REGISTER_SUCCESS: 106*436bf2bcSAndroid Build Coastguard Worker printf ("Registered handler for hrtimer_expire_entry\n"); 107*436bf2bcSAndroid Build Coastguard Worker break; 108*436bf2bcSAndroid Build Coastguard Worker case TEP_REGISTER_SUCCESS_OVERWRITE: 109*436bf2bcSAndroid Build Coastguard Worker printf ("Overwrote handler for hrtimer_expire_entry\n"); 110*436bf2bcSAndroid Build Coastguard Worker break; 111*436bf2bcSAndroid Build Coastguard Worker } 112*436bf2bcSAndroid Build Coastguard Worker } 113*436bf2bcSAndroid Build Coastguard Worker... 114*436bf2bcSAndroid Build Coastguard Worker ret = tep_unregister_event_handler(tep, -1, "timer", "hrtimer_expire_entry", 115*436bf2bcSAndroid Build Coastguard Worker timer_expire_handler, NULL); 116*436bf2bcSAndroid Build Coastguard Worker if ( ret ) 117*436bf2bcSAndroid Build Coastguard Worker printf ("Failed to unregister handler for hrtimer_expire_entry\n"); 118*436bf2bcSAndroid Build Coastguard Worker 119*436bf2bcSAndroid Build Coastguard Worker-- 120*436bf2bcSAndroid Build Coastguard Worker 121*436bf2bcSAndroid Build Coastguard WorkerFILES 122*436bf2bcSAndroid Build Coastguard Worker----- 123*436bf2bcSAndroid Build Coastguard Worker[verse] 124*436bf2bcSAndroid Build Coastguard Worker-- 125*436bf2bcSAndroid Build Coastguard Worker*event-parse.h* 126*436bf2bcSAndroid Build Coastguard Worker Header file to include in order to have access to the library APIs. 127*436bf2bcSAndroid Build Coastguard Worker*trace-seq.h* 128*436bf2bcSAndroid Build Coastguard Worker Header file to include in order to have access to trace sequences 129*436bf2bcSAndroid Build Coastguard Worker related APIs. Trace sequences are used to allow a function to call 130*436bf2bcSAndroid Build Coastguard Worker several other functions to create a string of data to use. 131*436bf2bcSAndroid Build Coastguard Worker*-ltraceevent* 132*436bf2bcSAndroid Build Coastguard Worker Linker switch to add when building a program that uses the library. 133*436bf2bcSAndroid Build Coastguard Worker-- 134*436bf2bcSAndroid Build Coastguard Worker 135*436bf2bcSAndroid Build Coastguard WorkerSEE ALSO 136*436bf2bcSAndroid Build Coastguard Worker-------- 137*436bf2bcSAndroid Build Coastguard Worker*libtraceevent*(3), *trace-cmd*(1) 138*436bf2bcSAndroid Build Coastguard Worker 139*436bf2bcSAndroid Build Coastguard WorkerAUTHOR 140*436bf2bcSAndroid Build Coastguard Worker------ 141*436bf2bcSAndroid Build Coastguard Worker[verse] 142*436bf2bcSAndroid Build Coastguard Worker-- 143*436bf2bcSAndroid Build Coastguard Worker*Steven Rostedt* <[email protected]>, author of *libtraceevent*. 144*436bf2bcSAndroid Build Coastguard Worker*Tzvetomir Stoyanov* <[email protected]>, author of this man page. 145*436bf2bcSAndroid Build Coastguard Worker-- 146*436bf2bcSAndroid Build Coastguard WorkerREPORTING BUGS 147*436bf2bcSAndroid Build Coastguard Worker-------------- 148*436bf2bcSAndroid Build Coastguard WorkerReport bugs to <[email protected]> 149*436bf2bcSAndroid Build Coastguard Worker 150*436bf2bcSAndroid Build Coastguard WorkerLICENSE 151*436bf2bcSAndroid Build Coastguard Worker------- 152*436bf2bcSAndroid Build Coastguard Workerlibtraceevent is Free Software licensed under the GNU LGPL 2.1 153*436bf2bcSAndroid Build Coastguard Worker 154*436bf2bcSAndroid Build Coastguard WorkerRESOURCES 155*436bf2bcSAndroid Build Coastguard Worker--------- 156*436bf2bcSAndroid Build Coastguard Workerhttps://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/ 157