aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>2023-03-28 18:03:20 +0300
committerSteven Rostedt (Google) <rostedt@goodmis.org>2023-05-30 00:32:16 -0400
commit003917316e5d9e9ba3b682752e183753bef2a8db (patch)
tree944c67aafe546248591587d7c677894983b2482c
parente97c311389c4b91e2044cddd0c33417b969329d7 (diff)
downloadlibtracefs-003917316e5d9e9ba3b682752e183753bef2a8db.tar.gz
libtracefs: New API to set synthetic event instance
The current implementation of tracefs_synth_create() API always creates the synthetic event in the top trace instance - the "trigger" files of the start and end events are updated in the context of the top instance. Then the same synthetic event can be enabled and operates in any trace instance. That logic works well in the most use cases, where there is a single application, managing these events and the trace process. However, there are use cases where multiple applications can run different trace sessions, each in its own trace instance. For those use cases, the default logic does not work well - the synthetic event can be created by one application in the top instance, and cannot be reused easily by any other applications in different trace instance. The tracefs_synth structure already has an instance context, but there is no way to set it to other than default top instance. That's why a new API is introduced: tracefs_synth_set_instance(), which sets the instance in the tracefs_synth structure. If that API is called before tracefs_synth_create(), then the "trigger" files will be updated only in the context of that user instance, instead of the default one. This allows synthetic events to be more flexible and reduces the interference between different trace instance. Link: https://lore.kernel.org/linux-trace-devel/20230328150321.34808-2-tz.stoyanov@gmail.com Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
-rw-r--r--include/tracefs.h1
-rw-r--r--src/tracefs-hist.c19
2 files changed, 20 insertions, 0 deletions
diff --git a/include/tracefs.h b/include/tracefs.h
index 245a99d..a8e30a5 100644
--- a/include/tracefs.h
+++ b/include/tracefs.h
@@ -612,6 +612,7 @@ struct tracefs_hist *tracefs_synth_get_start_hist(struct tracefs_synth *synth);
int tracefs_synth_create(struct tracefs_synth *synth);
int tracefs_synth_destroy(struct tracefs_synth *synth);
void tracefs_synth_free(struct tracefs_synth *synth);
+int tracefs_synth_set_instance(struct tracefs_synth *synth, struct tracefs_instance *instance);
int tracefs_synth_echo_cmd(struct trace_seq *seq, struct tracefs_synth *synth);
int tracefs_synth_raw_fmt(struct trace_seq *seq, struct tracefs_synth *synth);
const char *tracefs_synth_show_event(struct tracefs_synth *synth);
diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c
index e8d984b..1e3df6c 100644
--- a/src/tracefs-hist.c
+++ b/src/tracefs-hist.c
@@ -2195,6 +2195,25 @@ tracefs_synth_get_start_hist(struct tracefs_synth *synth)
}
/**
+ * tracefs_synth_set_instance - Set the ftrace instance of the synthetic events
+ * @synth: The tracefs_synth descriptor
+ * @instance: ftrace instance
+ *
+ * Set the ftrace instance, in which the synthetic event will be created. By default,
+ * the top instance is used. This API must be called before the call to tracefs_synth_create(),
+ * in order to use the new instance when creating the event.
+ *
+ * Returns 0 on success and -1 on error.
+ */
+int tracefs_synth_set_instance(struct tracefs_synth *synth, struct tracefs_instance *instance)
+{
+ if (!synth)
+ return -1;
+ synth->instance = instance;
+ return 0;
+}
+
+/**
* tracefs_synth_create - creates the synthetic event on the system
* @synth: The tracefs_synth descriptor
*