Received: by 10.223.185.116 with SMTP id b49csp5500148wrg; Tue, 27 Feb 2018 14:37:54 -0800 (PST) X-Google-Smtp-Source: AH8x227kiUqscoxgSazVZkxTTwFk+1G//p6scFp2jJAU7ci5G8cSQBUXjn866/zjluBpw5Fh67v3 X-Received: by 10.101.97.139 with SMTP id c11mr12472859pgv.433.1519771074290; Tue, 27 Feb 2018 14:37:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519771074; cv=none; d=google.com; s=arc-20160816; b=yCL3jP9nD32l+LpXsYnAFfeA6C2lOnvBgR0HZVwwY/PKCQeQc5yF92F/y+ytFpgyqk WHj7XWwfztUN4g7biN848ZRBvO3C4t8CnM47NLgGHdrO1cDVYtvAzkzIF1+273TVrEjM +/10w3eIuXuJge1SMKXSm0crAmNnyXmmw93ixa3IGxGFec0fwXfTa0aw+XXSkFQbPmra 8/Y3xlhR+y7XOYdva14xRZUWrlYKi6MRpqBV4sRAr45VVGKgeufYohwaEFwP3wAK7LFs J90frGKu6loVWQoJklWgnbosz6E09S+pMfaIlVMVkKXrwmTzS0Qih89o67Du/ZyO5HT3 oVNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=3dYBMmc1BbM4cg7UAHFzk9Z94D1/MAyyJwIV7ymS5pY=; b=CDzOark74VZykHuFr8eWzirnUnR3qKtCdLfxlNAnOK9BLoPQEJNMbvw/lzA49Pvw9d bSw5yRH+AhRLGa35JOiv1BrOcW3b7Rv8z1McRdUIr8+WYzb9NXXvksk4OkFqdTHK41XD TcCdPGoJqOluVTg3MIvJRcnlfRTJbQh0itw7YXR2JZj8K9WvgCW9LNRsS344H8rE8TIR P+Vh3Cw8k1OYWgXFsJIXBvk8R6J5l2rFfSYzHPwOtvDJtgh+lNF67pmXgnHp5oNmaCmT HYqqLhkAK44577TmAB7Q5ptjOI8oC653W2WgDvWcs0iPypCaJZgg3Gk9IimpcobIPLue AALg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=AmPlNiem; dkim=pass header.i=@codeaurora.org header.s=default header.b=cIRM/opQ; 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 t6si107246pgc.749.2018.02.27.14.37.39; Tue, 27 Feb 2018 14:37:54 -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; dkim=pass header.i=@codeaurora.org header.s=default header.b=AmPlNiem; dkim=pass header.i=@codeaurora.org header.s=default header.b=cIRM/opQ; 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 S1752070AbeB0Wfp (ORCPT + 99 others); Tue, 27 Feb 2018 17:35:45 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:45452 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751641AbeB0WfP (ORCPT ); Tue, 27 Feb 2018 17:35:15 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 921E760FE9; Tue, 27 Feb 2018 22:35:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1519770914; bh=PvGwkA4n4lJZGZrzUokCofz1CmePbgPeNfdFmNUJ1oA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AmPlNiemDofaY4xvHQBxKu2cAjgbbfAgqDN52g8Ez/8HAwjHLV37ebTw2EE9NqQRM sYa19tZWf3DLmZ3u9EJK8Jir8BYYeF288Ri6vg89jS15KGhaYCdFf9m+WCULmkCXmd +wVgKaq27KpYv8Kz+2rXDmNn6TZ/Hh0P5t41pT+o= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from azshara.qualcomm.com (global_nat1_iad_fw.qualcomm.com [129.46.232.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: agustinv@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 54B7060849; Tue, 27 Feb 2018 22:35:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1519770913; bh=PvGwkA4n4lJZGZrzUokCofz1CmePbgPeNfdFmNUJ1oA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cIRM/opQ+XMiRAjOJZPJUHfZLQMWjsyG4JOtOVnLMJTod564os+raE5tJ853vSdKs /bC7zEl3X4zBEGyTQ1XFqKQP7sr8fQuGSZFef9ZUVl01C8+50rw+3K++UdZAcHvGFN 2NLj60Uib/hN5ucAPbpQgPXJKP74CMpJu0pZyxpY= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 54B7060849 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=agustinv@codeaurora.org From: Agustin Vega-Frias To: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Andi Kleen , Alexander Shishkin , Jiri Olsa , Namhyung Kim Cc: timur@codeaurora.org, agustinv@codeaurora.org Subject: [RFC 2/3] perf, tools: Display pmu name when printing unmerged events in stat Date: Tue, 27 Feb 2018 17:34:07 -0500 Message-Id: <1519770848-26738-3-git-send-email-agustinv@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1519770848-26738-1-git-send-email-agustinv@codeaurora.org> References: <1519770848-26738-1-git-send-email-agustinv@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Starting on v4.12 event parsing code for dynamic pmu events supports prefix-based matching of multiple pmus when creating dynamic events. E.g., in a system with the following dynamic pmus: l3cache_0_0 l3cache_0_1 l3cache_0_2 l3cache_0_3 passing l3cache// as an event spec will result in the creation of the event in all of the pmus. When this functionality is used in stat the command will by default merge the event counts and display a single value. E.g.: ./perf stat -a -e l3cache/read-miss/ ls > /dev/null Performance counter stats for 'system wide': 328 l3cache/read-miss/ 0.001661809 seconds time elapsed JSON-based alias events behave in the same way: $ ./perf stat -a -e l3cache_read_miss ls > /dev/null Performance counter stats for 'system wide': 229 l3cache_read_miss 0.001656099 seconds time elapsed This behavior can be disabled by the --no-merge option but the real pmu name is lost and it's not possible to see which count corresponds to which pmu: $ ./perf stat -a -e l3cache/read-miss/ --no-merge ls > /dev/null Performance counter stats for 'system wide': 67 l3cache/read-miss/ 67 l3cache/read-miss/ 63 l3cache/read-miss/ 60 l3cache/read-miss/ 0.001675706 seconds time elapsed This is also the case for alias events, e.g.: $ ./perf stat -a -e l3cache_read_miss --no-merge ls > /dev/null Performance counter stats for 'system wide': 12 l3cache_read_miss 17 l3cache_read_miss 10 l3cache_read_miss 8 l3cache_read_miss 0.001661305 seconds time elapsed This change adds the original pmu name to the event. For dynamic pmu events the pmu name is restored in the event name: $ ./perf stat -a -e l3cache/read-miss/ --no-merge ls > /dev/null Performance counter stats for 'system wide': 63 l3cache_0_3/read-miss/ 74 l3cache_0_1/read-miss/ 64 l3cache_0_2/read-miss/ 74 l3cache_0_0/read-miss/ 0.001675706 seconds time elapsed For alias events the name is added after the event name: $ ./perf stat -a -e l3cache_read_miss --no-merge ls > /dev/null Performance counter stats for 'system wide': 10 l3cache_read_miss [l3cache_0_3] 12 l3cache_read_miss [l3cache_0_1] 10 l3cache_read_miss [l3cache_0_2] 17 l3cache_read_miss [l3cache_0_0] 0.001661305 seconds time elapsed Signed-off-by: Agustin Vega-Frias --- tools/perf/builtin-stat.c | 29 ++++++++++++++++++++++++++++- tools/perf/util/evsel.c | 1 + tools/perf/util/evsel.h | 1 + tools/perf/util/parse-events.c | 8 +++++++- 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 98bf9d3..d196972 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1225,6 +1225,31 @@ static void aggr_update_shadow(void) } } +static void uniquify_event_name(struct perf_evsel *counter) +{ + char *new_name; + char *config; + + if (!counter->pmu_name || !strncmp(counter->name, counter->pmu_name, + strlen(counter->pmu_name))) + return; + + config = strchr(counter->name, '/'); + if (config) { + if (asprintf(&new_name, + "%s%s", counter->pmu_name, config) > 0) { + free(counter->name); + counter->name = new_name; + } + } else { + if (asprintf(&new_name, + "%s [%s]", counter->name, counter->pmu_name) > 0) { + free(counter->name); + counter->name = new_name; + } + } +} + static void collect_all_aliases(struct perf_evsel *counter, void (*cb)(struct perf_evsel *counter, void *data, bool first), @@ -1253,7 +1278,9 @@ static bool collect_data(struct perf_evsel *counter, if (counter->merged_stat) return false; cb(counter, data, true); - if (!no_merge && counter->auto_merge_stats) + if (no_merge) + uniquify_event_name(counter); + else if (counter->auto_merge_stats) collect_all_aliases(counter, cb, data); return true; } diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index ef35168..4841000 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -244,6 +244,7 @@ void perf_evsel__init(struct perf_evsel *evsel, evsel->metric_name = NULL; evsel->metric_events = NULL; evsel->collect_stat = false; + evsel->pmu_name = NULL; } struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx) diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index a7487c6..c2ac16a 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -142,6 +142,7 @@ struct perf_evsel { struct perf_evsel **metric_events; bool collect_stat; bool weak_group; + const char *pmu_name; }; union u64_swap { diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 34589c4..bafc91e 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1247,7 +1247,12 @@ static int __parse_events_add_pmu(struct parse_events_state *parse_state, if (!head_config) { attr.type = pmu->type; evsel = __add_event(list, &parse_state->idx, &attr, NULL, pmu, NULL, auto_merge_stats); - return evsel ? 0 : -ENOMEM; + if (evsel) { + evsel->pmu_name = name; + return 0; + } else { + return -ENOMEM; + } } if (perf_pmu__check_alias(pmu, head_config, &info)) @@ -1276,6 +1281,7 @@ static int __parse_events_add_pmu(struct parse_events_state *parse_state, evsel->snapshot = info.snapshot; evsel->metric_expr = info.metric_expr; evsel->metric_name = info.metric_name; + evsel->pmu_name = name; } return evsel ? 0 : -ENOMEM; -- 2.7.4