* [PATCH] libtracefs: Allow for the same event to be start and end in tracefs_sql()
@ 2022-05-31 21:24 Steven Rostedt
2022-05-31 23:26 ` Harald Seiler
0 siblings, 1 reply; 2+ messages in thread
From: Steven Rostedt @ 2022-05-31 21:24 UTC (permalink / raw)
To: Linux Trace Devel; +Cc: hws
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
When creating a synthetic event that is based off of the same event with
two different fields, it should still work. But the assumption was that
every field that has a label will have the same label, which is not
true.
For example, to create an event that measures the time a task is
blocked, it needs to start and end on the same event (sched_switch), but
just use different fields.
sqlhist -n blocked 'SELECT end.next_pid AS pid,end.next_comm AS comm,(end.TIMESTAMP_USECS - start.TIMESTAMP_USECS) AS lat
FROM sched_switch AS start JOIN sched_switch AS end ON start.prev_pid = end.next_pid WHERE start.prev_state = 2'
But this gave the following error:
Failed creating synthetic event!: Success
SELECT end.next_pid AS pid,end.next_comm AS comm,(end.TIMESTAMP_USECS - start.TIMESTAMP_USECS) AS lat FROM sched_switch AS start JOIN sched_switch AS end ON start.prev_pid = end.next_pid WHERE start.prev_state = 2
^
ERROR: 'end.next_pid'
'start.prev_pid' and 'end.next_pid' must be a field for each event: 'sched_switch' and 'sched_switch'
Because the end sched_switch would already have the label "start" and it
would not create one for "end" making the "end" not resolve correctly.
Now it gives the correct answer:
echo 's:blocked pid_t next_pid; char next_comm[16]; u64 lat;' >> /sys/kernel/tracing/dynamic_events
echo 'hist:keys=prev_pid:__arg_21065_1=next_pid,__arg_21065_2=next_comm,__arg_21065_3=common_timestamp.usecs if prev_state == 2' >> /sys/kernel/tracing/events/sched/sched_switch/trigger
echo 'hist:keys=next_pid:next_pid=$__arg_21065_1,next_comm=$__arg_21065_2,lat=common_timestamp.usecs-$__arg_21065_3:onmatch(sched.sched_switch).trace(blocked,$next_pid,$next_comm,$lat)' >> /sys/kernel/tracing/events/sched/sched_switch/trigger
Fixes: 25446407 ("libtracefs: Added new API tracefs_sql()")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
src/tracefs-sqlhist.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/tracefs-sqlhist.c b/src/tracefs-sqlhist.c
index 9811362..cee037b 100644
--- a/src/tracefs-sqlhist.c
+++ b/src/tracefs-sqlhist.c
@@ -285,6 +285,8 @@ static struct expr *find_field(struct sqlhist_bison *sb,
if (!strcmp(field->raw, raw)) {
if (label && !field->label)
field->label = label;
+ if (label && strcmp(label, field->label) != 0)
+ continue;
return expr;
}
--
2.35.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] libtracefs: Allow for the same event to be start and end in tracefs_sql()
2022-05-31 21:24 [PATCH] libtracefs: Allow for the same event to be start and end in tracefs_sql() Steven Rostedt
@ 2022-05-31 23:26 ` Harald Seiler
0 siblings, 0 replies; 2+ messages in thread
From: Harald Seiler @ 2022-05-31 23:26 UTC (permalink / raw)
To: Steven Rostedt, Linux Trace Devel
On Tue, 2022-05-31 at 17:24 -0400, Steven Rostedt wrote:
> From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
>
> When creating a synthetic event that is based off of the same event with
> two different fields, it should still work. But the assumption was that
> every field that has a label will have the same label, which is not
> true.
>
> For example, to create an event that measures the time a task is
> blocked, it needs to start and end on the same event (sched_switch), but
> just use different fields.
>
> sqlhist -n blocked 'SELECT end.next_pid AS pid,end.next_comm AS comm,(end.TIMESTAMP_USECS - start.TIMESTAMP_USECS) AS lat
> FROM sched_switch AS start JOIN sched_switch AS end ON start.prev_pid = end.next_pid WHERE start.prev_state = 2'
>
> But this gave the following error:
>
> Failed creating synthetic event!: Success
> SELECT end.next_pid AS pid,end.next_comm AS comm,(end.TIMESTAMP_USECS - start.TIMESTAMP_USECS) AS lat FROM sched_switch AS start JOIN sched_switch AS end ON start.prev_pid = end.next_pid WHERE
> start.prev_state = 2
> ^
> ERROR: 'end.next_pid'
> 'start.prev_pid' and 'end.next_pid' must be a field for each event: 'sched_switch' and 'sched_switch'
>
> Because the end sched_switch would already have the label "start" and it
> would not create one for "end" making the "end" not resolve correctly.
>
> Now it gives the correct answer:
>
> echo 's:blocked pid_t next_pid; char next_comm[16]; u64 lat;' >> /sys/kernel/tracing/dynamic_events
> echo 'hist:keys=prev_pid:__arg_21065_1=next_pid,__arg_21065_2=next_comm,__arg_21065_3=common_timestamp.usecs if prev_state == 2' >> /sys/kernel/tracing/events/sched/sched_switch/trigger
> echo 'hist:keys=next_pid:next_pid=$__arg_21065_1,next_comm=$__arg_21065_2,lat=common_timestamp.usecs-$__arg_21065_3:onmatch(sched.sched_switch).trace(blocked,$next_pid,$next_comm,$lat)' >>
> /sys/kernel/tracing/events/sched/sched_switch/trigger
>
> Fixes: 25446407 ("libtracefs: Added new API tracefs_sql()")
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Tested-by: Harald Seiler <hws@denx.de>
Just gave it a spin, this is great!
> ---
> src/tracefs-sqlhist.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/src/tracefs-sqlhist.c b/src/tracefs-sqlhist.c
> index 9811362..cee037b 100644
> --- a/src/tracefs-sqlhist.c
> +++ b/src/tracefs-sqlhist.c
> @@ -285,6 +285,8 @@ static struct expr *find_field(struct sqlhist_bison *sb,
> if (!strcmp(field->raw, raw)) {
> if (label && !field->label)
> field->label = label;
> + if (label && strcmp(label, field->label) != 0)
> + continue;
> return expr;
> }
>
--
Harald
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-05-31 23:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-31 21:24 [PATCH] libtracefs: Allow for the same event to be start and end in tracefs_sql() Steven Rostedt
2022-05-31 23:26 ` Harald Seiler
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.