trace-cmd: Use BTF to show the arguments for function tracers
Subsystems (3)
v3 cover trace-cmd: Use BTF to show the arguments for function tracers
From: "Steven Rostedt (Google)" <[email protected]>
Have trace-cmd use the new BTF parsing to show the arguments of function tracing.
Changes since v2: https://lore.kernel.org/all/[email protected]
- Fixed tracecmd_append_btf_file() exiting out early when btf file doesn't exist. That would cause the offset to be incorrect and the next write to the trace.dat file would corrupt it. This happened with trace-cmd extract.
Steven Rostedt (Google) (6):
libtracecmd: Remove "compress" parameter from save_string_section()
libtracecmd: Remove "compress" parameter from tcmd_out_compress*() functions
libtracecmd: Add write_compress_section_header() for writing compress sections trace-cmd record / report: Record BTF file if function arguments are recorded
libtracecmd: Add printing of arguments for function graph tracer trace-cmd documenatation: Update the trace.dat man page for BTF_FILE
.../trace-cmd/trace-cmd.dat.v7.5.txt | 19 ++ Makefile | 9 + .../include/private/trace-cmd-private.h | 3 + lib/trace-cmd/include/trace-cmd-local.h | 7 +- lib/trace-cmd/trace-compress.c | 26 ++ lib/trace-cmd/trace-ftrace.c | 58 ++++- lib/trace-cmd/trace-input.c | 68 ++++-- lib/trace-cmd/trace-output.c | 228 ++++++++++-------- meson.build | 3 + tracecmd/trace-record.c | 42 +++- 10 files changed, 330 insertions(+), 133 deletions(-)
Signature · 1 line
2.51.0
PATCH v3 1/6 libtracecmd: Remove "compress" parameter from save_string_section()
From: "Steven Rostedt (Google)" <[email protected]>
The function save_string_section() is always called with the compress parameter as "true". There's no reason to have it. Just always make it true.
--- lib/trace-cmd/trace-output.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
lib/trace-cmd/trace-output.c +8 -10
@@ -97,7 +97,7 @@ struct list_event_system {#define HAS_SECTIONS (H ) ((H)->file_version >= FILE_VERSION_SECTIONS)static int write_options (struct tracecmd_output *handle); -static int save_string_section (struct tracecmd_output *handle,bool compress); +static int save_string_section (struct tracecmd_output *handle);__hidden long long tcmd_do_write_check (struct tracecmd_output *handle,const void *data,long long size)
@@ -290,7 +290,7 @@ void tracecmd_output_flush(struct tracecmd_output *handle)write_options (handle);/* write strings section */ -save_string_section (handle, true); +save_string_section (handle); } }
@@ -610,9 +610,9 @@ static int update_endian_4(struct tracecmd_output *handle,return 0 ; } -static int save_string_section (struct tracecmd_output *handle,bool compress) +static int save_string_section (struct tracecmd_output *handle) { -enum tracecmd_section_flags flags =0 ; +enum tracecmd_section_flags flags =TRACECMD_SEC_FL_COMPRESS ;tsize_t offset;if (!handle->strings || !handle->strings_p)
@@ -624,18 +624,16 @@ static int save_string_section(struct tracecmd_output *handle, bool compress)return -1 ; } -if (compress) - flags |=TRACECMD_SEC_FL_COMPRESS ; offset =tcmd_out_write_section_header (handle,TRACECMD_OPTION_STRINGS ,"strings" , flags, false);if (offset == (off_t)-1 )return -1 ; -tcmd_out_compression_start (handle, compress); +tcmd_out_compression_start (handle, true);if (tcmd_do_write_check (handle, handle->strings, handle->strings_p)) goto error; -if (tcmd_out_compression_end (handle, compress)) +if (tcmd_out_compression_end (handle, true)) goto error;if (tcmd_out_update_section_header (handle, offset))
@@ -649,7 +647,7 @@ static int save_string_section(struct tracecmd_output *handle, bool compress)return 0 ; error: -tcmd_out_compression_reset (handle, compress); +tcmd_out_compression_reset (handle, true);return -1 ; }
@@ -2158,7 +2156,7 @@ int tracecmd_write_meta_strings(struct tracecmd_output *handle)if (!HAS_SECTIONS (handle))return 0 ; -return save_string_section (handle, true); +return save_string_section (handle); }int tracecmd_write_options (struct tracecmd_output *handle)
Signature · 1 line
2.51.0
PATCH v3 2/6 libtracecmd: Remove "compress" parameter from tcmd_out_compress*() functions
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
All the tcmd_out_compression*() functions test if the handle passed in has its "compress" field set as well as the "compress" parameter is set. If either of them are not set, then those functions return without doing anything.
But the passed in "compress" value is derived from the handle->compress field, which makes it redundant.
Remove it as it's not need.
This also removes the tcmd_out_check_compression() which was used to see if the handle had its compress field set in order to set the compress variable!
--- lib/trace-cmd/include/trace-cmd-local.h | 7 ++- lib/trace-cmd/trace-input.c | 42 ++++++++--------- lib/trace-cmd/trace-output.c | 61 ++++++++++++------------- 3 files changed, 49 insertions(+), 61 deletions(-)
lib/trace-cmd/include/trace-cmd-local.h +3 -4
@@ -65,10 +65,9 @@ bool tcmd_check_file_state(unsigned long file_version, int current_state, int nebool tcmd_check_out_state (struct tracecmd_output *handle,int new_state);int tcmd_out_uncompress_block (struct tracecmd_output *handle); -int tcmd_out_compression_start (struct tracecmd_output *handle,bool compress); -int tcmd_out_compression_end (struct tracecmd_output *handle,bool compress); -void tcmd_out_compression_reset (struct tracecmd_output *handle,bool compress); -bool tcmd_out_check_compression (struct tracecmd_output *handle); +int tcmd_out_compression_start (struct tracecmd_output *handle); +int tcmd_out_compression_end (struct tracecmd_output *handle); +void tcmd_out_compression_reset (struct tracecmd_output *handle);void tcmd_out_set_file_state (struct tracecmd_output *handle,int new_state); int tcmd_out_save_options_offset(struct tracecmd_output *handle,
lib/trace-cmd/trace-input.c +18 -24
186 lines not on this page · raw message
lib/trace-cmd/trace-output.c +28 -33
204 lines not on this page · raw message
Signature · 1 line
2.51.0
PATCH v3 3/6 libtracecmd: Add write_compress_section_header() for writing compress sections
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
All the functions that write compressed sections has a "compress" parameter this is set when the handle->compress is set. But this is redundant and can be removed.
There's one function that still calls tcmd_out_write_section_header() without the compress flag set and that's write_options_start() as the options section is never compressed.
Since all the other functions compress their sections, add a wrapper function write_compress_section_header() that calls tcmd_out_write_section_header() with its compress flag set, and have those functions use the wrapper.
--- lib/trace-cmd/trace-output.c | 93 +++++++++++++----------------------- 1 file changed, 34 insertions(+), 59 deletions(-)
lib/trace-cmd/trace-output.c +34 -59
@@ -549,6 +549,14 @@ tcmd_out_write_section_header(struct tracecmd_output *handle, unsigned short heareturn offset; } +static unsigned long long +write_compress_section_header (struct tracecmd_output *handle,unsigned short header_id, +char *description,bool option) +{ +return tcmd_out_write_section_header (handle, header_id, description, +TRACECMD_SEC_FL_COMPRESS , option); +} + __hidden int tcmd_out_update_section_header(struct tracecmd_output *handle, tsize_t offset) {tsize_t current;
@@ -612,7 +620,6 @@ static int update_endian_4(struct tracecmd_output *handle,static int save_string_section (struct tracecmd_output *handle) { -enum tracecmd_section_flags flags =TRACECMD_SEC_FL_COMPRESS ;tsize_t offset;if (!handle->strings || !handle->strings_p)
@@ -624,7 +631,7 @@ static int save_string_section(struct tracecmd_output *handle)return -1 ; } - offset =tcmd_out_write_section_header (handle,TRACECMD_OPTION_STRINGS ,"strings" , flags, false); + offset =write_compress_section_header (handle,TRACECMD_OPTION_STRINGS ,"strings" , false);if (offset == (off_t)-1 )return -1 ;
@@ -651,9 +658,8 @@ error:return -1 ; } -static int read_header_files (struct tracecmd_output *handle,bool compress) +static int read_header_files (struct tracecmd_output *handle) { -enum tracecmd_section_flags flags =0 ;tsize_t size, check_size, endian8;struct stat st;tsize_t offset;
@@ -671,10 +677,8 @@ static int read_header_files(struct tracecmd_output *handle, bool compress)if (!path)return -1 ; -if (compress) - flags |=TRACECMD_SEC_FL_COMPRESS ; - offset =tcmd_out_write_section_header (handle,TRACECMD_OPTION_HEADER_INFO , -"headers" , flags, true); + offset =write_compress_section_header (handle,TRACECMD_OPTION_HEADER_INFO , +"headers" , true);if (offset == (off_t)-1 ) {put_tracing_file (path);return -1 ;
@@ -992,9 +996,8 @@ create_event_list_item(struct tracecmd_output *handle,tracecmd_warning ("Insufficient memory" ); } -static int read_ftrace_files (struct tracecmd_output *handle,bool compress) +static int read_ftrace_files (struct tracecmd_output *handle) { -enum tracecmd_section_flags flags =0 ;struct list_event_system *systems =NULL ;struct tracecmd_event_list list = { .glob ="ftrace/*" };tsize_t offset;
@@ -1006,10 +1009,8 @@ static int read_ftrace_files(struct tracecmd_output *handle, bool compress)return -1 ; } -if (compress) - flags |=TRACECMD_SEC_FL_COMPRESS ; - offset =tcmd_out_write_section_header (handle,TRACECMD_OPTION_FTRACE_EVENTS , -"ftrace events" , flags, true); + offset =write_compress_section_header (handle,TRACECMD_OPTION_FTRACE_EVENTS , +"ftrace events" , true);if (offset == (off_t)-1 )return -1 ;
@@ -1047,9 +1048,8 @@ create_event_list(struct tracecmd_output *handle, }static int read_event_files (struct tracecmd_output *handle, -struct tracecmd_event_list *event_list,bool compress) +struct tracecmd_event_list *event_list) { -enum tracecmd_section_flags flags =0 ;struct list_event_system *systems;struct list_event_system *slist;struct tracecmd_event_list *list;
@@ -1065,10 +1065,8 @@ static int read_event_files(struct tracecmd_output *handle,return -1 ; } -if (compress) - flags |=TRACECMD_SEC_FL_COMPRESS ; - offset =tcmd_out_write_section_header (handle,TRACECMD_OPTION_EVENT_FORMATS , -"events format" , flags, true); + offset =write_compress_section_header (handle,TRACECMD_OPTION_EVENT_FORMATS , +"events format" , true);if (offset == (off_t)-1 )return -1 ;/*
@@ -1161,9 +1159,8 @@ err:tracecmd_warning ("can't set kptr_restrict" ); } -static int read_proc_kallsyms (struct tracecmd_output *handle,bool compress) +static int read_proc_kallsyms (struct tracecmd_output *handle) { -enum tracecmd_section_flags flags =0 ;unsigned int size, check_size, endian4;const char *path ="/proc/kallsyms" ;off_t size_offset;
@@ -1180,10 +1177,8 @@ static int read_proc_kallsyms(struct tracecmd_output *handle, bool compress)if (handle->kallsyms) path = handle->kallsyms; -if (compress) - flags |=TRACECMD_SEC_FL_COMPRESS ; - offset =tcmd_out_write_section_header (handle,TRACECMD_OPTION_KALLSYMS , -"kallsyms" , flags, true); + offset =write_compress_section_header (handle,TRACECMD_OPTION_KALLSYMS , +"kallsyms" , true);if (offset == (off_t)-1 )return -1 ;
@@ -1228,9 +1223,8 @@ out:return ret; } -static int read_ftrace_printk (struct tracecmd_output *handle,bool compress) +static int read_ftrace_printk (struct tracecmd_output *handle) { -enum tracecmd_section_flags flags =0 ;unsigned int size, check_size, endian4;tsize_t offset;struct stat st;
@@ -1247,9 +1241,7 @@ static int read_ftrace_printk(struct tracecmd_output *handle, bool compress)if (!path)return -1 ; -if (compress) - flags |=TRACECMD_SEC_FL_COMPRESS ; - offset =tcmd_out_write_section_header (handle,TRACECMD_OPTION_PRINTK ,"printk" , flags, true); + offset =write_compress_section_header (handle,TRACECMD_OPTION_PRINTK ,"printk" , true);if (offset == (off_t)-1 ) {put_tracing_file (path);return -1 ;
@@ -1715,25 +1707,21 @@ static int output_write_init(struct tracecmd_output *handle)int tracecmd_output_write_headers (struct tracecmd_output *handle,struct tracecmd_event_list *list) { -bool compress = false; -if (!handle || handle->file_state <TRACECMD_FILE_ALLOCATED )return -1 ;/* Write init data, if not written yet */ if (handle->file_state <TRACECMD_FILE_INIT &&output_write_init (handle))return -1 ; -if (handle->compress) - compress = true; -if (read_header_files (handle, compress)) +if (read_header_files (handle))return -1 ; -if (read_ftrace_files (handle, compress)) +if (read_ftrace_files (handle))return -1 ; -if (read_event_files (handle, list, compress)) +if (read_event_files (handle, list))return -1 ; -if (read_proc_kallsyms (handle, compress)) +if (read_proc_kallsyms (handle))return -1 ; -if (read_ftrace_printk (handle, compress)) +if (read_ftrace_printk (handle))return -1 ;return 0 ; }
@@ -2304,8 +2292,6 @@ static tsize_t get_buffer_file_offset(struct tracecmd_output *handle, const charint tracecmd_write_cmdlines (struct tracecmd_output *handle) { -enum tracecmd_section_flags flags =0 ; -bool compress = false;tsize_t offset;int ret;
@@ -2315,13 +2301,8 @@ int tracecmd_write_cmdlines(struct tracecmd_output *handle)return -1 ; } -if (handle->compress) - compress = true; - -if (compress) - flags |=TRACECMD_SEC_FL_COMPRESS ; - offset =tcmd_out_write_section_header (handle,TRACECMD_OPTION_CMDLINES , -"command lines" , flags, true); + offset =write_compress_section_header (handle,TRACECMD_OPTION_CMDLINES , +"command lines" , true);if (offset == (off_t)-1 )return -1 ;
@@ -2456,7 +2437,6 @@ tcmd_out_add_buffer_option(struct tracecmd_output *handle, const char *name,struct tracecmd_output *tracecmd_create_file_latency (const char *output_file,int cpus,int file_version,const char *compression) { -enum tracecmd_section_flags flags =0 ;struct tracecmd_output *handle;tsize_t offset;char *path;
@@ -2508,11 +2488,9 @@ struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, in !tcmd_out_add_buffer_option(handle, "", TRACECMD_OPTION_BUFFER_TEXT, offset, 0, NULL, getpagesize())) goto out_free; -if (handle->compress) - flags |=TRACECMD_SEC_FL_COMPRESS ; - offset =tcmd_out_write_section_header (handle,TRACECMD_OPTION_BUFFER_TEXT , -"buffer latency" , flags, false); + offset =write_compress_section_header (handle,TRACECMD_OPTION_BUFFER_TEXT , +"buffer latency" , false);copy_file_compress (handle, path,NULL );if (tcmd_out_update_section_header (handle, offset))
@@ -2631,7 +2609,6 @@ __hidden int tcmd_out_write_cpu_data(struct tracecmd_output *handle, const char *buff_name) {struct data_file_write *data_files =NULL ; -enum tracecmd_section_flags flags =0 ;tsize_t data_offs, offset;unsigned long long endian8;unsigned long long read_size;
@@ -2661,11 +2638,9 @@ __hidden int tcmd_out_write_cpu_data(struct tracecmd_output *handle,if (!HAS_SECTIONS (handle) &&tcmd_do_write_check (handle,"flyrecord" ,10 )) goto out_free; -if (handle->compress) - flags |=TRACECMD_SEC_FL_COMPRESS ;if (asprintf (&str,"buffer flyrecord %s" , buff_name) <1 ) goto out_free; - offset =tcmd_out_write_section_header (handle,TRACECMD_OPTION_BUFFER , str, flags, false); + offset =write_compress_section_header (handle,TRACECMD_OPTION_BUFFER , str, false);free (str);if (offset == (off_t)-1 ) goto out_free;
@@ -2749,7 +2724,7 @@ __hidden int tcmd_out_write_cpu_data(struct tracecmd_output *handle,if (!tracecmd_get_quiet (handle)) {fprintf (stderr," %llu bytes in size" , (unsigned long long )data_files[i].write_size); -if (flags &TRACECMD_SEC_FL_COMPRESS ) +if (handle->compress)fprintf (stderr," (%llu uncompressed)" , (unsigned long long )data_files[i].file_size);fprintf (stderr,"\n" );
Signature · 1 line
2.51.0
PATCH v3 4/6 trace-cmd record / report: Record BTF file if function arguments are recorded
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
If function tracer is recorded with func-args option set, or the function_graph tracer is recorded with the funcgraph-args option set, then record the BTF file in a new BTF_FILE section in the trace.dat file.
This is compressed on disk, and when the trace.dat file is read, it is loaded into memory and sent to the libtraceevent tep_load_btf() function.
This will be used to show arguments of the function tracer:
cat-33501 [005] ..... 136155.767937: function: mutex_unlock(lock=0xffffffff831dbbe0)
cat-33501 [005] ..... 136155.767939: function: __mutex_unlock_slowpath(lock=0xffffffff831dbbe0, ip=0xffffffff814a7154)
cat-33501 [005] ..... 136155.767940: function: __f_unlock_pos(f=0xffff8881538de000)
cat-33501 [005] ..... 136155.767940: function: mutex_unlock(lock=0xffff8881538de090)
cat-33501 [005] ..... 136155.767940: function: __mutex_unlock_slowpath(lock=0xffff8881538de090, ip=0xffffffff816e8ed1)
cat-33501 [005] ..... 136155.767941: function: mem_cgroup_handle_over_high(gfp_mask=0xcc0)
cat-33501 [005] ..... 136155.767941: function: blkcg_maybe_throttle_current()
cat-33501 [005] ..... 136155.767942: function: __rseq_handle_notify_resume(ksig=0x0, regs=0xffffc9000e3eff58)
cat-33501 [005] d.... 136155.767943: function: fpregs_assert_state_consistent()
cat-33501 [005] d.... 136155.767943: function: switch_fpu_return()
cat-33501 [005] ..... 136155.767950: function: __x64_sys_execve(regs=0xffffc9000e3eff58)
cat-33501 [005] ..... 136155.767951: function: getname_flags(filename=0x7ffe7d33f3d0, flags=0)
cat-33501 [005] ..... 136155.767951: function: getname_flags.part.0(7ffe7d33f3d0, 0, 0, 0, 0, 0)
cat-33501 [005] ..... 136155.767951: function: kmem_cache_alloc_noprof(s=0xffff8881001d3800, gfpflags=0xcc0)Note, the parsing of BTF from the trace.dat file requires libtraceevent version 1.9 or higher.
---
Changes since v2: https://lore.kernel.org/[email protected]
- Fixed tracecmd_append_btf_file() exiting out early when btf file doesn't exist. That would cause the offset to be incorrect and the next write to the trace.dat file would corrupt it. This happened with trace-cmd extract.
Makefile | 9 +++ .../include/private/trace-cmd-private.h | 3 + lib/trace-cmd/trace-compress.c | 26 ++++++++ lib/trace-cmd/trace-input.c | 26 ++++++++ lib/trace-cmd/trace-output.c | 64 +++++++++++++++++++ meson.build | 3 + tracecmd/trace-record.c | 42 +++++++++++- 7 files changed, 172 insertions(+), 1 deletion(-)
Makefile +9 -0
@@ -230,6 +230,8 @@ LIBTRACEFS=libtracefs TEST_LIBTRACEEVENT := $(shell sh -c "$(PKG_CONFIG) --atleast-version $(LIBTRACEEVENT_MIN_VERSION) $(LIBTRACEEVENT) > /dev/null 2>&1 && echo y") TEST_LIBTRACEFS := $(shell sh -c "$(PKG_CONFIG) --atleast-version $(LIBTRACEFS_MIN_VERSION) $(LIBTRACEFS) > /dev/null 2>&1 && echo y") +TEST_LIBTRACEEVENT_BTF := $(shell sh -c "$(PKG_CONFIG) --atleast-version 1.9 $(LIBTRACEEVENT) > /dev/null 2>&1 && echo y") + ifeq ("$(TEST_LIBTRACEEVENT)", "y") LIBTRACEEVENT_CFLAGS := $(shell sh -c "$(PKG_CONFIG) --cflags $(LIBTRACEEVENT)") LIBTRACEEVENT_LDLAGS := $(shell sh -c "$(PKG_CONFIG) --libs $(LIBTRACEEVENT)")
@@ -247,6 +249,13 @@ warning: @echo "********************************************" endif +ifeq ("$(TEST_LIBTRACEEVENT_BTF)", "y") +CFLAGS += -DHAVE_KERNEL_BTF +else +.PHONY: warning +$(info Min version libtraceevent 1.9 not found. Will not use BTF for function args) +endif + export LIBTRACEEVENT_CFLAGS LIBTRACEEVENT_LDLAGS ifeq ("$(TEST_LIBTRACEFS)", "y")
lib/trace-cmd/include/private/trace-cmd-private.h +3 -0
@@ -159,6 +159,7 @@ enum {TRACECMD_OPTION_PRINTK ,TRACECMD_OPTION_CMDLINES ,TRACECMD_OPTION_BUFFER_TEXT , +TRACECMD_OPTION_BTF_FILE , TRACECMD_OPTION_MAX, };
@@ -340,6 +341,7 @@ int tracecmd_append_buffer_cpu_data(struct tracecmd_output *handle,struct tracecmd_output *tracecmd_get_output_handle_fd (int fd);unsigned long tracecmd_get_out_file_version (struct tracecmd_output *handle);size_t tracecmd_get_out_file_offset (struct tracecmd_output *handle); +int tracecmd_append_btf_file (struct tracecmd_output *handle);/* --- Reading the Fly Recorder Trace --- */
@@ -568,6 +570,7 @@ int tracecmd_uncompress_chunk(struct tracecmd_compression *handle, struct tracecmd_compress_chunk *chunk, char *data);int tracecmd_load_chunks_info (struct tracecmd_compression *handle,struct tracecmd_compress_chunk **chunks_info); +void *tracecmd_uncompress_buffer (struct tracecmd_compression *handle,size_t *size);/* --- Plugin handling --- */ extern struct tep_plugin_option trace_ftrace_options[];
lib/trace-cmd/trace-compress.c +26 -0
@@ -366,6 +366,32 @@ out:free (buf);return ret; } +/** +* tracecmd_uncompress_buffer - Returned the current uncompressed buffer +* @handle: compression handle +* @size: A pointer to place the size of the uncompressed buffer in +* +* Returns the current uncompressed buffer and resets the compression +* @handle. +* +* Returns the buffer (must be freed with free()) or NULL. +* @size (if not NULL) will contain the size of the uncompressed buffer. +*/ +void *tracecmd_uncompress_buffer (struct tracecmd_compression *handle,size_t *size) +{ +void *buffer; + +if (!handle) +return NULL ; + +if (size) + *size = handle->capacity; + + buffer = handle->buffer; + handle->buffer =NULL ; +tracecmd_compress_reset (handle); +return buffer; +}/** * tracecmd_compress_buffer_write - write() to compression buffer
lib/trace-cmd/trace-input.c +26 -0
@@ -1026,6 +1026,28 @@ static int read_ftrace_printk(struct tracecmd_input *handle)return 0 ; } +#ifdef HAVE_KERNEL_BTF +static int read_btf (struct tracecmd_input *handle) +{ +void *raw_data; +size_t size; + + raw_data =tracecmd_uncompress_buffer (handle->compress, &size); +if (!raw_data) +return -1 ; + +tep_load_btf (handle->pevent, raw_data, size); + +free (raw_data); +return 0 ; +} +#else +static inline int read_btf (struct tracecmd_input *handle) +{ +return 0 ; +} +#endif +static int read_and_parse_cmdlines (struct tracecmd_input *handle);/**
@@ -1203,6 +1225,9 @@ static int handle_section(struct tracecmd_input *handle, struct file_section *secase TRACECMD_OPTION_CMDLINES : ret =read_and_parse_cmdlines (handle);break ; +case TRACECMD_OPTION_BTF_FILE : + ret =read_btf (handle); +break ;default : ret =0 ;break ;
@@ -4208,6 +4233,7 @@ static int handle_options(struct tracecmd_input *handle)case TRACECMD_OPTION_KALLSYMS :case TRACECMD_OPTION_PRINTK :case TRACECMD_OPTION_CMDLINES : +case TRACECMD_OPTION_BTF_FILE :if (size <8 )break ; section_add_or_update(handle, option, -1,
lib/trace-cmd/trace-output.c +64 -0
70 lines not on this page · raw message
meson.build +3 -0
@@ -25,8 +25,11 @@ htmldir = join_paths(prefixdir, get_option('htmldir')) conf = configuration_data() libtraceevent_dep = dependency('libtraceevent', version: '>= 1.5.0', required: true) +libtraceevent_btf_dep = dependency('libtraceevent', version: '>= 1.9', required: false) libtracefs_dep = dependency('libtracefs', version: '>= 1.8.0', required: true) +conf.set('HAVE_KERNEL_BTF', libtraceevent_btf_dep.found(), description: 'Is BTF parsing available?') + threads_dep = dependency('threads', required: true) dl_dep = cc.find_library('dl', required : false)
tracecmd/trace-record.c +41 -1
64 lines not on this page · raw message
Signature · 1 line
2.51.0
Re: [PATCH v3 4/6] trace-cmd record / report: Record BTF file if function arguments are recorded
Quoted 27 lines · On Mon, 2 Feb 2026 17:36:59 -0500 Steven Rostedt <[email protected]> wrote:
lib/trace-cmd/trace-output.c +27
-0+#define BTF_FILE "/sys/kernel/btf/vmlinux" + +int tracecmd_append_btf_file (struct tracecmd_output *handle) +{ +tsize_t offset, size, check_size; +struct tracecmd_option *option; +struct iovec *vect; +struct stat st; +int ret; + +if (!HAS_SECTIONS (handle)) +return -1 ; + + ret =stat (BTF_FILE , &st); +if (ret <0 ) +return -1 ; + + offset =write_compress_section_header (handle,TRACECMD_OPTION_BTF_FILE ,NULL , true); +if (offset == (off_t)-1 ) +return -1 ; + +tcmd_out_compression_start (handle); + + check_size =copy_file (handle,BTF_FILE ); +if (st.st_size != check_size) { + errno =EINVAL ; +tracecmd_warning ("error in size of file '%s'" ,BTF_FILE );
lib/trace-cmd/trace-output.c int tracecmd_write_cmdlines(struct tracecmd_output *handle) · line 2363
Quoted 10 lines
lib/trace-cmd/trace-output.c +10
-0+return -1 ; + } + +if (tcmd_out_compression_end (handle)) +return -1 ; + +if (tcmd_out_update_section_header (handle, offset)) +return -1 ; + +return 0 ;
Bah, the below was from some old versions. I keep forgetting to remove it.
Will be sending a v4 shortly.
-- Steve
Quoted 27 lines
lib/trace-cmd/trace-output.c +27
-0+ +/* +* BTF file +* - data offset in the file +* - data size +*/ + + vect =calloc (2 ,sizeof (struct iovec )); +if (!vect) +return -1 ; + vect[0 ].iov_base = &offset; + vect[0 ].iov_len =8 ; + vect[1 ].iov_base = &size; + vect[1 ].iov_len =8 ; + + option =tracecmd_add_option_v (handle,TRACECMD_OPTION_BTF_FILE , vect,2 ); +free (vect); + +if (!option) +return -1 ; + +if (do_lseek (handle,0 ,SEEK_END ) == (off_t)-1 ) +return -1 ; + +return 0 ; +} +
PATCH v3 5/6 libtracecmd: Add printing of arguments for function graph tracer
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
If the function graph tracer was recorded with the funcgraph-args option set, then the BTF file would also be recorded. Print the contents of the arguments with the information provided by BTF.
The output will look like this:
cat-43792 [006] ..... 147894.472393: funcgraph_entry: | mutex_unlock(lock=0xffffffff831dbbe0) {
cat-43792 [006] ..... 147894.472394: funcgraph_entry: 1.005 us | __mutex_unlock_slowpath(lock=0xffffffff831dbbe0, ip=0xffffffff812f2e30); (ret=0x0)
cat-43792 [006] ..... 147894.472396: funcgraph_exit: 3.581 us | } (ret=0x0)
cat-43792 [006] ..... 147894.472397: funcgraph_entry: | __f_unlock_pos(f=0xffff8881538df980) {
cat-43792 [006] ..... 147894.472397: funcgraph_entry: | mutex_unlock(lock=0xffff8881538dfa10) {
cat-43792 [006] ..... 147894.472397: funcgraph_entry: 0.434 us | __mutex_unlock_slowpath(lock=0xffff8881538dfa10, ip=0xffffffff812f2e30); (ret=0x0)
cat-43792 [006] ..... 147894.472398: funcgraph_exit: 1.216 us | } (ret=0x0)
cat-43792 [006] ..... 147894.472399: funcgraph_exit: 2.152 us | } (ret=0x0)
cat-43792 [006] d.... 147894.472399: funcgraph_entry: 0.360 us | fpregs_assert_state_consistent(); (ret=0x6)
cat-43792 [006] ..... 147894.472403: funcgraph_entry: | __x64_sys_execve(regs=0xffffc900029f3f58) {
cat-43792 [006] ..... 147894.472404: funcgraph_entry: | getname_flags(filename=0x7fff4a902080, flags=0) {
cat-43792 [006] ..... 147894.472404: funcgraph_entry: | getname_flags.part.0(7fff4a902080, 0, 0, 0, 0, 0) {
cat-43792 [006] ..... 147894.472405: funcgraph_entry: | kmem_cache_alloc_noprof(s=0xffff8881001d3800, gfpflags=0xcc0) {
cat-43792 [006] ..... 147894.472405: funcgraph_entry: 0.618 us | fs_reclaim_acquire(gfp_mask=0xcc0); (ret=0x0)
cat-43792 [006] ..... 147894.472406: funcgraph_entry: 0.380 us | fs_reclaim_release(gfp_mask=0xcc0); (ret=0x0)
cat-43792 [006] ..... 147894.472407: funcgraph_entry: | kmemleak_alloc(ptr=0xffff8881120b0000, size=0x1000, min_count=1, gfp=0xcc0) {
cat-43792 [006] ..... 147894.472408: funcgraph_entry: | __create_object(ptr=0xffff8881120b0000, size=0x1000, min_count=1, gfp=0xcc0, objflags=0x0) {
cat-43792 [006] ..... 147894.472408: funcgraph_entry: | __alloc_object(gfp=0xcc0) {
cat-43792 [006] ..... 147894.472408: funcgraph_entry: | kmem_cache_alloc_noprof(s=0xffff888100045700, gfpflags=0x92cc0) {
cat-43792 [006] ..... 147894.472409: funcgraph_entry: 0.570 us | fs_reclaim_acquire(gfp_mask=0x92cc0); (ret=0x0)
cat-43792 [006] ..... 147894.472410: funcgraph_entry: 0.370 us | fs_reclaim_release(gfp_mask=0x92cc0); (ret=0x0)
cat-43792 [006] ..... 147894.472411: funcgraph_exit: 2.226 us | } (ret=0xffff88814bbcf6a8)Even if libtraceevent 1.9 is not available, print the raw arg registers if they exist in the function entry event.
--- lib/trace-cmd/trace-ftrace.c | 58 ++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 6 deletions(-)
lib/trace-cmd/trace-ftrace.c +52 -6
@@ -198,6 +198,48 @@ static void print_graph_duration(struct trace_seq *s, unsigned long long duratiotrace_seq_puts (s,"| " ); } +/* Returns true if it printed args, otherwise it returns false */ +static bool print_args (struct trace_seq *s,struct tep_event *event, +struct tep_record *record,const char *func) +{ +struct tep_format_field *field; +int long_size =tep_get_long_size (event->tep); +void *args; +int len; + +if (!long_size) + long_size =sizeof (long ); + + field =tep_find_field (event,"args" ); +if (!field) +return false; + + len = record->size - field->offset; + + len /= long_size; + + args = record->data + field->offset; + +#ifdef HAVE_KERNEL_BTF +tep_btf_print_args (event->tep, s, args, len, long_size, func); +#else +for (int i =0 ; i < len; i++) { +void *arg; + +if (i) +trace_seq_puts (s,", " ); + + arg = args + i * long_size; +if (long_size ==4 ) +trace_seq_printf (s,"%x" , *(unsigned int *)arg); +else +trace_seq_printf (s,"%llx" , *(unsigned long long *)arg); + } +#endif + +return true; +} + static int print_graph_entry_leaf(struct trace_seq *s, struct tep_event *event,
@@ -247,9 +289,11 @@ print_graph_entry_leaf(struct trace_seq *s,return trace_seq_putc (s,'!' ); func =tep_find_function (pevent, val); -if (func) - ret =trace_seq_printf (s,"%s();" , func); -else +if (func) { + ret =trace_seq_printf (s,"%s(" , func); +print_args (s, event, record, func); + ret =trace_seq_puts (s,");" ); + }else ret =trace_seq_printf (s,"%llx();" , val);if (ret && fgraph_depth->set)
@@ -302,9 +346,11 @@ static int print_graph_nested(struct trace_seq *s, func =tep_find_function (pevent, val); -if (func) - ret =trace_seq_printf (s,"%s() {" , func); -else +if (func) { + ret =trace_seq_printf (s,"%s(" , func); +print_args (s, event, record, func); + ret =trace_seq_puts (s,") {" ); + }else ret =trace_seq_printf (s,"%llx() {" , val);if (ret && fgraph_depth->set)
Signature · 1 line
2.51.0
PATCH v3 6/6 trace-cmd documenatation: Update the trace.dat man page for BTF_FILE
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
Now that the trace.dat file has a way to store the BTF file, update the documentation about it.
--- .../trace-cmd/trace-cmd.dat.v7.5.txt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
Documentation/trace-cmd/trace-cmd.dat.v7.5.txt +19 -0
@@ -270,6 +270,11 @@ OPTIONS SECTION <string> a null terminated ASCII string, trace clock used for events timestamps in this trace instance. + BTF_FILE: id 23, size 8 + The BTF_FILE option data is: + A compressed data from the host file /sys/kernel/btf/vmlinux, using the + compression algorthim defined by the trace.dat header. The compression data + includes the size of the uncompressed output. HEADER INFO SECTION -------------------
@@ -438,6 +443,20 @@ STRINGS SECTION meta data, which is the offset of the actual string into the string section. Strings can be stored into multiple string sections in the file. +BTF FILE SECTION +---------------- + + Section ID: 23 + + Directly after the section header comes the information mapping + a PID to a process name. + + The next 8 bytes contain a 64-bit word that holds the size of the + data mapping the PID to a process name. + + The next set of data is of the size defined by the previous 8 bytes + and contains the information from /sys/kernel/btf/vmlinux. + SEE ALSO -------- trace-cmd(1), trace-cmd-record(1), trace-cmd-report(1), trace-cmd-start(1),
Signature · 1 line
2.51.0