Skip to content

Commit

Permalink
perf stat: Stop repeating when ref_perf_stat() returns -1
Browse files Browse the repository at this point in the history
Exit when run_perf_stat() returns an error to avoid continuously
repeating the same error message. It's not expected that COUNTER_FATAL
or internal errors are recoverable so there's no point in retrying.

This fixes the following flood of error messages for permission issues,
for example when perf_event_paranoid==3:
  perf stat -r 1044 -- false

  Error:
  Access to performance monitoring and observability operations is limited.
  ...
  Error:
  Access to performance monitoring and observability operations is limited.
  ...
  (repeating for 1044 times).

Signed-off-by: Levi Yun <yeoreum.yun@arm.com>
Reviewed-by: James Clark <james.clark@linaro.org>
Cc: nd@arm.com
Cc: howardchu95@gmail.com
Link: https://lore.kernel.org/r/20240925132022.2650180-3-yeoreum.yun@arm.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
  • Loading branch information
Levi Yun authored and Namhyung Kim committed Sep 25, 2024
1 parent e880a70 commit b77f8c3
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tools/perf/builtin-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,14 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
return err;
}

/*
* Returns -1 for fatal errors which signifies to not continue
* when in repeat mode.
*
* Returns < -1 error codes when stat record is used. These
* result in the stat information being displayed, but writing
* to the file fails and is non fatal.
*/
static int run_perf_stat(int argc, const char **argv, int run_idx)
{
int ret;
Expand Down Expand Up @@ -2899,7 +2907,10 @@ int cmd_stat(int argc, const char **argv)
evlist__reset_prev_raw_counts(evsel_list);

status = run_perf_stat(argc, argv, run_idx);
if (forever && status != -1 && !interval) {
if (status == -1)
break;

if (forever && !interval) {
print_counters(NULL, argc, argv);
perf_stat__reset_stats();
}
Expand Down

0 comments on commit b77f8c3

Please sign in to comment.