summaryrefslogtreecommitdiff
path: root/tools/perf/arch/x86/util/evlist.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/arch/x86/util/evlist.c')
-rw-r--r--tools/perf/arch/x86/util/evlist.c45
1 files changed, 19 insertions, 26 deletions
diff --git a/tools/perf/arch/x86/util/evlist.c b/tools/perf/arch/x86/util/evlist.c
index cb59ce9b9638..d4193479a364 100644
--- a/tools/perf/arch/x86/util/evlist.c
+++ b/tools/perf/arch/x86/util/evlist.c
@@ -59,35 +59,28 @@ int arch_evlist__add_default_attrs(struct evlist *evlist,
struct perf_event_attr *attrs,
size_t nr_attrs)
{
- if (nr_attrs)
- return ___evlist__add_default_attrs(evlist, attrs, nr_attrs);
+ if (!nr_attrs)
+ return 0;
- return topdown_parse_events(evlist);
+ return ___evlist__add_default_attrs(evlist, attrs, nr_attrs);
}
-struct evsel *arch_evlist__leader(struct list_head *list)
+int arch_evlist__cmp(const struct evsel *lhs, const struct evsel *rhs)
{
- struct evsel *evsel, *first, *slots = NULL;
- bool has_topdown = false;
-
- first = list_first_entry(list, struct evsel, core.node);
-
- if (!topdown_sys_has_perf_metrics())
- return first;
-
- /* If there is a slots event and a topdown event then the slots event comes first. */
- __evlist__for_each_entry(list, evsel) {
- if (evsel->pmu_name && !strncmp(evsel->pmu_name, "cpu", 3) && evsel->name) {
- if (strcasestr(evsel->name, "slots")) {
- slots = evsel;
- if (slots == first)
- return first;
- }
- if (strcasestr(evsel->name, "topdown"))
- has_topdown = true;
- if (slots && has_topdown)
- return slots;
- }
+ if (topdown_sys_has_perf_metrics() &&
+ (!lhs->pmu_name || !strncmp(lhs->pmu_name, "cpu", 3))) {
+ /* Ensure the topdown slots comes first. */
+ if (strcasestr(lhs->name, "slots"))
+ return -1;
+ if (strcasestr(rhs->name, "slots"))
+ return 1;
+ /* Followed by topdown events. */
+ if (strcasestr(lhs->name, "topdown") && !strcasestr(rhs->name, "topdown"))
+ return -1;
+ if (!strcasestr(lhs->name, "topdown") && strcasestr(rhs->name, "topdown"))
+ return 1;
}
- return first;
+
+ /* Default ordering by insertion index. */
+ return lhs->core.idx - rhs->core.idx;
}