[PATCH 1/7] libtracefs: Move creating of onmatch handler and trace action into helper functions

From: Steven Rostedt
Date: Thu Aug 12 2021 - 22:17:48 EST


From: "Steven Rostedt (VMware)" <rostedt@xxxxxxxxxxx>

Have the creation of the onmatch handler and the trace action both be in
their own helper function. This will help when adding other handlers
like onmax and onchange as well as other actions like snapshot and save.

Signed-off-by: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx>
---
src/tracefs-hist.c | 38 +++++++++++++++++++++++++-------------
1 file changed, 25 insertions(+), 13 deletions(-)

diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c
index fefe251995ba..7fffa6cc653d 100644
--- a/src/tracefs-hist.c
+++ b/src/tracefs-hist.c
@@ -1378,28 +1378,40 @@ static char *create_hist(char **keys, char **vars)
return hist;
}

-static char *create_end_hist(struct tracefs_synth *synth)
+static char *create_onmatch(char *hist, struct tracefs_synth *synth)
{
- const char *name;
- char *end_hist;
+ hist = append_string(hist, NULL, ":onmatch(");
+ hist = append_string(hist, NULL, synth->start_event->system);
+ hist = append_string(hist, NULL, ".");
+ hist = append_string(hist, NULL, synth->start_event->name);
+ return append_string(hist, NULL, ")");
+}
+
+static char *create_trace(char *hist, struct tracefs_synth *synth)
+{
+ char *name;
int i;

- end_hist = create_hist(synth->end_keys, synth->end_vars);
- end_hist = append_string(end_hist, NULL, ":onmatch(");
- end_hist = append_string(end_hist, NULL, synth->start_event->system);
- end_hist = append_string(end_hist, NULL, ".");
- end_hist = append_string(end_hist, NULL, synth->start_event->name);
- end_hist = append_string(end_hist, NULL, ").trace(");
- end_hist = append_string(end_hist, NULL, synth->name);
+ hist = append_string(hist, NULL, ".trace(");
+ hist = append_string(hist, NULL, synth->name);

for (i = 0; synth->synthetic_args && synth->synthetic_args[i]; i++) {
name = synth->synthetic_args[i];

- end_hist = append_string(end_hist, NULL, ",");
- end_hist = append_string(end_hist, NULL, name);
+ hist = append_string(hist, NULL, ",");
+ hist = append_string(hist, NULL, name);
}

- return append_string(end_hist, NULL, ")");
+ return append_string(hist, NULL, ")");
+}
+
+static char *create_end_hist(struct tracefs_synth *synth)
+{
+ char *end_hist;
+
+ end_hist = create_hist(synth->end_keys, synth->end_vars);
+ end_hist = create_onmatch(end_hist, synth);
+ return create_trace(end_hist, synth);
}

static char *append_filter(char *hist, char *filter, unsigned int parens)
--
2.30.2