Skip to contentSkip to conversation

Improve workload error in 'perf record'

RFC New Arnaldo Carvalho de Melo 2 participants 4 messages Apr 14, 2021 – Apr 15, 2021 perf events

lore
Share & tools
lore

Arnaldo Carvalho de Melo

author maintainer
#0 lore raw

Hi,

Please take a look,

Best regards,

- Arnaldo

Arnaldo Carvalho de Melo (2):
perf evlist: Add a method to return the list of evsels as a string perf record: Improve 'Workload failed' message printing events + what
was exec'ed

 tools/perf/builtin-record.c |  8 ++++++--
 tools/perf/util/evlist.c    | 19 +++++++++++++++++++
 tools/perf/util/evlist.h    |  2 ++
 3 files changed, 27 insertions(+), 2 deletions(-)
Signature · 1 line
2.26.2
author maintainer
#1 lore raw

PATCH 1/2 perf evlist: Add a method to return the list of evsels as a string

From: Arnaldo Carvalho de Melo <[email protected]>

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.

Cc Adrian Hunter <[email protected]>
Cc Ian Rogers <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
---
 tools/perf/util/evlist.c | 19 +++++++++++++++++++
 tools/perf/util/evlist.h |  2 ++
 2 files changed, 21 insertions(+)
tools/perf/util/evlist.c +19 -0
index f1c79ecf81073f74..d29a8a118973c71c 100644
@@ -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;
+}
tools/perf/util/evlist.h +2 -0
index b695ffaae519a5d0..a8b97b50cceb7e43 100644
@@ -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 */
Signature · 1 line
2.26.2
author maintainer
#2 lore raw

PATCH 2/2 perf record: Improve 'Workload failed' message printing events + what was exec'ed

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Before:

  # perf record -a cycles,instructions,cache-misses
  Workload failed: No such file or directory
  #

After:

  # perf record -a cycles,instructions,cache-misses
  Failed to collect 'cycles' for the 'cycles,instructions,cache-misses' workload: No such file or directory
  #

Helps disambiguating other error scenarios:

  # perf record -a -e cycles,instructions,cache-misses bla
  Failed to collect 'cycles,instructions,cache-misses' for the 'bla' workload: No such file or directory
  # perf record -a cycles,instructions,cache-misses sleep 1
  Failed to collect 'cycles' for the 'cycles,instructions,cache-misses' workload: No such file or directory
  #

When all goes well we're back to the usual:

  # perf record -a -e cycles,instructions,cache-misses sleep 1
  [ perf record: Woken up 3 times to write data ]
  [ perf record: Captured and wrote 3.151 MB perf.data (21242 samples) ]
  #
Cc Adrian Hunter <[email protected]>
Cc Ian Rogers <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
---
 tools/perf/builtin-record.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tools/perf/builtin-record.c +6 -2
index 35465d1db6dda3ae..5fb9665a2ec27dde 100644
@@ -1977,9 +1977,13 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 		record__auxtrace_snapshot_exit(rec);
 
 	if (forks && workload_exec_errno) {
-		char msg[STRERR_BUFSIZE];
+		char msg[STRERR_BUFSIZE], strevsels[2048];
 		const char *emsg = str_error_r(workload_exec_errno, msg, sizeof(msg));
-		pr_err("Workload failed: %s\n", emsg);
+
+		evlist__scnprintf_evsels(rec->evlist, sizeof(strevsels), strevsels);
+
+		pr_err("Failed to collect '%s' for the '%s' workload: %s\n",
+			strevsels, argv[0], emsg);
 		err = -1;
 		goto out_child;
 	}
Signature · 1 line
2.26.2
reviewer Acked-by
#3 lore raw
In reply to Arnaldo Carvalho de Melo
Quoted 6 lines · Arnaldo Carvalho de Melo

Hi,

Please take a look,

Best regards,

Having been confused by this for a case in the past, thanks! It'd be nice for code coverage's sake to have a shell test on this.

Thanks,
Ian

Quoted 15 lines

- Arnaldo

Arnaldo Carvalho de Melo (2):
perf evlist: Add a method to return the list of evsels as a string perf record: Improve 'Workload failed' message printing events + what
was exec'ed

 tools/perf/builtin-record.c |  8 ++++++--
 tools/perf/util/evlist.c    | 19 +++++++++++++++++++
 tools/perf/util/evlist.h    |  2 ++
 3 files changed, 27 insertions(+), 2 deletions(-)

--
2.26.2