From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751866AbdINU5j (ORCPT ); Thu, 14 Sep 2017 16:57:39 -0400 Received: from mga03.intel.com ([134.134.136.65]:7041 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751557AbdINU5i (ORCPT ); Thu, 14 Sep 2017 16:57:38 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,394,1500966000"; d="scan'208";a="1218957150" From: Andi Kleen To: acme@kernel.org Cc: jolsa@kernel.org, linux-kernel@vger.kernel.org, Andi Kleen Subject: [PATCH] perf, tools: Fix adding multiple event groups Date: Thu, 14 Sep 2017 13:57:35 -0700 Message-Id: <20170914205735.18431-1-andi@firstfloor.org> X-Mailer: git-send-email 2.9.5 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andi Kleen The -M metric group parser threw away the events of earlier groups when multiple groups were specified. Fix this here by not overwriting the string incorrectly. Now this works correctly: % perf stat -M Summary,SMT --metric-only -a sleep 1 Performance counter stats for 'system wide': Instructions CPI CLKS CPU_Utilization GFLOPs SMT_2T_Utilization SMT_2T_Utilization Kernel_Utilization CoreIPC CORE_CLKS 900907376.0 2.7 2398954144.0 0.1 0.0 0.2 0.2 0.1 0.4 2080822855.5 while previously it would only show the SMT metrics. Signed-off-by: Andi Kleen --- tools/perf/util/metricgroup.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 0794f02cbb8f..ce18474adc12 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -373,9 +373,6 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events, int ret = -EINVAL; int i, j; - strbuf_init(events, 100); - strbuf_addf(events, "%s", ""); - if (!map) return 0; @@ -433,6 +430,10 @@ static int metricgroup__add_metric_list(const char *list, struct strbuf *events, if (!nlist) return -ENOMEM; llist = nlist; + + strbuf_init(events, 100); + strbuf_addf(events, "%s", ""); + while ((p = strsep(&llist, ",")) != NULL) { ret = metricgroup__add_metric(p, events, group_list); if (ret == -EINVAL) { -- 2.9.5