perf evlist: Add a method to return the list of evsels as a string
authorArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 14 Apr 2021 13:08:16 +0000 (10:08 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 15 Apr 2021 19:33:57 +0000 (16:33 -0300)
Add a 'scnprintf' method to obtain the list of evsels in a evlist as a
string, excluding the "dummy" event used for things like receiving
metadata events (PERF_RECORD_FORK, MMAP, etc) when synthesizing
preexisting threads.

Will be used to improve the error message for workload failure in 'perf
record.

Acked-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lore.kernel.org/lkml/20210414131628.2064862-2-acme@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/evlist.c
tools/perf/util/evlist.h

index f1c79ecf81073f74c1faa0f3062b7e7fde0b6f16..d29a8a118973c71c2eeeb2029ad6a1d2b8f1e00d 100644 (file)
@@ -2138,3 +2138,22 @@ struct evsel *evlist__find_evsel(struct evlist *evlist, int idx)
        }
        return NULL;
 }
+
+int evlist__scnprintf_evsels(struct evlist *evlist, size_t size, char *bf)
+{
+       struct evsel *evsel;
+       int printed = 0;
+
+       evlist__for_each_entry(evlist, evsel) {
+               if (evsel__is_dummy_event(evsel))
+                       continue;
+               if (size > (strlen(evsel__name(evsel)) + (printed ? 2 : 1))) {
+                       printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "," : "", evsel__name(evsel));
+               } else {
+                       printed += scnprintf(bf + printed, size - printed, "%s...", printed ? "," : "");
+                       break;
+               }
+       }
+
+       return printed;
+}
index b695ffaae519a5d09d184325c33a4c37639f4e0c..a8b97b50cceb7e43aed161922f26d4082cb2c240 100644 (file)
@@ -365,4 +365,6 @@ int evlist__ctlfd_ack(struct evlist *evlist);
 #define EVLIST_DISABLED_MSG "Events disabled\n"
 
 struct evsel *evlist__find_evsel(struct evlist *evlist, int idx);
+
+int evlist__scnprintf_evsels(struct evlist *evlist, size_t size, char *bf);
 #endif /* __PERF_EVLIST_H */