linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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>,
	"Steven Rostedt (VMware)" <rostedt@goodmis.org>
Subject: [PATCH v2 2/2] libtracefs: Have end event variables not be the end event field name
Date: Thu, 12 Aug 2021 11:50:29 -0400	[thread overview]
Message-ID: <20210812155029.929048-3-rostedt@goodmis.org> (raw)
In-Reply-To: <20210812155029.929048-1-rostedt@goodmis.org>

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Currently we have:

 # sqlhist -n wakeup 'select end.next_pid, (end.TIMESTAMP - start.TIMESTAMP) as lat
   from sched_waking as start join sched_switch as end on start.pid = end.next_pid'

produces:

 echo 'wakeup s32 next_pid; u64 lat;' > /sys/kernel/tracing/synthetic_events
 echo 'hist:keys=pid:__arg_18871_1=common_timestamp' > /sys/kernel/tracing/events/sched/sched_waking/trigger
 echo 'hist:keys=next_pid:next_pid=next_pid,lat=common_timestamp-$__arg_18871_1:onmatch(sched.sched_waking).trace(wakeup,$next_pid,$lat)' > /sys/kernel/tracing/events/sched/sched_switch/trigger

The issue is that we have "next_pid=next_pid" where if we want to change
the above to use the "save" action:

 hist:keys=next_pid:next_pid=next_pid,lat=common_timestamp-$__arg_18871_1:onmax($lat).save(next_pid)

It fails with:

   hist:sched:sched_switch: error: Couldn't find field
    Command: hist:keys=next_pid:next_pid=next_pid,lat=common_timestamp-$__arg_18871_1:onmax($lat).save(next_pid)
                                                                       ^

But by having the end vars be unique, then the above "save" works.

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

diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c
index 9de70579a871..fefe251995ba 100644
--- a/src/tracefs-hist.c
+++ b/src/tracefs-hist.c
@@ -851,16 +851,19 @@ struct tracefs_synth *tracefs_synth_init(struct tep_handle *tep,
 
 static int add_synth_fields(struct tracefs_synth *synth,
 			    const struct tep_format_field *field,
-			    const char *name)
+			    const char *name, const char *var)
 {
 	char **list;
 	char *str;
 	int ret;
 
-	str = add_synth_field(field, name);
+	str = add_synth_field(field, name ? : field->name);
 	if (!str)
 		return -1;
 
+	if (!name)
+		name = var;
+
 	list = tracefs_list_add(synth->synthetic_fields, str);
 	free(str);
 	if (!list)
@@ -942,7 +945,7 @@ int tracefs_synth_add_match_field(struct tracefs_synth *synth,
 	if (ret < 0)
 		goto pop_lists;
 
-	ret = add_synth_fields(synth, key_field, name);
+	ret = add_synth_fields(synth, key_field, name, NULL);
 	if (ret < 0)
 		goto pop_lists;
 
@@ -1071,7 +1074,7 @@ int tracefs_synth_add_compare_field(struct tracefs_synth *synth,
 	if (ret < 0)
 		goto out_free;
 
-	ret = add_synth_fields(synth, start_field, name);
+	ret = add_synth_fields(synth, start_field, name, NULL);
 	if (ret < 0)
 		goto out_free;
 
@@ -1116,7 +1119,7 @@ __hidden int synth_add_start_field(struct tracefs_synth *synth,
 	if (ret)
 		goto out_free;
 
-	ret = add_synth_fields(synth, field, name);
+	ret = add_synth_fields(synth, field, name, NULL);
 	if (ret)
 		goto out_free;
 
@@ -1188,6 +1191,7 @@ int tracefs_synth_add_end_field(struct tracefs_synth *synth,
 				const char *name)
 {
 	const struct tep_format_field *field;
+	char *tmp_var = NULL;
 	int ret;
 
 	if (!synth || !end_field) {
@@ -1196,17 +1200,17 @@ int tracefs_synth_add_end_field(struct tracefs_synth *synth,
 	}
 
 	if (!name)
-		name = end_field;
+		tmp_var = new_arg(synth);
 
 	if (!trace_verify_event_field(synth->end_event, end_field, &field))
 		return -1;
 
-	ret = add_var(&synth->end_vars, name, end_field, false);
+	ret = add_var(&synth->end_vars, name ? : tmp_var, end_field, false);
 	if (ret)
 		goto out;
 
-	ret = add_synth_fields(synth, field, name);
-
+	ret = add_synth_fields(synth, field, name, tmp_var);
+	free(tmp_var);
  out:
 	return ret;
 }
-- 
2.30.2


      parent reply	other threads:[~2021-08-12 15:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-12 15:50 [PATCH v2 0/2] libtracefs: Make hist variable names unique Steven Rostedt
2021-08-12 15:50 ` [PATCH v2 1/2] libtracefs: Add random number to keep synthetic variables unique Steven Rostedt
2021-08-12 15:50 ` Steven Rostedt [this message]

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=20210812155029.929048-3-rostedt@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=bristot@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --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).