'\" t
.\" Title: libtraceevent
.\" Author: [see the "AUTHOR" section]
.\" Generator: DocBook XSL Stylesheets vsnapshot
.\" Date: 02/15/2021
.\" Manual: libtraceevent Manual
.\" Source: libtraceevent 1.1.2
.\" Language: English
.\"
.TH "LIBTRACEEVENT" "3" "02/15/2021" "libtraceevent 1\&.1\&.2" "libtraceevent Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
tep_register_event_handler, tep_unregister_event_handler \- Register / unregisters a callback function to parse an event information\&.
.SH "SYNOPSIS"
.sp
.nf
\fB#include \fR
enum \fBtep_reg_handler\fR {
\fITEP_REGISTER_SUCCESS\fR,
\fITEP_REGISTER_SUCCESS_OVERWRITE\fR,
};
int \fBtep_register_event_handler\fR(struct tep_handle *\fItep\fR, int \fIid\fR, const char *\fIsys_name\fR, const char *\fIevent_name\fR, tep_event_handler_func \fIfunc\fR, void *\fIcontext\fR);
int \fBtep_unregister_event_handler\fR(struct tep_handle *tep, int id, const char *sys_name, const char *event_name, tep_event_handler_func func, void *\fIcontext\fR);
typedef int (\fB*tep_event_handler_func\fR)(struct trace_seq *s, struct tep_record *record, struct tep_event *event, void *context);
.fi
.SH "DESCRIPTION"
.sp
The \fItep_register_event_handler()\fR function registers a handler function, which is going to be called to parse the information for a given event\&. The \fItep\fR argument is the trace event parser context\&. The \fIid\fR argument is the id of the event\&. The \fIsys_name\fR argument is the name of the system, the event belongs to\&. The \fIevent_name\fR argument is the name of the event\&. If \fIid\fR is >= 0, it is used to find the event, otherwise \fIsys_name\fR and \fIevent_name\fR are used\&. The \fIfunc\fR is a pointer to the function, which is going to be called to parse the event information\&. The \fIcontext\fR argument is a pointer to the context data, which will be passed to the \fIfunc\fR\&. If a handler function for the same event is already registered, it will be overridden with the new one\&. This mechanism allows a developer to override the parsing of a given event\&. If for some reason the default print format is not sufficient, the developer can register a function for an event to be used to parse the data instead\&.
.sp
The \fItep_unregister_event_handler()\fR function unregisters the handler function, previously registered with \fItep_register_event_handler()\fR\&. The \fItep\fR argument is the trace event parser context\&. The \fIid\fR, \fIsys_name\fR, \fIevent_name\fR, \fIfunc\fR, and \fIcontext\fR are the same arguments, as when the callback function \fIfunc\fR was registered\&.
.sp
The \fItep_event_handler_func\fR is the type of the custom event handler function\&. The \fIs\fR argument is the trace sequence, it can be used to create a custom string, describing the event\&. A \fIrecord\fR to get the event from is passed as input parameter and also the \fIevent\fR \- the handle to the record\(cqs event\&. The \fIcontext\fR is custom context, set when the custom event handler is registered\&.
.SH "RETURN VALUE"
.sp
The \fItep_register_event_handler()\fR function returns \fITEP_REGISTER_SUCCESS\fR if the new handler is registered successfully or \fITEP_REGISTER_SUCCESS_OVERWRITE\fR if an existing handler is overwritten\&. If there is not enough memory to complete the registration, TEP_ERRNO__MEM_ALLOC_FAILED is returned\&.
.sp
The \fItep_unregister_event_handler()\fR function returns 0 if \fIfunc\fR was removed successful or, \-1 if the event was not found\&.
.sp
The \fItep_event_handler_func\fR should return \-1 in case of an error, or 0 otherwise\&.
.SH "EXAMPLE"
.sp
.if n \{\
.RS 4
.\}
.nf
#include
#include
\&.\&.\&.
struct tep_handle *tep = tep_alloc();
\&.\&.\&.
int timer_expire_handler(struct trace_seq *s, struct tep_record *record,
struct tep_event *event, void *context)
{
trace_seq_printf(s, "hrtimer=");
if (tep_print_num_field(s, "0x%llx", event, "timer", record, 0) == \-1)
tep_print_num_field(s, "0x%llx", event, "hrtimer", record, 1);
trace_seq_printf(s, " now=");
tep_print_num_field(s, "%llu", event, "now", record, 1);
tep_print_func_field(s, " function=%s", event, "function", record, 0);
return 0;
}
\&.\&.\&.
int ret;
ret = tep_register_event_handler(tep, \-1, "timer", "hrtimer_expire_entry",
timer_expire_handler, NULL);
if (ret < 0) {
char buf[32];
tep_strerror(tep, ret, buf, 32)
printf("Failed to register handler for hrtimer_expire_entry: %s\en", buf);
} else {
switch (ret) {
case TEP_REGISTER_SUCCESS:
printf ("Registered handler for hrtimer_expire_entry\en");
break;
case TEP_REGISTER_SUCCESS_OVERWRITE:
printf ("Overwrote handler for hrtimer_expire_entry\en");
break;
}
}
\&.\&.\&.
ret = tep_unregister_event_handler(tep, \-1, "timer", "hrtimer_expire_entry",
timer_expire_handler, NULL);
if ( ret )
printf ("Failed to unregister handler for hrtimer_expire_entry\en");
.fi
.if n \{\
.RE
.\}
.SH "FILES"
.sp
.if n \{\
.RS 4
.\}
.nf
\fBevent\-parse\&.h\fR
Header file to include in order to have access to the library APIs\&.
\fBtrace\-seq\&.h\fR
Header file to include in order to have access to trace sequences
related APIs\&. Trace sequences are used to allow a function to call
several other functions to create a string of data to use\&.
\fB\-ltraceevent\fR
Linker switch to add when building a program that uses the library\&.
.fi
.if n \{\
.RE
.\}
.SH "SEE ALSO"
.sp
\fIlibtraceevent(3)\fR, \fItrace\-cmd(1)\fR
.SH "AUTHOR"
.sp
.if n \{\
.RS 4
.\}
.nf
\fBSteven Rostedt\fR <\m[blue]\fBrostedt@goodmis\&.org\fR\m[]\&\s-2\u[1]\d\s+2>, author of \fBlibtraceevent\fR\&.
\fBTzvetomir Stoyanov\fR <\m[blue]\fBtz\&.stoyanov@gmail\&.com\fR\m[]\&\s-2\u[2]\d\s+2>, author of this man page\&.
.fi
.if n \{\
.RE
.\}
.SH "REPORTING BUGS"
.sp
Report bugs to <\m[blue]\fBlinux\-trace\-devel@vger\&.kernel\&.org\fR\m[]\&\s-2\u[3]\d\s+2>
.SH "LICENSE"
.sp
libtraceevent is Free Software licensed under the GNU LGPL 2\&.1
.SH "RESOURCES"
.sp
\m[blue]\fBhttps://git\&.kernel\&.org/pub/scm/libs/libtrace/libtraceevent\&.git/\fR\m[]
.SH "NOTES"
.IP " 1." 4
rostedt@goodmis.org
.RS 4
\%mailto:rostedt@goodmis.org
.RE
.IP " 2." 4
tz.stoyanov@gmail.com
.RS 4
\%mailto:tz.stoyanov@gmail.com
.RE
.IP " 3." 4
linux-trace-devel@vger.kernel.org
.RS 4
\%mailto:linux-trace-devel@vger.kernel.org
.RE