Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9934475ybi; Wed, 24 Jul 2019 12:36:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqwPIwufx0ibEc1WONsQTGxzVfM6PPXRIbq/IZDzDr27/0n4GhIiC9Ug4X0NDEikA4M6xQF0 X-Received: by 2002:a65:5687:: with SMTP id v7mr84421267pgs.263.1563996983857; Wed, 24 Jul 2019 12:36:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563996983; cv=none; d=google.com; s=arc-20160816; b=w1f/tW67g64uPzL17lzbpXYv8f/wXW/CGQPxZVf4hvuLbuN6Tgoi51pLe1pnyxkh+B CxQeE2ztpzwHA/3kj5JCAdOrlSkog4LFAB8m599l8rlHodeR3fAcRH33IZRwGiyy28DQ jrTTFPNMN9tveF2W7JSqFI7zVKZ8y77yZqsII8HTsiKqFgJT0P65JR/8ueNyfBpHPN5h /LEmB2/DkErr3AbyWPVv1/Sj7GtGCgddJI7n+UeCq/m7BTarli5fi3dMZuktDuCHCC3a A0UtqLkYwSQ8ResSv3GAdX9MKIXnNe9ljQUkdwr7kdC2ERxYv7gADlSItAIM/sc2dek2 GUvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5oMb1z/GGKV7dk6oXMmTACxidXfp6M4mw0Ltk2T4ZzI=; b=hnmtixRAYDPA7Ey0DIP/Sk3jXHJB8nfkVqQe/e4QLY3QJf9gBeR8YcWnSvTd2kAmo2 NgpsoTMdqqX2WSvuWnjnwpOyfbwm4Mubb5WVnGMbYc6K/sLCJDM9QgJpH13wi61c7Sxv ZK+jTwHRwUACcJmaPT7uybr3gq1XrdEAcNhhs6UV6qQjz26XVtQH8RLDZm7LMvcaAx2n 5f3548XXRtJ5xgNodXa5k5vzcDTLEy9e0lwaMyKZJU29izXyYaZbCfiC/WElRXOUYVJg mnG+094jylqoyXJ8L+WPkUWRPOc+019L4sDJoPRcVcXj5lmyQnwj2CZxcwhtip3FkzFU PW/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BIq6e7kV; 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 q7si41183646pjv.36.2019.07.24.12.36.09; Wed, 24 Jul 2019 12:36:23 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=BIq6e7kV; 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 S2388301AbfGXTfE (ORCPT + 99 others); Wed, 24 Jul 2019 15:35:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:58116 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389134AbfGXTfB (ORCPT ); Wed, 24 Jul 2019 15:35:01 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A0FA922BE8; Wed, 24 Jul 2019 19:34:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563996900; bh=9XV6RrFeBCprK+8tRB0d3BlXwDhOM4YtCH/KQXnD/j4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BIq6e7kVjYOnWEXTefsMWvoajDs1ZUHwIWD4ZilW4xGLunix9HpuFsnLa9DBqHG4M 373r6oWIZ6n2ASCHBc76FZ7QFu67OArg6s96LAn27zbu97kswi2TiRmavyLy5brSHP blHexX6stUiZ4K0/cQqIk1CGuO504ULccD8ZrjKI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andi Kleen , Jiri Olsa , Kan Liang , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.2 213/413] perf stat: Fix group lookup for metric group Date: Wed, 24 Jul 2019 21:18:24 +0200 Message-Id: <20190724191749.765374742@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 2f87f33f4226523df9c9cc28f9874ea02fcc3d3f ] The metric group code tries to find a group it added earlier in the evlist. Fix the lookup to handle groups with partially overlaps correctly. When a sub string match fails and we reset the match, we have to compare the first element again. I also renamed the find_evsel function to find_evsel_group to make its purpose clearer. With the earlier changes this fixes: Before: % perf stat -M UPI,IPC sleep 1 ... 1,032,922 uops_retired.retire_slots # 1.1 UPI 1,896,096 inst_retired.any 1,896,096 inst_retired.any 1,177,254 cpu_clk_unhalted.thread After: % perf stat -M UPI,IPC sleep 1 ... 1,013,193 uops_retired.retire_slots # 1.1 UPI 932,033 inst_retired.any 932,033 inst_retired.any # 0.9 IPC 1,091,245 cpu_clk_unhalted.thread Signed-off-by: Andi Kleen Acked-by: Jiri Olsa Cc: Kan Liang Fixes: b18f3e365019 ("perf stat: Support JSON metrics in perf stat") Link: http://lkml.kernel.org/r/20190624193711.35241-4-andi@firstfloor.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/metricgroup.c | 47 ++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 699e020737d9..fabdb6dde88e 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -85,26 +85,49 @@ struct egroup { const char *metric_expr; }; -static struct perf_evsel *find_evsel(struct perf_evlist *perf_evlist, - const char **ids, - int idnum, - struct perf_evsel **metric_events) +static bool record_evsel(int *ind, struct perf_evsel **start, + int idnum, + struct perf_evsel **metric_events, + struct perf_evsel *ev) +{ + metric_events[*ind] = ev; + if (*ind == 0) + *start = ev; + if (++*ind == idnum) { + metric_events[*ind] = NULL; + return true; + } + return false; +} + +static struct perf_evsel *find_evsel_group(struct perf_evlist *perf_evlist, + const char **ids, + int idnum, + struct perf_evsel **metric_events) { struct perf_evsel *ev, *start = NULL; int ind = 0; evlist__for_each_entry (perf_evlist, ev) { + if (ev->collect_stat) + continue; if (!strcmp(ev->name, ids[ind])) { - metric_events[ind] = ev; - if (ind == 0) - start = ev; - if (++ind == idnum) { - metric_events[ind] = NULL; + if (record_evsel(&ind, &start, idnum, + metric_events, ev)) return start; - } } else { + /* + * We saw some other event that is not + * in our list of events. Discard + * the whole match and start again. + */ ind = 0; start = NULL; + if (!strcmp(ev->name, ids[ind])) { + if (record_evsel(&ind, &start, idnum, + metric_events, ev)) + return start; + } } } /* @@ -134,8 +157,8 @@ static int metricgroup__setup_events(struct list_head *groups, ret = -ENOMEM; break; } - evsel = find_evsel(perf_evlist, eg->ids, eg->idnum, - metric_events); + evsel = find_evsel_group(perf_evlist, eg->ids, eg->idnum, + metric_events); if (!evsel) { pr_debug("Cannot resolve %s: %s\n", eg->metric_name, eg->metric_expr); -- 2.20.1