From nobody Sun Feb 8 10:50:07 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62F8BC04E69 for ; Thu, 10 Aug 2023 21:50:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231169AbjHJVuL (ORCPT ); Thu, 10 Aug 2023 17:50:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230525AbjHJVuI (ORCPT ); Thu, 10 Aug 2023 17:50:08 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1629273D for ; Thu, 10 Aug 2023 14:50:07 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d41fa6e7103so1355098276.0 for ; Thu, 10 Aug 2023 14:50:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691704207; x=1692309007; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=RLtP1qtlvTA2kCfp1Ts4w1guanUnakgxywtNcXiy9W8=; b=YC9fZNq/b9KbQfHldtBuTXro+KtUVPjH/3nUZF+AMHUn+gdmg7ibGC0S/cxkMnN9nP qmCz1wHZhq87HbDKl5IMrcHLEmv5quM96FvZHHiaQ6ixawb6zv74FwrTvS8OQxPyTyom 5zOx5UB3axV/7mxBB/ZYl3W3YUKXX8o7J9e60oF3nCUxEdV8thWIaUYU7CAnGqSZ53kF l4ylVkMKYG2+3SK3H4SBhi6ZHMeaN80dAeEybmjty7Zm3kziDuHXaRbX6VaZPF6gkxGH KZTchU0C9zi4M8bl+lpDaWRYXIoVJn11Ky87pxNMnAIpykRFsy9GspzHb6poLkKWkFIC WVYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691704207; x=1692309007; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RLtP1qtlvTA2kCfp1Ts4w1guanUnakgxywtNcXiy9W8=; b=ElHLsHKtLKWrEnxqCHk9jy65w2a5szp4Beeezjn0Qdi13+TVE1Tr+Yr1NTVU+w29on ouJxLHjTdzGQE0d48K3abPXJzkrleTeDTeOiPWdg4QYarNDne32k1wYrE64wLwPRiClH rtsqBupqXbpOSib6/8OPaamBi9ei6wZvDN5YUUSl8O29rag74Hw8LJLG96keKQbEUmby kK+cGlAUoAuAmS0D8Dvyh2+hVqsi+tfqSN95TqEQD31ghhRfTrY6613RjTIhHZi28+Rx +ksKOO4uiDW8RXeiLMaS8u3Dul4ASUsDRKFa17VtvVMhE+1kGcbCaQPltnK9FHOzI5SW UdiQ== X-Gm-Message-State: AOJu0Ywyb77nYzPk5gCzgilz0gErFTX0b4wfvw0Xby11kNUbrTBcPbvG nQNUskmcRGGQqroLHwA6/VJTsMbSfL5X X-Google-Smtp-Source: AGHT+IEYsDFnzflV/jH0oE2OFvevp2qXB5ijl9PvOCqXoN+rOZm6n23oBbrY1iL48zKDsq40EAAutNM2yHtb X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:797f:302e:992f:97f2]) (user=irogers job=sendgmr) by 2002:a25:32d6:0:b0:d62:5d0f:a6a6 with SMTP id y205-20020a2532d6000000b00d625d0fa6a6mr60084yby.1.1691704206914; Thu, 10 Aug 2023 14:50:06 -0700 (PDT) Date: Thu, 10 Aug 2023 14:49:50 -0700 In-Reply-To: <20230810214952.2934029-1-irogers@google.com> Message-Id: <20230810214952.2934029-2-irogers@google.com> Mime-Version: 1.0 References: <20230810214952.2934029-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog Subject: [PATCH v2 1/3] perf pmus: Sort pmus by name then suffix From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kan Liang , Ravi Bangoria , Kajol Jain , John Garry , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Sort PMUs by name. If two PMUs have the same name but differ by suffix, sort the suffixes numerically. For example, "breakpoint" comes before "cpu", "uncore_imc_free_running_0" comes before "uncore_imc_free_running_1". Signed-off-by: Ian Rogers --- tools/perf/util/pmus.c | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index c58ba9fb6a36..3581710667b0 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -1,8 +1,10 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include #include #include +#include #include #include #include @@ -33,6 +35,31 @@ static LIST_HEAD(other_pmus); static bool read_sysfs_core_pmus; static bool read_sysfs_all_pmus; =20 +static int pmu_name_len_no_suffix(const char *str, unsigned long *num) +{ + int orig_len, len; + + orig_len =3D len =3D strlen(str); + + /* Non-uncore PMUs have their full length, for example, i915. */ + if (strncmp(str, "uncore_", 7)) + return len; + + /* + * Count trailing digits and '_', if '_{num}' suffix isn't present use + * the full length. + */ + while (len > 0 && isdigit(str[len - 1])) + len--; + + if (len > 0 && len !=3D orig_len && str[len - 1] =3D=3D '_') { + if (num) + *num =3D strtoul(&str[len], NULL, 10); + return len - 1; + } + return orig_len; +} + void perf_pmus__destroy(void) { struct perf_pmu *pmu, *tmp; @@ -122,6 +149,25 @@ static struct perf_pmu *perf_pmu__find2(int dirfd, con= st char *name) return perf_pmu__lookup(core_pmu ? &core_pmus : &other_pmus, dirfd, name); } =20 +static int pmus_cmp(void *priv __maybe_unused, + const struct list_head *lhs, const struct list_head *rhs) +{ + unsigned long lhs_num, rhs_num; + struct perf_pmu *lhs_pmu =3D container_of(lhs, struct perf_pmu, list); + struct perf_pmu *rhs_pmu =3D container_of(rhs, struct perf_pmu, list); + const char *lhs_pmu_name =3D lhs_pmu->name ?: ""; + const char *rhs_pmu_name =3D rhs_pmu->name ?: ""; + int lhs_pmu_name_len =3D pmu_name_len_no_suffix(lhs_pmu_name, &lhs_num); + int rhs_pmu_name_len =3D pmu_name_len_no_suffix(rhs_pmu_name, &rhs_num); + int ret =3D strncmp(lhs_pmu_name, rhs_pmu_name, + lhs_pmu_name_len < rhs_pmu_name_len ? lhs_pmu_name_len : rhs_pmu_name_l= en); + + if (lhs_pmu_name_len !=3D rhs_pmu_name_len || ret !=3D 0 || lhs_pmu_name_= len =3D=3D 0) + return ret; + + return lhs_num < rhs_num ? -1 : (lhs_num > rhs_num ? 1 : 0); +} + /* Add all pmus in sysfs to pmu list: */ static void pmu_read_sysfs(bool core_only) { @@ -156,6 +202,8 @@ static void pmu_read_sysfs(bool core_only) if (!perf_pmu__create_placeholder_core_pmu(&core_pmus)) pr_err("Failure to set up any core PMUs\n"); } + list_sort(NULL, &core_pmus, pmus_cmp); + list_sort(NULL, &other_pmus, pmus_cmp); if (!list_empty(&core_pmus)) { read_sysfs_core_pmus =3D true; if (!core_only) --=20 2.41.0.640.ga95def55d0-goog From nobody Sun Feb 8 10:50:07 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92D6FC04A6A for ; Thu, 10 Aug 2023 21:50:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229525AbjHJVuO (ORCPT ); Thu, 10 Aug 2023 17:50:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230526AbjHJVuK (ORCPT ); Thu, 10 Aug 2023 17:50:10 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3938ED for ; Thu, 10 Aug 2023 14:50:09 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-57320c10635so17727117b3.3 for ; Thu, 10 Aug 2023 14:50:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691704209; x=1692309009; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=igst4mk2Qe0yy+cOTE8q+SB7QjnlDxT/LagI8IxyHvs=; b=1Uh56WiLkoyMI5VvuQ64Fkl3EL0jo1oj3OUQZspMOCcGeQn1Z6MqFewMaAPYVc2J7o GkjBsp00AuA3CGVqZ2dkDm8HR1hjHNxwwIBiYlZio4VvZH5or4SpIxGnx0Uha/FmP8Xn HUPmripMAou5hS/8lKfpSQl1lwYOzrJ5jGysvXq0qeRrlYzUPVbfT+9ALqyXNrkJc56U /Ga/aScGDvGubfT8S3612p/aPhIZJ6syAh9UF8v2Nn3m2hjeR9HY1JgH/riCquwasQz3 DFbCnUVs/8qGv0tFo3GRHE5QWUcSC2rIOCtEU1lGi8vWdyXjeFJqViqVNrWWddBHijKW R4mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691704209; x=1692309009; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=igst4mk2Qe0yy+cOTE8q+SB7QjnlDxT/LagI8IxyHvs=; b=GScdGwFIUs2Fa78VJL+dfhhrhdfgkKY/x+D1GJrRFMMDCoxR/moooh1+fxajibDN8f YEAkIRQdp4LjjlkDjrbboo15IZEjIv8PjGyjbqlgWEtlJPY2BcQ7TnWgXn9nz1p6XyYo dT4TkMBE9HMAYuwwnnI7/3DmtknQ+Mb88nIqDPhjLX/onLgtsUmZXXOAkKZTrCEw9vkt ax2M2yhEe7HyJ6JzvFRP5tWbBvJ6sn/RV+ucLMwSrTB18eBX/wgWM1ce7vjdM62eBJSq 2PIhSk0YlzaFOI+PD2FwQbL9tU4GADqF8HiaBa/ddj6rVnPo48XFqdcWhIwIw0igkynD QCWg== X-Gm-Message-State: AOJu0YxwPUfGufLoXfTaU/Nf1+FcSo3qQG2qexctlTujjTPMo2h2Yq83 Pad39GA4Ci27nEILu3fWS6o9m1yLHtO2 X-Google-Smtp-Source: AGHT+IHqVFGK64ooHjYnqb74yHRXIzY5S8RKU8bRuw3+8hqn+avf1VIEUlEkbcFNHzS4NKdKdZJHa5r2QZM0 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:797f:302e:992f:97f2]) (user=irogers job=sendgmr) by 2002:a25:e750:0:b0:d0e:e780:81b3 with SMTP id e77-20020a25e750000000b00d0ee78081b3mr58676ybh.2.1691704209270; Thu, 10 Aug 2023 14:50:09 -0700 (PDT) Date: Thu, 10 Aug 2023 14:49:51 -0700 In-Reply-To: <20230810214952.2934029-1-irogers@google.com> Message-Id: <20230810214952.2934029-3-irogers@google.com> Mime-Version: 1.0 References: <20230810214952.2934029-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog Subject: [PATCH v2 2/3] perf pmus: Add scan that ignores duplicates, use for perf list From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kan Liang , Ravi Bangoria , Kajol Jain , John Garry , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When there are multiple PMUs that differ only by suffix, by default just list the first one and skip all others. As the PMUs are sorted, the scan routine checks that the PMU names match and the numbers are consecutive. If "-v" is passed to "perf list" then list all PMUs. Signed-off-by: Ian Rogers --- tools/perf/builtin-list.c | 8 +++++ tools/perf/util/pmus.c | 54 ++++++++++++++++++++++++++++++++-- tools/perf/util/print-events.h | 1 + 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c index 7fec2cca759f..8fe4ddf02c14 100644 --- a/tools/perf/builtin-list.c +++ b/tools/perf/builtin-list.c @@ -423,6 +423,13 @@ static void json_print_metric(void *ps __maybe_unused,= const char *group, strbuf_release(&buf); } =20 +static bool default_skip_duplicate_pmus(void *ps) +{ + struct print_state *print_state =3D ps; + + return !print_state->long_desc; +} + int cmd_list(int argc, const char **argv) { int i, ret =3D 0; @@ -434,6 +441,7 @@ int cmd_list(int argc, const char **argv) .print_end =3D default_print_end, .print_event =3D default_print_event, .print_metric =3D default_print_metric, + .skip_duplicate_pmus =3D default_skip_duplicate_pmus, }; const char *cputype =3D NULL; const char *unit_name =3D NULL; diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 3581710667b0..5073843aca19 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -275,6 +275,50 @@ struct perf_pmu *perf_pmus__scan_core(struct perf_pmu = *pmu) return NULL; } =20 +static struct perf_pmu *perf_pmus__scan_skip_duplicates(struct perf_pmu *p= mu) +{ + bool use_core_pmus =3D !pmu || pmu->is_core; + int last_pmu_name_len =3D 0; + unsigned long last_pmu_num =3D 0; + const char *last_pmu_name =3D (pmu && pmu->name) ? pmu->name : ""; + + if (!pmu) { + pmu_read_sysfs(/*core_only=3D*/false); + pmu =3D list_prepare_entry(pmu, &core_pmus, list); + } else + last_pmu_name_len =3D pmu_name_len_no_suffix(pmu->name ?: "", &last_pmu_= num); + + if (use_core_pmus) { + list_for_each_entry_continue(pmu, &core_pmus, list) { + unsigned long pmu_num =3D 0; + int pmu_name_len =3D pmu_name_len_no_suffix(pmu->name ?: "", &pmu_num); + + if (last_pmu_name_len =3D=3D pmu_name_len && + (last_pmu_num + 1 =3D=3D pmu_num) && + !strncmp(last_pmu_name, pmu->name ?: "", pmu_name_len)) { + last_pmu_num++; + continue; + } + return pmu; + } + pmu =3D NULL; + pmu =3D list_prepare_entry(pmu, &other_pmus, list); + } + list_for_each_entry_continue(pmu, &other_pmus, list) { + unsigned long pmu_num =3D 0; + int pmu_name_len =3D pmu_name_len_no_suffix(pmu->name ?: "", &pmu_num); + + if (last_pmu_name_len =3D=3D pmu_name_len && + (last_pmu_num + 1 =3D=3D pmu_num) && + !strncmp(last_pmu_name, pmu->name ?: "", pmu_name_len)) { + last_pmu_num++; + continue; + } + return pmu; + } + return NULL; +} + const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str) { struct perf_pmu *pmu =3D NULL; @@ -429,10 +473,16 @@ void perf_pmus__print_pmu_events(const struct print_c= allbacks *print_cb, void *p int printed =3D 0; int len, j; struct sevent *aliases; + struct perf_pmu *(*scan_fn)(struct perf_pmu *); + + if (print_cb->skip_duplicate_pmus(print_state)) + scan_fn =3D perf_pmus__scan_skip_duplicates; + else + scan_fn =3D perf_pmus__scan; =20 pmu =3D NULL; len =3D 0; - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { + while ((pmu =3D scan_fn(pmu)) !=3D NULL) { list_for_each_entry(event, &pmu->aliases, list) len++; if (pmu->selectable) @@ -445,7 +495,7 @@ void perf_pmus__print_pmu_events(const struct print_cal= lbacks *print_cb, void *p } pmu =3D NULL; j =3D 0; - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { + while ((pmu =3D scan_fn(pmu)) !=3D NULL) { bool is_cpu =3D pmu->is_core; =20 list_for_each_entry(event, &pmu->aliases, list) { diff --git a/tools/perf/util/print-events.h b/tools/perf/util/print-events.h index d7fab411e75c..bf4290bef0cd 100644 --- a/tools/perf/util/print-events.h +++ b/tools/perf/util/print-events.h @@ -26,6 +26,7 @@ struct print_callbacks { const char *expr, const char *threshold, const char *unit); + bool (*skip_duplicate_pmus)(void *print_state); }; =20 /** Print all events, the default when no options are specified. */ --=20 2.41.0.640.ga95def55d0-goog From nobody Sun Feb 8 10:50:07 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BD3AC04A94 for ; Thu, 10 Aug 2023 21:50:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231231AbjHJVuV (ORCPT ); Thu, 10 Aug 2023 17:50:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231174AbjHJVuN (ORCPT ); Thu, 10 Aug 2023 17:50:13 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E4F3273E for ; Thu, 10 Aug 2023 14:50:12 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d5d5617ecc9so1343091276.1 for ; Thu, 10 Aug 2023 14:50:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691704211; x=1692309011; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=nscFVL3MFrP2MCfpvE3b34w9xAwW74LjxwP+hgfykt8=; b=5FZtuCkOD8r22iOeIWwQ4EsKC5V9oacrymly9BvtQDx+idhZLiswyd2Pn4fM+Y5yJU gihlEkfRYcZf+1od12kgpm54yVKgJK7Kp02Fg5aaLqMXX4HvsMKCvC9IlLrzauKF1goE emh076z/YKK/fJ62QXpR2rkG+QMHC/RaiZgTwNg4RY+ds/iLPnai5viHHZlucQ04R5L3 Ca1j1b//D1R+DowDCdlvDl6kX5Q4A0mIGMow6CEzNRF9TexLxzUgBNhUR7xvyfdU6aTS rGbfEVmw188O8OYF7SOCwkgYPg6oVMYJtDt2P1rHtBnpwWPtJuCbvsdr5+w6ydavhOoU S2YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691704211; x=1692309011; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nscFVL3MFrP2MCfpvE3b34w9xAwW74LjxwP+hgfykt8=; b=VGxmw8oHBZ4J7WRYmFv2zlkjtc6+r84sJMEl6oakWRbAWfOSZTFruG1eq/kjROMHfW yqZk2jDsY0Bj7w0NPeg+cConCi2S8uCl3JL51plI3b1qFoKUxGVhy1OryvcX3TpTrJ51 vulXHua2Whh666h5xRQfjwsWs+M0WyRu3VEolAqCWvXIsk2KeLYcfhWeRljF1NG4ahIR Z0Yq2ki0BArshYS60sqK2+DffHEtTwARFDStI5Jd+YswbtBnbB8ofkWjiM6l45ufdUSm y3GuIt/l+lcoSHrHhFeFBN+UfhW3PUG+C6RCk/ID4OjuK8YoWF1pv42eLHEDhW/Rj0AS rILw== X-Gm-Message-State: AOJu0YwWqAhc9IXjFdtR1wNF6jhVmMfYVYxSIZLEDk1kyJXhYUUuCzli cV8xp0VOyO8LBkjq4hOAnZflzF0Rz7VG X-Google-Smtp-Source: AGHT+IFhhIft5gWXsXGy4semc/T7A1pqRtRHdrjo123kU3YRYq8kKu0kmsMFOr7Pr8tU4963zgfNzCg55EHG X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:797f:302e:992f:97f2]) (user=irogers job=sendgmr) by 2002:a25:60d6:0:b0:d12:d6e4:a08d with SMTP id u205-20020a2560d6000000b00d12d6e4a08dmr51937ybb.7.1691704211412; Thu, 10 Aug 2023 14:50:11 -0700 (PDT) Date: Thu, 10 Aug 2023 14:49:52 -0700 In-Reply-To: <20230810214952.2934029-1-irogers@google.com> Message-Id: <20230810214952.2934029-4-irogers@google.com> Mime-Version: 1.0 References: <20230810214952.2934029-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog Subject: [PATCH v2 3/3] perf pmus: Don't print duplicate PMU suffix in list by default From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kan Liang , Ravi Bangoria , Kajol Jain , John Garry , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Duplicate PMUs are no longer printed by default but the suffix of the first is printed. When duplicate PMUs are being skipped avoid printing the suffix. Before: ``` $ perf list ... uncore_imc_free_running_0/data_read/ [Kernel PMU event] uncore_imc_free_running_0/data_total/ [Kernel PMU event] uncore_imc_free_running_0/data_write/ [Kernel PMU event] ``` After: ``` $ perf list ... uncore_imc_free_running/data_read/ [Kernel PMU event] uncore_imc_free_running/data_total/ [Kernel PMU event] uncore_imc_free_running/data_write/ [Kernel PMU event] ... $ perf list -v uncore_imc_free_running_0/data_read/ [Kernel PMU event] uncore_imc_free_running_0/data_total/ [Kernel PMU event] uncore_imc_free_running_0/data_write/ [Kernel PMU event] uncore_imc_free_running_1/data_read/ [Kernel PMU event] uncore_imc_free_running_1/data_total/ [Kernel PMU event] uncore_imc_free_running_1/data_write/ [Kernel PMU event] ... ``` Signed-off-by: Ian Rogers --- tools/perf/util/pmus.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 5073843aca19..b0ecb2e5bdcc 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -440,10 +440,13 @@ static int sub_non_neg(int a, int b) } =20 static char *format_alias(char *buf, int len, const struct perf_pmu *pmu, - const struct perf_pmu_alias *alias) + const struct perf_pmu_alias *alias, bool skip_duplicate_pmus) { struct parse_events_term *term; - int used =3D snprintf(buf, len, "%s/%s", pmu->name, alias->name); + int pmu_name_len =3D skip_duplicate_pmus + ? pmu_name_len_no_suffix(pmu->name, /*num=3D*/NULL) + : (int)strlen(pmu->name); + int used =3D snprintf(buf, len, "%.*s/%s", pmu_name_len, pmu->name, alias= ->name); =20 list_for_each_entry(term, &alias->terms, list) { if (term->type_val =3D=3D PARSE_EVENTS__TERM_TYPE_STR) @@ -473,9 +476,10 @@ void perf_pmus__print_pmu_events(const struct print_ca= llbacks *print_cb, void *p int printed =3D 0; int len, j; struct sevent *aliases; + bool skip_duplicate_pmus =3D print_cb->skip_duplicate_pmus(print_state); struct perf_pmu *(*scan_fn)(struct perf_pmu *); =20 - if (print_cb->skip_duplicate_pmus(print_state)) + if (skip_duplicate_pmus) scan_fn =3D perf_pmus__scan_skip_duplicates; else scan_fn =3D perf_pmus__scan; @@ -518,6 +522,7 @@ void perf_pmus__print_pmu_events(const struct print_cal= lbacks *print_cb, void *p *desc =3D NULL, *long_desc =3D NULL, *encoding_desc =3D NULL, *topic =3D NULL, *pmu_name =3D NULL; + int pmu_name_len; bool deprecated =3D false; size_t buf_used; =20 @@ -528,7 +533,8 @@ void perf_pmus__print_pmu_events(const struct print_cal= lbacks *print_cb, void *p if (!aliases[j].event) { /* A selectable event. */ pmu_name =3D aliases[j].pmu->name; - buf_used =3D snprintf(buf, sizeof(buf), "%s//", pmu_name) + 1; + pmu_name_len =3D pmu_name_len_no_suffix(pmu_name, /*num=3D*/NULL); + buf_used =3D snprintf(buf, sizeof(buf), "%.*s//", pmu_name_len, pmu_nam= e) + 1; name =3D buf; } else { if (aliases[j].event->desc) { @@ -536,7 +542,7 @@ void perf_pmus__print_pmu_events(const struct print_cal= lbacks *print_cb, void *p buf_used =3D 0; } else { name =3D format_alias(buf, sizeof(buf), aliases[j].pmu, - aliases[j].event); + aliases[j].event, skip_duplicate_pmus); if (aliases[j].is_cpu) { alias =3D name; name =3D aliases[j].event->name; @@ -554,8 +560,10 @@ void perf_pmus__print_pmu_events(const struct print_ca= llbacks *print_cb, void *p long_desc =3D aliases[j].event->long_desc; topic =3D aliases[j].event->topic; encoding_desc =3D buf + buf_used; + pmu_name_len =3D pmu_name_len_no_suffix(pmu_name, /*num=3D*/NULL); buf_used +=3D snprintf(buf + buf_used, sizeof(buf) - buf_used, - "%s/%s/", pmu_name, aliases[j].event->str) + 1; + "%.*s/%s/", pmu_name_len, pmu_name, + aliases[j].event->str) + 1; deprecated =3D aliases[j].event->deprecated; } print_cb->print_event(print_state, --=20 2.41.0.640.ga95def55d0-goog