Received: by 10.223.185.111 with SMTP id b44csp55518wrg; Fri, 9 Mar 2018 00:45:53 -0800 (PST) X-Google-Smtp-Source: AG47ELu0J579VMph6Lxvce38PAs8tIuGUFGSUVfN9RaKHy1+5pzeytEIJTbPKya5Fq4bllp06Ivf X-Received: by 10.99.103.69 with SMTP id b66mr23455656pgc.233.1520585153762; Fri, 09 Mar 2018 00:45:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520585153; cv=none; d=google.com; s=arc-20160816; b=zPCGjUx4jcqQCVF5dNeypYAAxLz2QxxUjFxDqKv5T07rHFs9OMMvEsvzDpjapdLsrJ ylgXa/1m5/TWjJje8nv9V8F3Del1/18unx+ezl8+Czzf3loZPXSbAU+aSJbxhX+PJHfy peHJ9Tvp/JXSkk7xMa4OOIbmlOxBcwRS4gp2lV3d0tPvymtRLbBx4D9vWZUaFbuUbjOm UCBtRJrgJYddv71RSkWU2eXcFGe6mUx5JCvh9/7kWFzDJHrEduQjO9a4i0KAlX2c0mN8 dE+qL8ebwCQwJscDLtUQkxDuE0Wv4VHxB3i507kJnqvPHaHCg6ggJBVBz09el/3UUBub sATQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=Gst4K2YGwfFV+LV0vMmfQEuIJgwZ7SHuVGho4BkxnVU=; b=tZwJNyYd4ttjedJLXaIa0FQd6PQgC/U/79AvgWAkatg7LLOnbKHVd91PKAuYmwhuxw LXhxixVdLtbN1YXkAISH64ih1Zpx7RMIZVrrv6wQCZKcUFB3X20UVQFiLKRL5g/hA6GJ UJyKydJ2HMc16Q8PgUSB+j5ThQzl4cOB6B4O2Z+4ICZz0gcgI6uzgzi2Delf5lRyNj8X X8GYqSAdlSnAmLrkN29gEvzFtLIbpPWCFIFnkYdnrnVMKRmydnvk7YohEbyEL1U/+osi wnsWdjoAeo5HBehwCgorMNCpeewhkbyBB1xSNataMkvBjFbsiEXkddVCdnQ1u/4k3YFV fBgA== 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 g4si410137pgr.797.2018.03.09.00.45.39; Fri, 09 Mar 2018 00:45:53 -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 S1751322AbeCIIoO (ORCPT + 99 others); Fri, 9 Mar 2018 03:44:14 -0500 Received: from terminus.zytor.com ([198.137.202.136]:59629 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750898AbeCIIoM (ORCPT ); Fri, 9 Mar 2018 03:44:12 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w298gkhB024118; Fri, 9 Mar 2018 00:42:46 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w298gk1D024115; Fri, 9 Mar 2018 00:42:46 -0800 Date: Fri, 9 Mar 2018 00:42:46 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Agustin Vega-Frias Message-ID: Cc: timur@codeaurora.org, mingo@kernel.org, acme@redhat.com, peterz@infradead.org, alexander.shishkin@linux.intel.com, agustinv@codeaurora.org, hpa@zytor.com, ak@linux.intel.com, namhyung@kernel.org, tglx@linutronix.de, jolsa@kernel.org, linux-kernel@vger.kernel.org Reply-To: timur@codeaurora.org, peterz@infradead.org, alexander.shishkin@linux.intel.com, acme@redhat.com, mingo@kernel.org, jolsa@kernel.org, tglx@linutronix.de, namhyung@kernel.org, ak@linux.intel.com, hpa@zytor.com, agustinv@codeaurora.org, linux-kernel@vger.kernel.org In-Reply-To: <1520345084-42646-3-git-send-email-agustinv@codeaurora.org> References: <1520345084-42646-3-git-send-email-agustinv@codeaurora.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf pmu: Display pmu name when printing unmerged events in stat Git-Commit-ID: 8c5421c016a4ef7fd0141fe3a1ad221feba12f92 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 8c5421c016a4ef7fd0141fe3a1ad221feba12f92 Gitweb: https://git.kernel.org/tip/8c5421c016a4ef7fd0141fe3a1ad221feba12f92 Author: Agustin Vega-Frias AuthorDate: Tue, 6 Mar 2018 09:04:43 -0500 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 8 Mar 2018 10:05:49 -0300 perf pmu: Display pmu name when printing unmerged events in stat To simplify creation of events accross multiple instances of the same type of PMU stat supports two methods for creating multiple events from a single event specification: 1. A prefix or glob can be used in the PMU name. 2. Aliases, which are listed immediately after the Kernel PMU events by perf list, are used. When the --no-merge option is passed and these events are displayed individually the 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 $ 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 Acked-by: Andi Kleen Acked-by: Jiri Olsa Cc: Alexander Shishkin Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Timur Tabi Cc: linux-arm-kernel@lists.infradead.org Change-Id: I8056b9eda74bda33e95065056167ad96e97cb1fb Link: http://lkml.kernel.org/r/1520345084-42646-3-git-send-email-agustinv@codeaurora.org Signed-off-by: Arnaldo Carvalho de Melo --- 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 3a022b3e5c02..0fa9ea3a6d92 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1251,6 +1251,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), @@ -1279,7 +1304,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 f1f883bb41a8..e937894654b2 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 92ba001b627f..55ae1cda7396 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 34589c427e52..bafc91edcb44 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;