From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759002AbcDAPQQ (ORCPT ); Fri, 1 Apr 2016 11:16:16 -0400 Received: from mail.kernel.org ([198.145.29.136]:38159 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751876AbcDAPQP (ORCPT ); Fri, 1 Apr 2016 11:16:15 -0400 Date: Fri, 1 Apr 2016 12:16:10 -0300 From: Arnaldo Carvalho de Melo To: Wang Nan Cc: linux-kernel@vger.kernel.org, pi3orama@163.com, Arnaldo Carvalho de Melo , Adrian Hunter , Ingo Molnar , David Ahern , Jiri Olsa , Milian Wolff , Namhyung Kim , Brendan Gregg Subject: Re: [PATCH] perf tools: Add sample types for bpf-output event Message-ID: <20160401151610.GG7115@kernel.org> References: <1459517202-42320-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1459517202-42320-1-git-send-email-wangnan0@huawei.com> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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