aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt (Google) <rostedt@goodmis.org>2022-01-31 11:36:41 -0500
committerSteven Rostedt (Google) <rostedt@goodmis.org>2022-02-02 21:58:41 -0500
commit74a6754b9e67b572a2c99945b1f8e08c09e4d113 (patch)
tree7678d6f7381b28ebf14a7fd3a5c757c9030b051b
parent29a06f7619b419146920ed38e4dce880eb769077 (diff)
downloadlibtracefs-74a6754b9e67b572a2c99945b1f8e08c09e4d113.tar.gz
libtracefs: Check README to know if we should do old onmatch format
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. Link: https://lore.kernel.org/linux-trace-devel/20220131163642.2754485-4-rostedt@goodmis.org Fixes: 7c9000c7495b9 ("libtracefs: Create a way to create a synthetic event") Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
-rw-r--r--src/tracefs-hist.c38
1 files changed, 35 insertions, 3 deletions
diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c
index 622fe5c..ec63b88 100644
--- a/src/tracefs-hist.c
+++ b/src/tracefs-hist.c
@@ -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);
}