OSDN Git Service

Merge tag 'perf-tools-for-v5.18-2022-03-26' of git://git.kernel.org/pub/scm/linux...
[uclinux-h8/linux.git] / tools / perf / arch / x86 / util / evlist.c
index 8d9b559..cfc208d 100644 (file)
@@ -20,17 +20,27 @@ int arch_evlist__add_default_attrs(struct evlist *evlist)
 
 struct evsel *arch_evlist__leader(struct list_head *list)
 {
-       struct evsel *evsel, *first;
+       struct evsel *evsel, *first, *slots = NULL;
+       bool has_topdown = false;
 
        first = list_first_entry(list, struct evsel, core.node);
 
        if (!pmu_have_event("cpu", "slots"))
                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 && !strcmp(evsel->pmu_name, "cpu") &&
-                       evsel->name && strcasestr(evsel->name, "slots"))
-                       return evsel;
+               if (evsel->pmu_name && !strcmp(evsel->pmu_name, "cpu") && evsel->name) {
+                       if (strcasestr(evsel->name, "slots")) {
+                               slots = evsel;
+                               if (slots == first)
+                                       return first;
+                       }
+                       if (!strncasecmp(evsel->name, "topdown", 7))
+                               has_topdown = true;
+                       if (slots && has_topdown)
+                               return slots;
+               }
        }
        return first;
 }