From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932301AbcFCIi5 (ORCPT ); Fri, 3 Jun 2016 04:38:57 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:41610 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932176AbcFCIiz (ORCPT ); Fri, 3 Jun 2016 04:38:55 -0400 Subject: Re: [PATCH] perf script: Fix display inconsitency when call-graph config is used To: , , References: <1463374279-97209-1-git-send-email-hekuang@huawei.com> CC: He Kuang , , , From: "Wangnan (F)" Message-ID: <575141EC.5090806@huawei.com> Date: Fri, 3 Jun 2016 16:38:04 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 In-Reply-To: <1463374279-97209-1-git-send-email-hekuang@huawei.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.111.66.109] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090204.57514208.0073,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: bb34820fc6e4b858d0b6576c5c5e5c47 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Arnaldo and David, Could you please have a look at this patch? It solves a perf script problem when dealing with mixed call-graph and no-call-graph events. Thank you. On 2016/5/16 12:51, He Kuang wrote: > There's a display inconsistency when 'call-graph' config event appears > in different position. The problem can be reproduced like this: > > We record signal_deliver with call-graph and signal_generate without it. > > $ perf record -g -a -e signal:signal_deliver -e signal:signal_generate/call-graph=no/ > > [ perf record: Captured and wrote 0.017 MB perf.data (2 samples) ] > > $ perf script > > kworker/u2:1 13 [000] 6563.875949: signal:signal_generate: sig=2 errno=0 code=128 comm=perf pid=1313 grp=1 res=0 ff61cc __send_signal+0x3ec ([kernel.kallsyms]) > perf 1313 [000] 6563.877584: signal:signal_deliver: sig=2 errno=0 code=128 sa_handler=43115e sa_flags=14000000 > 7ffff314 get_signal+0x80007f0023a4 ([kernel.kallsyms]) > 7fffe358 do_signal+0x80007f002028 ([kernel.kallsyms]) > 7fffa5e8 exit_to_usermode_loop+0x80007f002053 ([kernel.kallsyms]) > ... > > Then we exchange the order of these two events in commandline, and keep > signal_generate without call-graph. > > $ perf record -g -a -e signal:signal_generate/call-graph=no/ -e signal:signal_deliver > > [ perf record: Captured and wrote 0.017 MB perf.data (2 samples) ] > > $ perf script > > kworker/u2:2 1314 [000] 6933.353060: signal:signal_generate: sig=2 errno=0 code=128 comm=perf pid=1321 grp=1 res=0 > perf 1321 [000] 6933.353872: signal:signal_deliver: sig=2 errno=0 code=128 sa_handler=43115e sa_flags=14000000 > > This time, the callchain of the event signal_deliver disappeared. The > problem is caused by that perf only checks for the first evsel in evlist > and decides if callchain should be printed. > > This patch travseres all evsels in evlist to see if any of them have > callchains, and shows the right result: > > $ perf script > > kworker/u2:2 1314 [000] 6933.353060: signal:signal_generate: sig=2 errno=0 code=128 comm=perf pid=1321 grp=1 res=0 ff61cc __send_signal+0x3ec ([kernel.kallsyms]) > perf 1321 [000] 6933.353872: signal:signal_deliver: sig=2 errno=0 code=128 sa_handler=43115e sa_flags=14000000 > 7ffff314 get_signal+0x80007f0023a4 ([kernel.kallsyms]) > 7fffe358 do_signal+0x80007f002028 ([kernel.kallsyms]) > 7fffa5e8 exit_to_usermode_loop+0x80007f002053 ([kernel.kallsyms]) > ... > > Signed-off-by: He Kuang > --- > tools/perf/builtin-script.c | 23 +++++++++++++---------- > 1 file changed, 13 insertions(+), 10 deletions(-) > > diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c > index efca816..7a18b92 100644 > --- a/tools/perf/builtin-script.c > +++ b/tools/perf/builtin-script.c > @@ -339,7 +339,7 @@ static void set_print_ip_opts(struct perf_event_attr *attr) > */ > static int perf_session__check_output_opt(struct perf_session *session) > { > - int j; > + unsigned int j; > struct perf_evsel *evsel; > > for (j = 0; j < PERF_TYPE_MAX; ++j) { > @@ -388,17 +388,20 @@ static int perf_session__check_output_opt(struct perf_session *session) > struct perf_event_attr *attr; > > j = PERF_TYPE_TRACEPOINT; > - evsel = perf_session__find_first_evtype(session, j); > - if (evsel == NULL) > - goto out; > > - attr = &evsel->attr; > + evlist__for_each(session->evlist, evsel) { > + if (evsel->attr.type != j) > + continue; > + > + attr = &evsel->attr; > > - if (attr->sample_type & PERF_SAMPLE_CALLCHAIN) { > - output[j].fields |= PERF_OUTPUT_IP; > - output[j].fields |= PERF_OUTPUT_SYM; > - output[j].fields |= PERF_OUTPUT_DSO; > - set_print_ip_opts(attr); > + if (attr->sample_type & PERF_SAMPLE_CALLCHAIN) { > + output[j].fields |= PERF_OUTPUT_IP; > + output[j].fields |= PERF_OUTPUT_SYM; > + output[j].fields |= PERF_OUTPUT_DSO; > + set_print_ip_opts(attr); > + goto out; > + } > } > } >