All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] Improve workload error in 'perf record'
@ 2021-04-14 13:16 Arnaldo Carvalho de Melo
  2021-04-14 13:16 ` [PATCH 1/2] perf evlist: Add a method to return the list of evsels as a string Arnaldo Carvalho de Melo
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-04-14 13:16 UTC (permalink / raw)
  To: Jiri Olsa, Namhyung Kim
  Cc: Ingo Molnar, Thomas Gleixner, Clark Williams, linux-kernel,
	linux-perf-users, Arnaldo Carvalho de Melo, Adrian Hunter,
	Ian Rogers

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(-)

-- 
2.26.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] perf evlist: Add a method to return the list of evsels as a string
  2021-04-14 13:16 [RFC] Improve workload error in 'perf record' Arnaldo Carvalho de Melo
@ 2021-04-14 13:16 ` Arnaldo Carvalho de Melo
  2021-04-14 13:16 ` [PATCH 2/2] perf record: Improve 'Workload failed' message printing events + what was exec'ed Arnaldo Carvalho de Melo
  2021-04-15  5:33 ` [RFC] Improve workload error in 'perf record' Ian Rogers
  2 siblings, 0 replies; 4+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-04-14 13:16 UTC (permalink / raw)
  To: Jiri Olsa, Namhyung Kim
  Cc: Ingo Molnar, Thomas Gleixner, Clark Williams, linux-kernel,
	linux-perf-users, Arnaldo Carvalho de Melo, Adrian Hunter,
	Ian Rogers

From: Arnaldo Carvalho de Melo <acme@redhat.com>

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 <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/evlist.c | 19 +++++++++++++++++++
 tools/perf/util/evlist.h |  2 ++
 2 files changed, 21 insertions(+)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index f1c79ecf81073f74..d29a8a118973c71c 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -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;
+}
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index b695ffaae519a5d0..a8b97b50cceb7e43 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -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 */
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] perf record: Improve 'Workload failed' message printing events + what was exec'ed
  2021-04-14 13:16 [RFC] Improve workload error in 'perf record' Arnaldo Carvalho de Melo
  2021-04-14 13:16 ` [PATCH 1/2] perf evlist: Add a method to return the list of evsels as a string Arnaldo Carvalho de Melo
@ 2021-04-14 13:16 ` Arnaldo Carvalho de Melo
  2021-04-15  5:33 ` [RFC] Improve workload error in 'perf record' Ian Rogers
  2 siblings, 0 replies; 4+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-04-14 13:16 UTC (permalink / raw)
  To: Jiri Olsa, Namhyung Kim
  Cc: Ingo Molnar, Thomas Gleixner, Clark Williams, linux-kernel,
	linux-perf-users, Arnaldo Carvalho de Melo, Adrian Hunter,
	Ian Rogers

From: Arnaldo Carvalho de Melo <acme@redhat.com>

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 <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-record.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 35465d1db6dda3ae..5fb9665a2ec27dde 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -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;
 	}
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [RFC] Improve workload error in 'perf record'
  2021-04-14 13:16 [RFC] Improve workload error in 'perf record' Arnaldo Carvalho de Melo
  2021-04-14 13:16 ` [PATCH 1/2] perf evlist: Add a method to return the list of evsels as a string Arnaldo Carvalho de Melo
  2021-04-14 13:16 ` [PATCH 2/2] perf record: Improve 'Workload failed' message printing events + what was exec'ed Arnaldo Carvalho de Melo
@ 2021-04-15  5:33 ` Ian Rogers
  2 siblings, 0 replies; 4+ messages in thread
From: Ian Rogers @ 2021-04-15  5:33 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Jiri Olsa, Namhyung Kim, Ingo Molnar, Thomas Gleixner,
	Clark Williams, LKML, linux-perf-users, Adrian Hunter

On Wed, Apr 14, 2021 at 6:16 AM Arnaldo Carvalho de Melo
<acme@kernel.org> wrote:
>
> Hi,
>
>         Please take a look,
>
> Best regards,

Acked-by: Ian Rogers <irogers@google.com>

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

> - 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
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-04-15  5:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-14 13:16 [RFC] Improve workload error in 'perf record' Arnaldo Carvalho de Melo
2021-04-14 13:16 ` [PATCH 1/2] perf evlist: Add a method to return the list of evsels as a string Arnaldo Carvalho de Melo
2021-04-14 13:16 ` [PATCH 2/2] perf record: Improve 'Workload failed' message printing events + what was exec'ed Arnaldo Carvalho de Melo
2021-04-15  5:33 ` [RFC] Improve workload error in 'perf record' Ian Rogers

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.