Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5457571imu; Sun, 20 Jan 2019 11:17:03 -0800 (PST) X-Google-Smtp-Source: ALg8bN5S82z4GjsToIHy7dtI+xYrW2DRQ9PnHYHjpEFFc4wNw4lt3eEVCoBYxJFpbrz6xNyOh/am X-Received: by 2002:a62:2781:: with SMTP id n123mr27554628pfn.138.1548011823390; Sun, 20 Jan 2019 11:17:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548011823; cv=none; d=google.com; s=arc-20160816; b=ytlwTquRdkMXAAujs0fd4JaLm1CykFLcYS9KZ8SM58U4vX2j/lBMs218plDpSUklFa p2/b4mVhUZcY6qviWm8cHMtIeU9bydcFMx+saaKSF9ASG/YIOqgKnctL0sDe++nwYAm8 Hq/f8V0oHzMN2ZZI+Ztp9Ym4r2MlEMzU7qLHCQPEiBDj6FAQjHGRetcz6gajCUbZGSXo gGm31KXijfLTM9xyzYrwNGR1o1NaimJjYkqqT3/HZqRkE6O85m0lTx9G0hIRuGmfPUBc UPopyxqgxWkvBh0s4oPCTlUjSgZguGgfKT4ehY/SS76t30lO1EOdmiio51xnWsX8gPlL FsxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=va08ovMO3+wmkpfGLzQSYn4KqN/2xE43bPxum1PT+Ks=; b=X1osr54hJNtVV469TUi/X9SFk0saLHfe1hpxn4ACaaw9iA8JSXFeObtvzTT+DQ+fn1 SEKuSH3qkQ04fp7H+iDc2nWB5ntvG2uHYF8e8lY36ANx/xVt5XpaMzX1OSSfPaYw1VDP HROP+mBIzRP840fSE67xti7Pi64EZkeZLITItZi5NETi04aI2W+pETdYY8hJwMeaGM7+ QZ6e7G47c/lBarcwonmJRXtDt3sLJxTejgyo8ZNe/PtSZcD4s26pcWdSO16MQ8JK/LhA ZTbXjF7e+fRVk/ALStQ3PXA/XBzdd9ANQrwhFl2OBqBoGE+eFQVKhIPC2Iruxmq72RdX 1olA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h3si9776283pll.116.2019.01.20.11.16.48; Sun, 20 Jan 2019 11:17:03 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727806AbfATTOf (ORCPT + 99 others); Sun, 20 Jan 2019 14:14:35 -0500 Received: from mx2.suse.de ([195.135.220.15]:42338 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727415AbfATTOf (ORCPT ); Sun, 20 Jan 2019 14:14:35 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 0472EAB42; Sun, 20 Jan 2019 19:14:34 +0000 (UTC) From: Tony Jones To: linux-perf-users@vger.kernel.org Cc: Tony Jones , acme@kernel.org, Jin Yao , jolsa@redhat.com, ak@linux.intel.com, linux-kernel@vger.kernel.org Subject: [PATCH] perf script: fix crash when processing recorded stat data Date: Sun, 20 Jan 2019 11:14:14 -0800 Message-Id: <20190120191414.12925-1-tonyj@suse.de> X-Mailer: git-send-email 2.18.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; - } 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