LIBTRACEEVENT(3)

πŸ’– LIBTRACEEVENT(3) πŸ’–

okay bestie, welcome to the libtraceevent Manual β€” specifically the LIBTRACEEVENT(3) page, and lemme tell you, this one is a whole vibe πŸ¦‹


✨ NAME ✨

tep_register_print_function, tep_unregister_print_function β€” Registers / Unregisters a helper function.

like... it literally signs a helper function up for the group chat, or removes it. that's the whole gig πŸŽ€


🌸 SYNOPSIS 🌸

#include <event-parse.h>

enum tep_func_arg_type {
        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 (*tep_func_handler)(struct trace_seq *s, unsigned long long *args);

int tep_register_print_function(struct tep_handle *tep, tep_func_handler func, enum tep_func_arg_type ret_type, char *name, ...);
int tep_unregister_print_function(struct tep_handle *tep, tep_func_handler func, char *name);

no cap, that's the whole signature lineup right there πŸ‘‘


πŸ’… DESCRIPTION πŸ’…

so here's the tea: some events have helper functions chillin' in their print format arguments. and this API is the way a plugin can dynamically create a way to process one of those functions. main character energy, honestly πŸ”₯

tep_register_print_function() registers such a helper function. breaking it down:

  • the tep argument is the trace event parser context.
  • the func argument is a pointer to the helper function.
  • the ret_type argument is the return type of the helper function β€” a value from the tep_func_arg_type enum.
  • the name is the name of the helper function, as seen in the print format arguments.
  • the ... is a variable list of tep_func_arg_type enums, aka the func function arguments. this list must end with TEP_FUNC_ARG_VOID. peep the EXAMPLE section for the whole picture ✨

tep_unregister_print_function() unregisters a helper function that was previously registered with tep_register_print_function(). the tep argument is the trace event parser context, and the func and name arguments are the same ones used when the helper function was registered. it's giving "we're removing you from the group chat" πŸ’€

tep_func_handler is the type of the helper function. the s argument is the trace sequence β€” you can use it to create a custom string. the args is a list of arguments, defined back when the helper function was registered. iconic.


🫢 RETURN VALUE 🫢

  • tep_register_print_function() returns 0 in case of success. in case of an error, a TEP_ERRNO_... code is returned.
  • tep_unregister_print_function() returns 0 in case of success, or -1 in case of an error.

🧚 EXAMPLE 🧚

some events have internal function calls that show up in the print format output. for example, "tracefs/events/i915/g4x_wm/format" has:

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) + 'A'), 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)

notice the call to the function yesno() in the print arguments? yeah. so in the kernel context, this function has the following implementation:

static const char *yesno(int x)
{
        static const char *yes = "yes";
        static const char *no = "no";

        return x ? yes : no;
}

the user space event parser has no idea how to handle this yesno() function 😭. so the tep_register_print_function() API can be used to register a user space helper function, mapped to the kernel's yesno():

#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 */
        }

and just like that, the parser gets it. slay πŸ’…


πŸ“ FILES πŸ“

  • event-parse.h β€” Header file to include in order to have access to the library APIs.
  • trace-seq.h β€” 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.
  • -ltraceevent β€” Linker switch to add when building a program that uses the library.

🌈 SEE ALSO 🌈

libtraceevent(3), trace-cmd(1)


πŸ‘‘ AUTHOR πŸ‘‘

  • Steven Rostedt <rostedt@goodmis.org> [1], author of libtraceevent.
  • Tzvetomir Stoyanov <tz.stoyanov@gmail.com> [2], author of this man page.

πŸ™ˆ REPORTING BUGS πŸ™ˆ

Report bugs to <linux-trace-devel@vger.kernel.org> [3]


⭐ LICENSE ⭐

libtraceevent is Free Software licensed under the GNU LGPL 2.1


πŸ”₯ RESOURCES πŸ”₯

https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/


πŸ’œ NOTES πŸ’œ

  1. rostedt@goodmis.org mailto:rostedt@goodmis.org
  2. tz.stoyanov@gmail.com mailto:tz.stoyanov@gmail.com
  3. linux-trace-devel@vger.kernel.org mailto:linux-trace-devel@vger.kernel.org

okay that's the whole page bestie, you ate it up πŸ’–βœ¨

this was libtraceevent 1.9.0, dated 06/15/2026 β€” mwah, periodt πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from