Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5924114imu; Sun, 20 Jan 2019 23:32:28 -0800 (PST) X-Google-Smtp-Source: ALg8bN6gOJIXpqL7Y15JZL+Wkv1YqEmQOu/ZxF6JNnt/bLeU47oyANqZZD4GzRnW50zx0nyVdtQ3 X-Received: by 2002:a63:d104:: with SMTP id k4mr26581513pgg.227.1548055948002; Sun, 20 Jan 2019 23:32:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548055947; cv=none; d=google.com; s=arc-20160816; b=WgX2P8uf7wLS8f9kMFIfbiukZGJiHPP/zIZWojB5Ubh3UgzA+7efxPUhLTabnTDPNy 9eaXFpbNoroUzvMdF8FGJIlGtPkKEBhm/PgpD1ab0MDrWVY01wSLdAS6MRDBmsBH4vYG f9R30mWiqSPagnmKhgTpHNi4b6CGujI4T0AqEbxIlF3yas4dTEQv9zYc99hIDnGt2Moh StqY45iQDy/k9nTslKV5j1lkmrvipPiKA8MqaU0kzf40eM60sx5kiz7U12P7FwpjMNxT RIZPMNqKlWJ2Ai+060J8JXq50wWKraa0cFVgIEFG3wnu8lEHALvXd9JqIOoexVKVZIVS u6xQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=aQ7TOBrVsnYnQr//2s5iIuHdmDJ+tnB/yB9MOV62AZI=; b=AgEwYES/Ol4IOWAE2kjFgqLOMR197D7ifTU8gmdw8iPqFFETv7Fx/UMr8P6XKrsFfd GI6jX3MVKQLLGsHFe3hnKfJUNsZiRkNAqOXHL7MM5kI+m0FjAOm6udKNkACs+djMlx+g YQZb7iI4ZcBedtTy6FmeqbQKd/HCe/X8x14+PH0SQYMdlP7QeI6RVLy0r76WDUj/gefh +vXA0C5SDJJdDk5E+YjfgBzapH5UNrvZwpJqtKGDSkReeBtl5lCgEVsA4jQWwvosJNlU 4hnz9gWuHqtz6gbuddz5EtlgeGabw0gOepNs8771TLi7pYS7JocpQvueIfErzIwOm4rC +Mkw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u9si6108661plk.61.2019.01.20.23.32.12; Sun, 20 Jan 2019 23:32:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728150AbfAUHbD (ORCPT + 99 others); Mon, 21 Jan 2019 02:31:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33198 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726912AbfAUHbD (ORCPT ); Mon, 21 Jan 2019 02:31:03 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CE28585A07; Sun, 20 Jan 2019 22:01:24 +0000 (UTC) Received: from krava (ovpn-204-22.brq.redhat.com [10.40.204.22]) by smtp.corp.redhat.com (Postfix) with SMTP id 94BD81048124; Sun, 20 Jan 2019 22:01:22 +0000 (UTC) Date: Sun, 20 Jan 2019 23:01:21 +0100 From: Jiri Olsa To: Tony Jones Cc: linux-perf-users@vger.kernel.org, acme@kernel.org, Jin Yao , ak@linux.intel.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] perf script: fix crash when processing recorded stat data Message-ID: <20190120220121.GE8591@krava> References: <20190120191414.12925-1-tonyj@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190120191414.12925-1-tonyj@suse.de> User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sun, 20 Jan 2019 22:01:24 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jan 20, 2019 at 11:14:14AM -0800, Tony Jones wrote: > While updating Perf to work with Python3 and Python2 I noticed that the > stat-cpi script was dumping core. > > $ perf stat -e cycles,instructions record -o /tmp/perf.data /bin/false > > Performance counter stats for '/bin/false': > > 802,148 cycles > > 604,622 instructions 802,148 cycles > 604,622 instructions > > 0.001445842 seconds time elapsed > > $ perf script -i /tmp/perf.data -s scripts/python/stat-cpi.py > Segmentation fault (core dumped) > ... > ... > rblist=rblist@entry=0xb2a200 , > new_entry=new_entry@entry=0x7ffcb755c310) at util/rblist.c:33 > ctx=, type=, create=, > cpu=, evsel=) at util/stat-shadow.c:118 > ctx=, type=, st=) > at util/stat-shadow.c:196 > count=count@entry=727442, cpu=cpu@entry=0, st=0xb2a200 ) > at util/stat-shadow.c:239 > config=config@entry=0xafeb40 , > counter=counter@entry=0x133c6e0) at util/stat.c:372 > ... > ... > > The issue is that since 1fcd03946b52 perf_stat__update_shadow_stats now calls > update_runtime_stat passing rt_stat rather than calling update_stats but > perf_stat__init_shadow_stats has never been called to initialize rt_stat in > the script path processing recorded stat data. > > Since I can't see any reason why perf_stat__init_shadow_stats() is presently > initialized like it is in builtin-script.c::perf_sample__fprint_metric() > [4bd1bef8bba2f] I'm proposing it instead be initialized once in __cmd_script > > Fixes: 1fcd03946b52 ("perf stat: Update per-thread shadow stats") > Signed-off-by: Tony Jones > --- > tools/perf/builtin-script.c | 7 ++----- > 1 file changed, 2 insertions(+), 5 deletions(-) > > diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c > index d079f36d342d..9a6dd86e606f 100644 > --- a/tools/perf/builtin-script.c > +++ b/tools/perf/builtin-script.c > @@ -1681,13 +1681,8 @@ static void perf_sample__fprint_metric(struct perf_script *script, > .force_header = false, > }; > struct perf_evsel *ev2; > - static bool init; > u64 val; > > - if (!init) { > - perf_stat__init_shadow_stats(); > - init = true; > - } well, there's no need to use shadow stats until stat data is processed.. but it's actually just a static initialization, so there's no need for late init Reviewed-by: Jiri Olsa thanks, jirka > if (!evsel->stats) > perf_evlist__alloc_stats(script->session->evlist, false); > if (evsel_script(evsel->leader)->gnum++ == 0) > @@ -2359,6 +2354,8 @@ static int __cmd_script(struct perf_script *script) > > signal(SIGINT, sig_handler); > > + perf_stat__init_shadow_stats(); > + > /* override event processing functions */ > if (script->show_task_events) { > script->tool.comm = process_comm_event; > -- > 2.18.0 >