Re: [PATCH] perf tools: Add sample types for bpf-output event
From: Arnaldo Carvalho de Melo
Date: Fri Apr 01 2016 - 11:16:19 EST
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