Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1369312 > unrolled thread
| Started by | Wang Nan <wangnan0@huawei.com> |
|---|---|
| First post | 2016-04-01 15:30 +0200 |
| Last post | 2016-04-01 17:30 +0200 |
| Articles | 3 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH] perf tools: Add sample types for bpf-output event Wang Nan <wangnan0@huawei.com> - 2016-04-01 15:30 +0200
Re: [PATCH] perf tools: Add sample types for bpf-output event Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-01 17:20 +0200
Re: [PATCH] perf tools: Add sample types for bpf-output event Arnaldo Carvalho de Melo <acme@redhat.com> - 2016-04-01 17:30 +0200
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-04-01 15:30 +0200 |
| Subject | [PATCH] perf tools: Add sample types for bpf-output event |
| Message-ID | <rj7jb-4UU-1@gated-at.bofh.it> |
Before this patch we can see very large time in the events before
bpf-output event. For example:
# ./perf trace -vv -T --ev sched:sched_switch \
--ev bpf-output/no-inherit,name=evt/ \
--ev ./test_bpf_trace.c/map:channel.event=evt/ \
usleep 10
...
18446744073709.551 (18446564645918.480 ms): usleep/4157 nanosleep(rqtp: 0x7ffd3f0dc4e0 ) ...
18446744073709.551 ( ): evt:Raise a BPF event!..)
179427791.076 ( ): perf_bpf_probe:func_begin:(ffffffff810eb9a0))
179427791.081 ( ): sched:sched_switch:usleep:4157 [120] S ==> swapper/2:0 [120])
...
We can also see the differences between bpf-output events and
breakpoint events:
For bpf output event:
sample_type IP|TID|RAW|IDENTIFIER
For tracepoint events:
sample_type IP|TID|TIME|CPU|PERIOD|RAW|IDENTIFIER
This patch fix this differences by adding more sample type for
bpf-output events.
After this patch:
# ./perf trace -vv -T --ev sched:sched_switch \
--ev bpf-output/no-inherit,name=evt/ \
--ev ./test_bpf_trace.c/map:channel.event=evt/ \
usleep 10
...
179877370.878 ( 0.003 ms): usleep/5336 nanosleep(rqtp: 0x7ffff866c450 ) ...
179877370.878 ( ): evt:Raise a BPF event!..)
179877370.878 ( ): perf_bpf_probe:func_begin:(ffffffff810eb9a0))
179877370.882 ( ): sched:sched_switch:usleep:5336 [120] S ==> swapper/4:0 [120])
179877370.945 ( ): evt:Raise a BPF event!..)
...
# ./perf trace -vv -T --ev sched:sched_switch \
--ev bpf-output/no-inherit,name=evt/ \
--ev ./test_bpf_trace.c/map:channel.event=evt/ \
usleep 10 2>&1 | grep sample_type
sample_type IP|TID|TIME|ID|CPU|PERIOD|RAW
sample_type IP|TID|TIME|ID|CPU|PERIOD|RAW
sample_type IP|TID|TIME|ID|CPU|PERIOD|RAW
sample_type IP|TID|TIME|ID|CPU|PERIOD|RAW
sample_type IP|TID|TIME|ID|CPU|PERIOD|RAW
sample_type IP|TID|TIME|ID|CPU|PERIOD|RAW
The 'IDENTIFIER' is not required because all events have the
same sample_type.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Milian Wolff <milian.wolff@kdab.com>
Cc: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/evsel.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 738ce22..3fd7c2c 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -226,7 +226,8 @@ struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx)
perf_evsel__init(evsel, attr, idx);
if (perf_evsel__is_bpf_output(evsel)) {
- evsel->attr.sample_type |= PERF_SAMPLE_RAW;
+ evsel->attr.sample_type |= (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME |
+ PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD),
evsel->attr.sample_period = 1;
}
--
1.8.3.4
[toc] | [next] | [standalone]
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Date | 2016-04-01 17:20 +0200 |
| Message-ID | <rj91E-6gd-7@gated-at.bofh.it> |
| In reply to | #1369312 |
Em Fri, Apr 01, 2016 at 01:26:42PM +0000, Wang Nan escreveu:
> Before this patch we can see very large time in the events before
> bpf-output event. For example:
>
> # perf trace --ev bpf-output/no-inherit,name=evt/ \
> --ev ./test_bpf_trace.c/map:channel.event=evt/ \
> usleep 10
Thanks, applied and tested, now one idea that occurred to me to shorten
the above command line: automagically create a
"__perf_trace_bpf_stdout__" bpf-output event when a .c bpf event is
specified and no bpf-output is present, i.e. the following command line
would produce the same result as the one above:
# trace --ev test_bpf_trace.c usleep 10
Well, it would have to build test_bpf_trace.c and see if it references
the equivalent of a "stdout", i.e. it expects a bpf-output event to be
present to send output to.
I.e. in this example we have a:
struct bpf_map_def SEC("maps") channel = {
That later on you use to do "puts(msg)" like operations, i.e. to a
"stdout" of sorts:
func(void *ctx, int type)
{
char output_str[] = "Raise a BPF event!";
char err_str[] = "BAD %d\n";
int err;
err = perf_event_output(ctx, &channel, get_smp_processor_id(),
&output_str, sizeof(output_str));
if (err)
trace_printk(err_str, sizeof(err_str), err);
return 1;
}
Perhaps, to make all more familiar we could even define equivalents to
stdio.h functions like puts, printf, fputs, etc, that would send to this
bpf-output based "stdout" "channel", then the above would end up being:
func(void *ctx, int type)
{
char err_str[] = "BAD %d\n";
int err;
err = puts("Raise a BPF event!");
if (err)
trace_printk(err_str, sizeof(err_str), err);
return 1;
}
This trace_printk() in turn could become error() (glibc's error.h header), i.e.
the error mechanism would use the equivalent to userland's "syslog", i.e.
trace_printk :-)
In general trying to make BPF C scriptlets fed via perf to be as compact as
possible, hiding all these details while allowing them to be used, if desired.
- Arnaldo
[toc] | [prev] | [next] | [standalone]
| From | Arnaldo Carvalho de Melo <acme@redhat.com> |
|---|---|
| Date | 2016-04-01 17:30 +0200 |
| Message-ID | <rj9bk-6jH-27@gated-at.bofh.it> |
| In reply to | #1369410 |
Em Fri, Apr 01, 2016 at 12:16:10PM -0300, Arnaldo Carvalho de Melo escreveu:
> Perhaps, to make all more familiar we could even define equivalents to
> stdio.h functions like puts, printf, fputs, etc, that would send to this
> bpf-output based "stdout" "channel", then the above would end up being:
>
> func(void *ctx, int type)
> {
> char err_str[] = "BAD %d\n";
> int err;
>
> err = puts("Raise a BPF event!");
> if (err)
> trace_printk(err_str, sizeof(err_str), err);
> return 1;
> }
>
> This trace_printk() in turn could become error() (glibc's error.h header), i.e.
> the error mechanism would use the equivalent to userland's "syslog", i.e.
> trace_printk :-)
>
> In general trying to make BPF C scriptlets fed via perf to be as compact as
> possible, hiding all these details while allowing them to be used, if desired.
One extra possibility would be that it would look so much like a user
space C program that we could test it without loading it to the kernel,
with just building it with a different header and feeding it data as it
would get inside the kernel :-)
- Arnaldo
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web