'\" t
.\"     Title: libtraceevent
.\"    Author: [see the "AUTHOR" section]
.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
.\"      Date: 03/03/2025
.\"    Manual: libtraceevent Manual
.\"    Source: libtraceevent 1.8.4
.\"  Language: English
.\"
.TH "LIBTRACEEVENT" "3" "03/03/2025" "libtraceevent 1\&.8\&.4" "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_print_function, tep_unregister_print_function \- Registers / Unregisters a helper function\&.
.SH "SYNOPSIS"
.sp
.nf
\fB#include <event\-parse\&.h>\fR

enum \fBtep_func_arg_type\fR {
        TEP_FUNC_ARG_VOID,
        TEP_FUNC_ARG_INT,
        TEP_FUNC_ARG_LONG,
        TEP_FUNC_ARG_STRING,
        TEP_FUNC_ARG_PTR,
        TEP_FUNC_ARG_MAX_TYPES
};

typedef unsigned long long (\fB*tep_func_handler\fR)(struct trace_seq *s, unsigned long long *args);

int \fBtep_register_print_function\fR(struct tep_handle *\fItep\fR, tep_func_handler \fIfunc\fR, enum tep_func_arg_type \fIret_type\fR, char *\fIname\fR, \fI\&...\fR);
int \fBtep_unregister_print_function\fR(struct tep_handle *\fItep\fR, tep_func_handler \fIfunc\fR, char *\fIname\fR);
.fi
.SH "DESCRIPTION"
.sp
Some events may have helper functions in the print format arguments\&. This allows a plugin to dynamically create a way to process one of these functions\&.
.sp
The \fBtep_register_print_function()\fR registers such helper function\&. The \fItep\fR argument is the trace event parser context\&. The \fIfunc\fR argument is a pointer to the helper function\&. The \fIret_type\fR argument is the return type of the helper function, value from the \fItep_func_arg_type\fR enum\&. The \fIname\fR is the name of the helper function, as seen in the print format arguments\&. The \fI\&...\fR is a variable list of \fItep_func_arg_type\fR enums, the \fIfunc\fR function arguments\&. This list must end with \fITEP_FUNC_ARG_VOID\fR\&. See \fIEXAMPLE\fR section\&.
.sp
The \fBtep_unregister_print_function()\fR unregisters a helper function, previously registered with \fBtep_register_print_function()\fR\&. The \fItep\fR argument is the trace event parser context\&. The \fIfunc\fR and \fIname\fR arguments are the same, used when the helper function was registered\&.
.sp
The \fItep_func_handler\fR is the type of the helper function\&. The \fIs\fR argument is the trace sequence, it can be used to create a custom string\&. The \fIargs\fR is a list of arguments, defined when the helper function was registered\&.
.SH "RETURN VALUE"
.sp
The \fBtep_register_print_function()\fR function returns 0 in case of success\&. In case of an error, TEP_ERRNO_\&... code is returned\&.
.sp
The \fBtep_unregister_print_function()\fR returns 0 in case of success, or \-1 in case of an error\&.
.SH "EXAMPLE"
.sp
Some events have internal functions calls, that appear in the print format output\&. For example "tracefs/events/i915/g4x_wm/format" has:
.sp
.if n \{\
.RS 4
.\}
.nf
print fmt: "pipe %c, frame=%u, scanline=%u, wm %d/%d/%d, sr %s/%d/%d/%d, hpll %s/%d/%d/%d, fbc %s",
            ((REC\->pipe) + \*(AqA\*(Aq), REC\->frame, REC\->scanline, REC\->primary,
            REC\->sprite, REC\->cursor, yesno(REC\->cxsr), REC\->sr_plane,
            REC\->sr_cursor, REC\->sr_fbc, yesno(REC\->hpll), REC\->hpll_plane,
            REC\->hpll_cursor, REC\->hpll_fbc, yesno(REC\->fbc)
.fi
.if n \{\
.RE
.\}
.sp
Notice the call to function \fByesno()\fR in the print arguments\&. In the kernel context, this function has the following implementation:
.sp
.if n \{\
.RS 4
.\}
.nf
static const char *yesno(int x)
{
        static const char *yes = "yes";
        static const char *no = "no";

        return x ? yes : no;
}
.fi
.if n \{\
.RE
.\}
.sp
The user space event parser has no idea how to handle this \fByesno()\fR function\&. The \fBtep_register_print_function()\fR API can be used to register a user space helper function, mapped to the kernel\(cqs \fByesno()\fR:
.sp
.if n \{\
.RS 4
.\}
.nf
#include <event\-parse\&.h>
#include <trace\-seq\&.h>
\&.\&.\&.
struct tep_handle *tep = tep_alloc();
\&.\&.\&.
static const char *yes_no_helper(int x)
{
        return x ? "yes" : "no";
}
\&.\&.\&.
        if ( tep_register_print_function(tep,
                                    yes_no_helper,
                                    TEP_FUNC_ARG_STRING,
                                    "yesno",
                                    TEP_FUNC_ARG_INT,
                                    TEP_FUNC_ARG_VOID) != 0) {
                /* Failed to register yes_no_helper function */
        }

/*
   Now, when the event parser encounters this yesno() function, it will know
   how to handle it\&.
*/
\&.\&.\&.
        if (tep_unregister_print_function(tep, yes_no_helper, "yesno") != 0) {
                /* Failed to unregister yes_no_helper function */
        }
.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
\fBlibtraceevent\fR(3), \fBtrace\-cmd\fR(1)
.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
