From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Tom Zanussi <zanussi@kernel.org>,
Daniel Bristot de Oliveira <bristot@redhat.com>,
Masami Hiramatsu <mhiramat@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
linux-rt-users <linux-rt-users@vger.kernel.org>,
Clark Williams <williams@redhat.com>,
"Steven Rostedt (VMware)" <rostedt@goodmis.org>
Subject: [PATCH 3/7] libtracefs: Add API tracefs_synth_trace()
Date: Thu, 12 Aug 2021 22:16:51 -0400 [thread overview]
Message-ID: <20210813021655.939819-4-rostedt@goodmis.org> (raw)
In-Reply-To: <20210813021655.939819-1-rostedt@goodmis.org>
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
Add the API tracefs_synth_trace() that adds a "trace" action that can be
attached to the onmax or the onchange handler. Note, this still can be
used for onmatch, but that's the default anyway.
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
Documentation/libtracefs-synth2.txt | 17 +++++-
include/tracefs.h | 2 +
src/tracefs-hist.c | 91 +++++++++++++++++++++++++++++
3 files changed, 109 insertions(+), 1 deletion(-)
diff --git a/Documentation/libtracefs-synth2.txt b/Documentation/libtracefs-synth2.txt
index 44693b394f29..a74e88ec0eda 100644
--- a/Documentation/libtracefs-synth2.txt
+++ b/Documentation/libtracefs-synth2.txt
@@ -3,7 +3,8 @@ libtracefs(3)
NAME
----
-tracefs_synth_create, tracefs_synth_destroy, tracefs_synth_show - Creation of synthetic events
+tracefs_synth_create, tracefs_synth_destroy, tracefs_synth_show,tracefs_synth_complete,
+tracefs_synth_get_start_hist,tracefs_synth_trace - Creation of synthetic events
SYNOPSIS
--------
@@ -20,6 +21,8 @@ int tracefs_synth_show(struct trace_seq pass:[*]seq, struct tracefs_instance pas
bool tracefs_synth_complete(struct tracefs_synth pass:[*]synth);
struct tracefs_hist pass:[*]tracefs_synth_get_start_hist(struct tracefs_synth pass:[*]synth);
+int tracefs_synth_trace(struct tracefs_synth pass:[*]synth,
+ enum tracefs_synth_handler type, const char pass:[*]var);
--
DESCRIPTION
@@ -60,6 +63,18 @@ a starting and ending event.
*tracefs_synth_get_start_hist*() returns a struct tracefs_hist descriptor describing
the histogram used to create the synthetic event.
+enum tracefs_synth_handler {
+ TRACEFS_SYNTH_HANDLE_MATCH,
+ TRACEFS_SYNTH_HANDLE_MAX,
+ TRACEFS_SYNTH_HANDLE_CHANGE,
+};
+
+*tracefs_synth_trace*() Instead of doing just a trace on matching of the start and
+end events, do the _type_ handler where *TRACEFS_SYNTH_HANDLE_MAX* will do a trace
+when the given variable _var_ hits a new max for the matching keys. Or
+*TRACEFS_SYNTH_HANDLE_CHANGE* for when the _var_ changes. _var_ must be one of
+the _name_ elements used in *tracefs_synth_add_end_field*(3).
+
RETURN VALUE
------------
Returns zero on success or -1 on error.
diff --git a/include/tracefs.h b/include/tracefs.h
index d83c4e33c69a..2faa564a860f 100644
--- a/include/tracefs.h
+++ b/include/tracefs.h
@@ -476,6 +476,8 @@ int tracefs_synth_append_end_filter(struct tracefs_synth *synth,
const char *field,
enum tracefs_compare compare,
const char *val);
+int tracefs_synth_trace(struct tracefs_synth *synth,
+ enum tracefs_synth_handler type, const char *field);
bool tracefs_synth_complete(struct tracefs_synth *synth);
struct tracefs_hist *tracefs_synth_get_start_hist(struct tracefs_synth *synth);
int tracefs_synth_create(struct tracefs_instance *instance,
diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c
index 262db7fbb925..562ec65088a9 100644
--- a/src/tracefs-hist.c
+++ b/src/tracefs-hist.c
@@ -1323,6 +1323,97 @@ int tracefs_synth_append_end_filter(struct tracefs_synth *synth,
type, field, compare, val);
}
+static int test_max_var(struct tracefs_synth *synth, const char *var)
+{
+ char **vars = synth->end_vars;
+ char *p;
+ int len;
+ int i;
+
+ len = strlen(var);
+
+ /* Make sure the var is defined for the end event */
+ for (i = 0; vars[i]; i++) {
+ p = strchr(vars[i], '=');
+ if (!p)
+ continue;
+ if (p - vars[i] != len)
+ continue;
+ if (!strncmp(var, vars[i], len))
+ return 0;
+ }
+ errno = ENODEV;
+ return -1;
+}
+
+static struct action *create_action(enum tracefs_synth_handler type,
+ struct tracefs_synth *synth,
+ const char *var)
+{
+ struct action *action;
+ int ret;
+
+ switch (type) {
+ case TRACEFS_SYNTH_HANDLE_MAX:
+ case TRACEFS_SYNTH_HANDLE_CHANGE:
+ ret = test_max_var(synth, var);
+ if (ret < 0)
+ return NULL;
+ break;
+ default:
+ break;
+ }
+
+ action = calloc(1, sizeof(*action));
+ if (!action)
+ return NULL;
+
+ if (var) {
+ ret = asprintf(&action->handle_field, "$%s", var);
+ if (!action->handle_field) {
+ free(action);
+ return NULL;
+ }
+ }
+ return action;
+}
+
+static void add_action(struct tracefs_synth *synth, struct action *action)
+{
+ *synth->next_action = action;
+ synth->next_action = &action->next;
+}
+
+/**
+ * tracefs_synth_trace - Execute the trace option
+ * @synth: The tracefs_synth descriptor
+ * @type: The type of handler to attach the trace action with
+ * @field: The field for handlers onmax and onchange (ignored otherwise)
+ *
+ * Add the action 'trace' for handlers onmatch, onmax and onchange.
+ *
+ * Returns 0 on succes, -1 on error.
+ */
+int tracefs_synth_trace(struct tracefs_synth *synth,
+ enum tracefs_synth_handler type, const char *field)
+{
+ struct action *action;
+
+ if (!synth || (!field && (type != TRACEFS_SYNTH_HANDLE_MATCH))) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ action = create_action(type, synth, field);
+ if (!action)
+ return -1;
+
+ action->type = ACTION_TRACE;
+ action->handler = type;
+ add_action(synth, action);
+ return 0;
+}
+
static char *create_synthetic_event(struct tracefs_synth *synth)
{
char *synthetic_event;
--
2.30.2
next prev parent reply other threads:[~2021-08-13 2:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-13 2:16 [PATCH 0/7] libtracefs: Add handlers 'onmax' and 'onchange' and actions 'snapshot' and 'save' Steven Rostedt
2021-08-13 2:16 ` [PATCH 1/7] libtracefs: Move creating of onmatch handler and trace action into helper functions Steven Rostedt
2021-08-13 2:16 ` [PATCH 2/7] libtracefs: Add logic to apply actions to synthetic events Steven Rostedt
2021-08-13 2:16 ` Steven Rostedt [this message]
2021-08-13 2:16 ` [PATCH 4/7] libtracefs: Add API tracefs_synth_snapshot() Steven Rostedt
2021-08-13 2:16 ` [PATCH 5/7] libtracefs: Add API tracefs_synth_save() Steven Rostedt
2021-08-13 2:16 ` [PATCH 6/7] libtracefs: Update the libtracefs-sql man page for the new tracefs_synth APIs Steven Rostedt
2021-08-13 2:16 ` [PATCH 7/7] libtracefs: Make a man page for the sqlhist man page example Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210813021655.939819-4-rostedt@goodmis.org \
--to=rostedt@goodmis.org \
--cc=bristot@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=linux-trace-devel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=namhyung@kernel.org \
--cc=williams@redhat.com \
--cc=zanussi@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).