LIBTRACEEVENT(3)

πŸ“¦ version 1.3.3, in ubuntu jammy

πŸ’– LIBTRACEEVENT(3) β€” the libtraceevent manual, bestie edition πŸ’–

okay so welcome to the libtraceevent manual page, section 3 (that's library functions, iykyk). this one's about printing field content and honestly it's giving "tiny function, huge glow-up" energy ✨


🌸 NAME 🌸

tep_print_field, tep_print_fields, tep_print_num_field, tep_print_func_field β€” Print the field content. that's it, that's the whole vibe. πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <event-parse.h>
#include <trace-seq.h>

void tep_print_field(struct trace_seq *s, void *data, struct tep_format_field *field);
void tep_print_fields(struct trace_seq *s, void *data, int size, struct tep_event *event);
int tep_print_num_field(struct trace_seq *s, const char *fmt, struct tep_event *event, const char *name, struct tep_record *record, int err);
int tep_print_func_field(struct trace_seq *s, const char *fmt, struct tep_event *event, const char *name, struct tep_record *record, int err);

look at those signatures, so clean, so precise πŸ’…


✨ DESCRIPTION ✨

so these functions print recorded field data, and they do it according to the field's type. no guessing, no vibes-based formatting, the type decides. periodt.

The tep_print_field() function extracts from the recorded raw data value of the field and prints it into s, according to the field type. 🫢

The tep_print_fields() prints each field name followed by the record's field value according to the field's type:

"field1_name=field1_value field2_name=field2_value ..."

It iterates all fields of the event, and calls tep_print_field() for each of them. like, all of them. no skipping, bestie, it's thorough. πŸ‘‘

The tep_print_num_field() function prints a numeric field with given format string. A search is performed in the event for a field with name. If such field is found, its value is extracted from the record and is printed in the s, according to the given format string fmt. If the argument err is non-zero, and an error occures β€” it is printed in the s. 😭 (yes, "occures" β€” we're keeping it exactly how it is, character for character, no cap)

The tep_print_func_field() function prints a function field with given format string. A search is performed in the event for a field with name. If such field is found, its value is extracted from the record. The value is assumed to be a function address, and a search is perform to find the name of this function. The function name (if found) and its address are printed in the s, according to the given format string fmt. If the argument err is non-zero, and an error occures β€” it is printed in s. πŸ”₯


πŸŽ€ RETURN VALUE πŸŽ€

The tep_print_num_field() and tep_print_func_field() functions return 1 on success, -1 in case of an error or 0 if the print buffer s is full.

three outcomes, three moods: 1 slay, -1 not slay, 0 the buffer said "i'm full bestie" πŸ’€


🌈 EXAMPLE 🌈

#include <event-parse.h>
#include <trace-seq.h>
...
struct tep_handle *tep = tep_alloc();
...
struct trace_seq seq;
trace_seq_init(&seq);
struct tep_event *event = tep_find_event_by_name(tep, "timer", "hrtimer_start");
...
void process_record(struct tep_record *record)
{
        struct tep_format_field *field_pid = tep_find_common_field(event, "common_pid");

        trace_seq_reset(&seq);

        /* Print the value of "common_pid" */
        tep_print_field(&seq, record->data, field_pid);

        /* Print all fields of the "hrtimer_start" event */
        tep_print_fields(&seq, record->data, record->size, event);

        /* Print the value of "expires" field with custom format string */
        tep_print_num_field(&seq, " timer expires in %llu ", event, "expires", record, 0);

        /* Print the address and the name of "function" field with custom format string */
        tep_print_func_field(&seq, " timer function is %s ", event, "function", record, 0);
 }
 ...

not the comments doing all the explaining for us 😌 main character energy fr fr.


πŸ’œ 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.

absolute legends, both of them 🫢


πŸ“ REPORTING BUGS πŸ“

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

found a bug? tell the mailing list, don't just suffer in silence bestie 😭

πŸ’… 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, you ate it πŸ’– this was libtraceevent 1.3.3, dated 08/28/2021, and it lives in section 3 of the manual. now go print some fields, bestie πŸ‘‘βœ¨

πŸ“¦ where this page comes from