Received: by 10.223.185.116 with SMTP id b49csp3850875wrg; Tue, 6 Mar 2018 06:07:27 -0800 (PST) X-Google-Smtp-Source: AG47ELv5i5gKCeS3iTmIwN34i/JzquRRPvnWv9oxQjNsDvM7mYYo/kAZfU48BhW+hAldjPKmyIBD X-Received: by 2002:a17:902:424:: with SMTP id 33-v6mr17133669ple.433.1520345247387; Tue, 06 Mar 2018 06:07:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520345247; cv=none; d=google.com; s=arc-20160816; b=C8vUHiH26BVCIGagDk3aRGtxi/n4k9EeZpqjSoYr82l9qrOgD144RoGaQ1jPA7nyGB 2feVfY8KqFtNzGCgOcboYDVESrsC0ecTchavmUnyYQZbwGAaJ4557Pa9QZ3wMC108oi2 tbdttbW9u+8I17Pedxi4RWmv0DVRs5my2N1Trgf4H1EAgA8KDFLG7+la1DKDy624RmYu KO74joM23riMTr2wpZOmnpG4k0VgN+4Y1g5LDz85kxQYDfPhEyydOVcaNMVwMmydiuMB lhj5ingRIESIyrhC1NxWbDa6WTBO00MZb/6OvxfY+A7NS/eoEE66prSNPostG6JUAbag E2tg== 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=BcIMQT9bnAL7kdNKXi3VTs3bOLFfqYkXcIqeP8viPKg=; b=bsONVlPpsl6Si+hDELURifEfLxDxwYod9kT5dFCvIDyOs9i1RY/Q/kqbZqy5Wb9Yj+ TBMCulXjh+SlSOfaWotNOQigOo08u3ydUeMwVMqNYVAPE7hyMcloxSVnCd5AwjBGyFiK G+bX4j3IMQ7RAn5i9kDphPN+QJWz6cjxXYei0rP5TGBqgYx7fLPL7eDT0QT29iAxMerQ +Qm0gOgXYo8MENTPQwG6A1l6gKTuEXFtX0sNN6G4y/cfHcxDoxhaF6Iz1Pc6gVMJjbsr 3Jbrp3LM5hKnOjAgf7DqJhwPliZhE6Im/ZgbrveiVZ5ZNfaJZWInpHP3pXYQfYujrDTB DFFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=byPmhGIf; dkim=pass header.i=@codeaurora.org header.s=default header.b=cmXsqahc; 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 m8-v6si11477657plk.593.2018.03.06.06.07.13; Tue, 06 Mar 2018 06:07:27 -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=byPmhGIf; dkim=pass header.i=@codeaurora.org header.s=default header.b=cmXsqahc; 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 S932961AbeCFOFe (ORCPT + 99 others); Tue, 6 Mar 2018 09:05:34 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:52568 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932739AbeCFOFH (ORCPT ); Tue, 6 Mar 2018 09:05:07 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 0A37A607EF; Tue, 6 Mar 2018 14:05:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1520345107; bh=biZ5H7JkkexcHTvEWZB2yRnfSZaJGYw/3aLLUFV8Oao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=byPmhGIfuCt7IMR6Erb1WVj0OhqzM03v8CvJJRz80zGth0vsftyxlkzSK9vOQrwA5 8vvvwwL//0VTVPXeHJpEJcktM0Nz//APZMDKLHuf7+j4t/sgem/kEA6+psHc7bfYqE +lIMoDNb4lbTiReZZ3sKUfyXniqHGJIAoC6FXn6g= 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 ral-tools-sdp4.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 6CD80607EF; Tue, 6 Mar 2018 14:05:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1520345105; bh=biZ5H7JkkexcHTvEWZB2yRnfSZaJGYw/3aLLUFV8Oao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cmXsqahck18qVudP7KSry08JC7/xx4B6TtP+h1Z7NDGhwVQNvl2Bg1gcvWJt19PKK FrzJ43RniOWMggq1k3d5n5hkRxm14u6OK0u/p63+BPN1TT1T3wXL4iO6empvvBMWST tGmXqCBW3Xj0e1mdjAcVPyJfDIJq1tUcSSNgSDDw= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 6CD80607EF 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 V3 2/3] perf, tools: Display pmu name when printing unmerged events in stat Date: Tue, 6 Mar 2018 09:04:43 -0500 Message-Id: <1520345084-42646-3-git-send-email-agustinv@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520345084-42646-1-git-send-email-agustinv@codeaurora.org> References: <1520345084-42646-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 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 Change-Id: I8056b9eda74bda33e95065056167ad96e97cb1fb 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; -- Qualcomm Datacenter Technologies, Inc. on behalf of the Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.