Skip to content

Commit bc35582

Browse files
captain5050acmel
authored andcommitted
perf parse-events: Move slots only with topdown
If slots isn't with a topdown event then moving it is unnecessary. For example {instructions, slots} is re-ordered: $ perf stat -e '{instructions,slots}' -a sleep 1 Performance counter stats for 'system wide': 936,600,825 slots 144,440,968 instructions 1.006061423 seconds time elapsed Which can break tools expecting the command line order to match the printed order. It is necessary to move the slots event first when it appears with topdown events. Add extra checking so that the slots event is only moved in the case of there being a topdown event like: $ perf stat -e '{instructions,slots,topdown-fe-bound}' -a sleep 1 Performance counter stats for 'system wide': 2427568570 slots 300927614 instructions 551021649 topdown-fe-bound 1.001771803 seconds time elapsed Fixes: 94dbfd6 ("perf parse-events: Architecture specific leader override") Reported-by: Kan Liang <kan.liang@linux.intel.com> Signed-off-by: Ian Rogers <irogers@google.com> Tested-by: Kan Liang <kan.liang@linux.intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Alexandre Torgue <alexandre.torgue@foss.st.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@arm.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: John Garry <john.garry@huawei.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com> Link: https://lore.kernel.org/r/20220321223344.1034479-1-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 34fe4cc commit bc35582

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

tools/perf/arch/x86/util/evlist.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,27 @@ int arch_evlist__add_default_attrs(struct evlist *evlist)
2020

2121
struct evsel *arch_evlist__leader(struct list_head *list)
2222
{
23-
struct evsel *evsel, *first;
23+
struct evsel *evsel, *first, *slots = NULL;
24+
bool has_topdown = false;
2425

2526
first = list_first_entry(list, struct evsel, core.node);
2627

2728
if (!pmu_have_event("cpu", "slots"))
2829
return first;
2930

31+
/* If there is a slots event and a topdown event then the slots event comes first. */
3032
__evlist__for_each_entry(list, evsel) {
31-
if (evsel->pmu_name && !strcmp(evsel->pmu_name, "cpu") &&
32-
evsel->name && strcasestr(evsel->name, "slots"))
33-
return evsel;
33+
if (evsel->pmu_name && !strcmp(evsel->pmu_name, "cpu") && evsel->name) {
34+
if (strcasestr(evsel->name, "slots")) {
35+
slots = evsel;
36+
if (slots == first)
37+
return first;
38+
}
39+
if (!strncasecmp(evsel->name, "topdown", 7))
40+
has_topdown = true;
41+
if (slots && has_topdown)
42+
return slots;
43+
}
3444
}
3545
return first;
3646
}

0 commit comments

Comments
 (0)