Back to home page

OSCL-LXR

 
 

    


0001 libtraceevent(3)
0002 ================
0003 
0004 NAME
0005 ----
0006 tep_register_event_handler, tep_unregister_event_handler -  Register /
0007 unregisters a callback function to parse an event information.
0008 
0009 SYNOPSIS
0010 --------
0011 [verse]
0012 --
0013 *#include <event-parse.h>*
0014 
0015 enum *tep_reg_handler* {
0016         _TEP_REGISTER_SUCCESS_,
0017         _TEP_REGISTER_SUCCESS_OVERWRITE_,
0018 };
0019 
0020 int *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_);
0021 int *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_);
0022 
0023 typedef int (*pass:[*]tep_event_handler_func*)(struct trace_seq pass:[*]s, struct tep_record pass:[*]record, struct tep_event pass:[*]event, void pass:[*]context);
0024 --
0025 
0026 DESCRIPTION
0027 -----------
0028 The _tep_register_event_handler()_ function registers a handler function,
0029 which is going to be called to parse the information for a given event.
0030 The _tep_ argument is the trace event parser context. The _id_ argument is
0031 the id of the event. The _sys_name_ argument is the name of the system,
0032 the event belongs to. The _event_name_ argument is the name of the event.
0033 If _id_ is >= 0, it is used to find the event, otherwise _sys_name_ and
0034 _event_name_ are used. The _func_ is a pointer to the function, which is going
0035 to be called to parse the event information. The _context_ argument is a pointer
0036 to the context data, which will be passed to the _func_. If a handler function
0037 for the same event is already registered, it will be overridden with the new
0038 one. This mechanism allows a developer to override the parsing of a given event.
0039 If for some reason the default print format is not sufficient, the developer
0040 can register a function for an event to be used to parse the data instead.
0041 
0042 The _tep_unregister_event_handler()_ function unregisters the handler function,
0043 previously registered with _tep_register_event_handler()_. The _tep_ argument
0044 is the trace event parser context. The _id_, _sys_name_, _event_name_, _func_,
0045 and _context_ are the same arguments, as when the callback function _func_ was
0046 registered.
0047 
0048 The _tep_event_handler_func_ is the type of the custom event handler
0049 function. The _s_ argument is the trace sequence, it can be used to create a
0050 custom string, describing the event. A _record_  to get the event from is passed
0051 as input parameter and also the _event_ - the handle to the record's event. The
0052 _context_ is custom context, set when the custom event handler is registered.
0053 
0054 RETURN VALUE
0055 ------------
0056 The _tep_register_event_handler()_ function returns _TEP_REGISTER_SUCCESS_
0057 if the new handler is registered successfully or
0058 _TEP_REGISTER_SUCCESS_OVERWRITE_ if an existing handler is overwritten.
0059 If there is not  enough memory to complete the registration,
0060 TEP_ERRNO__MEM_ALLOC_FAILED is returned.
0061 
0062 The _tep_unregister_event_handler()_ function returns 0 if _func_ was removed
0063 successful or, -1 if the event was not found.
0064 
0065 The _tep_event_handler_func_ should return -1 in case of an error,
0066 or 0 otherwise.
0067 
0068 EXAMPLE
0069 -------
0070 [source,c]
0071 --
0072 #include <event-parse.h>
0073 #include <trace-seq.h>
0074 ...
0075 struct tep_handle *tep = tep_alloc();
0076 ...
0077 int timer_expire_handler(struct trace_seq *s, struct tep_record *record,
0078                          struct tep_event *event, void *context)
0079 {
0080         trace_seq_printf(s, "hrtimer=");
0081 
0082         if (tep_print_num_field(s, "0x%llx", event, "timer", record, 0) == -1)
0083                 tep_print_num_field(s, "0x%llx", event, "hrtimer", record, 1);
0084 
0085         trace_seq_printf(s, " now=");
0086 
0087         tep_print_num_field(s, "%llu", event, "now", record, 1);
0088 
0089         tep_print_func_field(s, " function=%s", event, "function", record, 0);
0090 
0091         return 0;
0092 }
0093 ...
0094         int ret;
0095 
0096         ret = tep_register_event_handler(tep, -1, "timer", "hrtimer_expire_entry",
0097                                          timer_expire_handler, NULL);
0098         if (ret < 0) {
0099                 char buf[32];
0100 
0101                 tep_strerror(tep, ret, buf, 32)
0102                 printf("Failed to register handler for hrtimer_expire_entry: %s\n", buf);
0103         } else {
0104                 switch (ret) {
0105                 case TEP_REGISTER_SUCCESS:
0106                         printf ("Registered handler for hrtimer_expire_entry\n");
0107                         break;
0108                 case TEP_REGISTER_SUCCESS_OVERWRITE:
0109                         printf ("Overwrote handler for hrtimer_expire_entry\n");
0110                         break;
0111                 }
0112         }
0113 ...
0114         ret = tep_unregister_event_handler(tep, -1, "timer", "hrtimer_expire_entry",
0115                                            timer_expire_handler, NULL);
0116         if ( ret )
0117                 printf ("Failed to unregister handler for hrtimer_expire_entry\n");
0118 
0119 --
0120 
0121 FILES
0122 -----
0123 [verse]
0124 --
0125 *event-parse.h*
0126         Header file to include in order to have access to the library APIs.
0127 *trace-seq.h*
0128         Header file to include in order to have access to trace sequences
0129         related APIs. Trace sequences are used to allow a function to call
0130         several other functions to create a string of data to use.
0131 *-ltraceevent*
0132         Linker switch to add when building a program that uses the library.
0133 --
0134 
0135 SEE ALSO
0136 --------
0137 _libtraceevent(3)_, _trace-cmd(1)_
0138 
0139 AUTHOR
0140 ------
0141 [verse]
0142 --
0143 *Steven Rostedt* <rostedt@goodmis.org>, author of *libtraceevent*.
0144 *Tzvetomir Stoyanov* <tz.stoyanov@gmail.com>, author of this man page.
0145 --
0146 REPORTING BUGS
0147 --------------
0148 Report bugs to  <linux-trace-devel@vger.kernel.org>
0149 
0150 LICENSE
0151 -------
0152 libtraceevent is Free Software licensed under the GNU LGPL 2.1
0153 
0154 RESOURCES
0155 ---------
0156 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git