libtracefs: synthetic event fixes
cover libtracefs: synthetic event fixes
From: "Steven Rostedt (Google)" <[email protected]>
While working on some utilities to create synthetic events, I was testing on both older (4.19) and newer kernels and found a few bugs along the way.
This fixes a memory initialization issue, and errors in displaying commands to create synthetic events that work on both new and older kernels.
Steven Rostedt (Google) (4):
libtracefs: Initialized func_list in tracefs_filter_functions()
libtracefs: Fix tracefs_synth_echo_cmd()
libtracefs: Check README to know if we should do old onmatch format
libtracefs: Have synthetic events use types pid_t, gfp_t and bool
src/tracefs-hist.c | 53 ++++++++++++++++++++++++++++++++++++++++----- src/tracefs-tools.c | 2 +- 2 files changed, 49 insertions(+), 6 deletions(-)
Signature · 1 line
2.33.0
PATCH 1/4 libtracefs: Initialized func_list in tracefs_filter_functions()
From: "Steven Rostedt (Google)" <[email protected]>
The variable func_list is used to create a link list and it is expected to be NULL. This causes a crash because of the logic checks it before it gets initialized.
Initialize func_list to NULL.
This was found by valgrind after a crash.
--- src/tracefs-tools.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/tracefs-tools.c +1 -1
@@ -1237,7 +1237,7 @@ void tracefs_trace_pipe_stop(struct tracefs_instance *instance)int tracefs_filter_functions (const char *filter,const char *module,char ***list) {struct func_filter func_filter; -struct func_list *func_list, *f; +struct func_list *func_list =NULL , *f;char **funcs =NULL ;int ret;
Signature · 1 line
2.33.0
PATCH 2/4 libtracefs: Fix tracefs_synth_echo_cmd()
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
The update to use dynamic_events instead of synthetic_events for echoing the synthetic event missed out on adding the colon, and made the output incorrect for the new format.
--- src/tracefs-hist.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
src/tracefs-hist.c +4 -2
@@ -2155,8 +2155,10 @@ int tracefs_synth_echo_cmd(struct trace_seq *seq,if (!path) goto out_free; -trace_seq_printf (seq,"echo '%s%s %s' > %s/%s\n" , - synth->dyn_event->prefix, synth->dyn_event->event, +trace_seq_printf (seq,"echo '%s%s%s %s' > %s/%s\n" , + synth->dyn_event->prefix, +strlen (synth->dyn_event->prefix) ?":" :"" , + synth->dyn_event->event, synth->dyn_event->format, path, synth->dyn_event->trace_file);tracefs_put_tracing_file (path);
Signature · 1 line
2.33.0
PATCH 3/4 libtracefs: Check README to know if we should do old onmatch format
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
Older kernels use:
onmatch(..).synth_event(...)
Where the "synth_event" is the synthetic event that was created. The new format uses:
onmatch(..).trace(synth_event,...)
Where it uses the new "trace" command and the synthetic event is the first parameter.
The tracefs README can determine which format is used. Search the README and if the string "trace(<synthetic_event>,param list)" is found, then we know that the kernel uses the new format. Yes, the README in the tracefs file system *is* an ABI.
--- src/tracefs-hist.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-)
src/tracefs-hist.c +35 -3
@@ -674,6 +674,7 @@ struct action {* @end_filters: The fields in the end event to record * @start_parens: Current parenthesis level for start event * @end_parens: Current parenthesis level for end event +* @new_format: onmatch().trace(synth_event,..) or onmatch().synth_event(...) */ struct tracefs_synth {struct tracefs_instance *instance;
@@ -702,6 +703,7 @@ struct tracefs_synth {int *start_type;char arg_name[16 ];int arg_cnt; +bool new_format; };/*
@@ -949,6 +951,26 @@ static int alloc_synthetic_event(struct tracefs_synth *synth)return synth->dyn_event ?0 :-1 ; } +/* +* See if it is onmatch().trace(synth_event,...) or +* onmatch().synth_event(...) +*/ +static bool has_new_format () +{ +char *readme; +char *p; +int size; + + readme =tracefs_instance_file_read (NULL ,"README" , &size); +if (!readme) +return false; + + p =strstr (readme,"trace(<synthetic_event>,param list)" ); +free (readme); + +return p !=NULL ; +} +/** * tracefs_synth_alloc - create a new tracefs_synth instance * @tep: The tep handle that holds the events to work on
@@ -1037,6 +1059,8 @@ struct tracefs_synth *tracefs_synth_alloc(struct tep_handle *tep, synth =NULL ; } + synth->new_format =has_new_format (); +return synth; }
@@ -1730,13 +1754,21 @@ static char *create_trace(char *hist, struct tracefs_synth *synth)char *name;int i; - hist =append_string (hist,NULL ,".trace(" ); - hist =append_string (hist,NULL , synth->name); +if (synth->new_format) { + hist =append_string (hist,NULL ,".trace(" ); + hist =append_string (hist,NULL , synth->name); + hist =append_string (hist,NULL ,"," ); + }else { + hist =append_string (hist,NULL ,"." ); + hist =append_string (hist,NULL , synth->name); + hist =append_string (hist,NULL ,"(" ); + }for (i =0 ; synth->synthetic_args && synth->synthetic_args[i]; i++) { name = synth->synthetic_args[i]; - hist =append_string (hist,NULL ,"," ); +if (i) + hist =append_string (hist,NULL ,"," ); hist =append_string (hist,NULL , name); }
Signature · 1 line
2.33.0
PATCH 4/4 libtracefs: Have synthetic events use types pid_t, gfp_t and bool
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
The synthetic events understand pid_t, gfp_t and bool, and it is better to use them, as some kernels have bugs where a field with one of the above types may not match the raw format they are.
That is, pid_t may not match s32, even though they are the same type!
--- src/tracefs-hist.c | 9 +++++++++ 1 file changed, 9 insertions(+)
src/tracefs-hist.c +9 -0
@@ -841,6 +841,15 @@ static char *add_synth_field(const struct tep_format_field *field,return append_string (str,NULL ,"];" ); } +/* Synthetic events understand pid_t, gfp_t and bool */ +if (strcmp (field->type,"pid_t" ) ==0 || +strcmp (field->type,"gfp_t" ) ==0 || +strcmp (field->type,"bool" ) ==0 ) { + str =strdup (field->type); + str =append_string (str," " , name); +return append_string (str,NULL ,";" ); + } + sign = field->flags &TEP_FIELD_IS_SIGNED ;switch (field->size) {
Signature · 1 line
2.33.0