Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp672026ybj; Thu, 7 May 2020 05:05:10 -0700 (PDT) X-Google-Smtp-Source: APiQypI+e87E0lxirQWnu9a42FGRVgZZR4SmjMOIxjI9OsUcwyBO7S9G5zT3sC+nEvVZePE5z5Uj X-Received: by 2002:a17:906:459:: with SMTP id e25mr11869974eja.379.1588853110231; Thu, 07 May 2020 05:05:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588853110; cv=none; d=google.com; s=arc-20160816; b=0HjfcxaggbudC5kaZ8y0nqCpXVO2PraUlVyaW7UeNSsxZ4sb0t8Y26axmZ/46IOuft mwlIT6G2t1z3DVcRXpwK/W/74q8zsaNHuHr8gdT8PXySZiYhPM3fyia7fEJYprpdIydQ DBCNc3KvmM4kBEWHF2tO2ATle7YxL+mEh5/jXG0ZoC6OYRQMU6ULb2Xx8LRljbpCTWoH j0iroqx6C50FFAowmeFdzSlBvqbV9KiyRSbKQPXKVIiPRYOeYetgCmv6ay2RDHn9wnYt yCp/XRoloOjX2XrTuOblQlzjc5tGmJqI6AhENHHSTxSjIExbfXKf6TINlGNP5D3a1QvS 46Yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=jdDbpRqZ56sDpXxz8Bs57Cvs+zqNra4ugD4xWMMDsKE=; b=y91zr0wFeeE0EVhn9uWf50Fqt5lVJ4WkjnKhPoNYaLnL/mGfVupgCf17z8wGa4lO3F K/Rh821GQQw/h1AsK94QnCKDG4dZuL7Lg3/H4Qqu/EqFX34Mq9oPkKRhzU6wdRdXyYWY OUIZBWmUHboITp/ZLMjHOWIMtJ9xTy6BcbtxNH5cSO6QwKOtq6zgJkFvTJrtRkmrm2KV ct7QHpZfQpnQ9G6WtxOY6O0Qvudyh7mxw7sQ9KxHin8UpOZ7WjzCQ74cLAZBlQKBS6tC aWSAS+qI2DKgtbQ9RayjroPmvErtg92WekC/nCof9ONl6cxr25F1X0PCkUwgEAmK7pFt yk+A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x21si3088412ejw.432.2020.05.07.05.04.43; Thu, 07 May 2020 05:05:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727108AbgEGMCT (ORCPT + 99 others); Thu, 7 May 2020 08:02:19 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:42310 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726942AbgEGMCO (ORCPT ); Thu, 7 May 2020 08:02:14 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id AA14637066ECD14BF777; Thu, 7 May 2020 20:02:09 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Thu, 7 May 2020 20:01:59 +0800 From: John Garry To: , , , , , , CC: , , , , , , , , , John Garry Subject: [PATCH RFC v3 11/12] perf metricgroup: Support printing metric groups for system PMUs Date: Thu, 7 May 2020 19:57:50 +0800 Message-ID: <1588852671-61996-12-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1588852671-61996-1-git-send-email-john.garry@huawei.com> References: <1588852671-61996-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently only metricgroups for core- or uncore-based events is supported. Extend this for system events. Signed-off-by: John Garry --- tools/perf/util/metricgroup.c | 66 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 31e97e24c2b0..ecf14aa01a59 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -377,6 +377,51 @@ static void metricgroup__print_pmu_event(struct pmu_event *pe, } } +struct metricgroup_print_sys_idata { + struct strlist *metriclist; + bool metricgroups; + char *filter; + bool raw; + bool details; + struct rblist *groups; +}; + +typedef int (*metricgroup_sys_event_iter_fn)(struct pmu_event *pe, void *); + +struct metricgroup_iter_data { + metricgroup_sys_event_iter_fn fn; + void *data; +}; + +static int metricgroup__sys_event_iter(struct pmu_event *pe, void *data) +{ + struct metricgroup_iter_data *d = data; + struct perf_pmu *pmu = NULL; + + if (!pe->metric_expr || !pe->compat) + return 0; + + while ((pmu = perf_pmu__scan(pmu)) != NULL) { + + if (!pmu->id || strcmp(pmu->id, pe->compat)) + continue; + + return d->fn(pe, d->data); + } + + return 0; +} + +static int metricgroup__print_sys_event_iter(struct pmu_event *pe, void *data) +{ + struct metricgroup_print_sys_idata *d = data; + + metricgroup__print_pmu_event(pe, d->metricgroups, d->filter, d->raw, + d->details, d->groups, d->metriclist); + + return 0; +} + void metricgroup__print(bool metrics, bool metricgroups, char *filter, bool raw, bool details) { @@ -387,9 +432,6 @@ void metricgroup__print(bool metrics, bool metricgroups, char *filter, struct rb_node *node, *next; struct strlist *metriclist = NULL; - if (!map) - return; - if (!metricgroups) { metriclist = strlist__new(NULL, NULL); if (!metriclist) @@ -400,7 +442,7 @@ void metricgroup__print(bool metrics, bool metricgroups, char *filter, groups.node_new = mep_new; groups.node_cmp = mep_cmp; groups.node_delete = mep_delete; - for (i = 0; ; i++) { + for (i = 0; map; i++) { pe = &map->table[i]; if (!pe->name && !pe->metric_group && !pe->metric_name) @@ -412,6 +454,22 @@ void metricgroup__print(bool metrics, bool metricgroups, char *filter, details, &groups, metriclist); } + { + struct metricgroup_iter_data data = { + .fn = metricgroup__print_sys_event_iter, + .data = (void *) &(struct metricgroup_print_sys_idata){ + .metriclist = metriclist, + .metricgroups = metricgroups, + .filter = filter, + .raw = raw, + .details = details, + .groups = &groups, + }, + }; + + pmu_for_each_sys_event(metricgroup__sys_event_iter, &data); + } + if (metricgroups && !raw) printf("\nMetric Groups:\n\n"); else if (metrics && !raw) -- 2.16.4