[PATCH 1/3] perf list: Order events by event name before PMU name

James Clark posted 3 patches 11 months, 1 week ago
[PATCH 1/3] perf list: Order events by event name before PMU name
Posted by James Clark 11 months, 1 week ago
In order to be able to show a single line for the same events on
different PMUs, they need to be grouped by event name. This is because
deduplication relies on similar items being adjacent in the list.

Even without the following changes this would arguably be better
grouping because it's easier to find events in a topic alphabetically
by name, rather than in separate PMU blocks.

Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/util/pmus.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c
index dd7c2ffdab38..4d60bac2d2b9 100644
--- a/tools/perf/util/pmus.c
+++ b/tools/perf/util/pmus.c
@@ -445,15 +445,15 @@ static int cmp_sevent(const void *a, const void *b)
 	if (a_iscpu != b_iscpu)
 		return a_iscpu ? -1 : 1;
 
-	/* Order by PMU name. */
-	if (as->pmu != bs->pmu) {
-		ret = strcmp(as->pmu_name ?: "", bs->pmu_name ?: "");
-		if (ret)
-			return ret;
-	}
-
 	/* Order by event name. */
-	return strcmp(as->name, bs->name);
+	ret = strcmp(as->name, bs->name);
+	if (ret)
+		return ret;
+
+	/* Order by PMU name. */
+	if (as->pmu == bs->pmu)
+		return 0;
+	return strcmp(as->pmu_name ?: "", bs->pmu_name ?: "");
 }
 
 static bool pmu_alias_is_duplicate(struct sevent *a, struct sevent *b)

-- 
2.34.1
Re: [PATCH 1/3] perf list: Order events by event name before PMU name
Posted by Ian Rogers 11 months, 1 week ago
On Tue, Mar 4, 2025 at 5:50 AM James Clark <james.clark@linaro.org> wrote:
>
> In order to be able to show a single line for the same events on
> different PMUs, they need to be grouped by event name. This is because
> deduplication relies on similar items being adjacent in the list.
>
> Even without the following changes this would arguably be better
> grouping because it's easier to find events in a topic alphabetically
> by name, rather than in separate PMU blocks.
>
> Signed-off-by: James Clark <james.clark@linaro.org>

Tested-by: Ian Rogers <irogers@google.com>

Thanks,
Ian

> ---
>  tools/perf/util/pmus.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c
> index dd7c2ffdab38..4d60bac2d2b9 100644
> --- a/tools/perf/util/pmus.c
> +++ b/tools/perf/util/pmus.c
> @@ -445,15 +445,15 @@ static int cmp_sevent(const void *a, const void *b)
>         if (a_iscpu != b_iscpu)
>                 return a_iscpu ? -1 : 1;
>
> -       /* Order by PMU name. */
> -       if (as->pmu != bs->pmu) {
> -               ret = strcmp(as->pmu_name ?: "", bs->pmu_name ?: "");
> -               if (ret)
> -                       return ret;
> -       }
> -
>         /* Order by event name. */
> -       return strcmp(as->name, bs->name);
> +       ret = strcmp(as->name, bs->name);
> +       if (ret)
> +               return ret;
> +
> +       /* Order by PMU name. */
> +       if (as->pmu == bs->pmu)
> +               return 0;
> +       return strcmp(as->pmu_name ?: "", bs->pmu_name ?: "");
>  }
>
>  static bool pmu_alias_is_duplicate(struct sevent *a, struct sevent *b)
>
> --
> 2.34.1
>