aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2014-08-01 11:46:54 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2014-08-12 11:03:02 -0400
commit63914aca8f7e7a75d0ee027af7b1755c69cc1e2c (patch)
treec65607803096bc9f410a44b3a81fd1d7fad2cf2c
parentb0a45203a75a800015828ac89f2945981019b65b (diff)
perf tools: Show better error message in case we fail to open counters due to EBUSY error
Showing better error message in case we fail to open counters due to the EBUSY error. If we detect oprofile daemon process running, we now display following message for EBUSY error: $ perf record ls Error: The PMU counters are busy/taken by another profiler. We found oprofile daemon running, please stop it and try again. In case oprofiled was not detected the current error message stays: $ perf record ls Error: The sys_perf_event_open() syscall returned with 16 (Device or resource busy) for event (cycles). /bin/dmesg may provide additional information. No CONFIG_PERF_EVENTS=y kernel support configured? Also changing PERF_FLAG_FD_CLOEXEC detection code not to display error in case of EBUSY error, as it currently does: $ perf record ls Error: perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error 16 (Device or resource busy) perf_event_open(..., 0) failed unexpectedly with error 16 (Device or resource busy) The PMU counters are busy/taken by another profiler. We found oprofile daemon running, please stop it and try again. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Namhyung Kim <namhyung@gmail.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: William Cohen <wcohen@redhat.com> Cc: Yann Droneaud <ydroneaud@opteya.com> Link: http://lkml.kernel.org/r/1406908014-8312-1-git-send-email-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/util/cloexec.c4
-rw-r--r--tools/perf/util/evsel.c6
-rw-r--r--tools/perf/util/util.c36
-rw-r--r--tools/perf/util/util.h1
4 files changed, 45 insertions, 2 deletions
diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
index c5d05ec17220..dede0c388ed4 100644
--- a/tools/perf/util/cloexec.c
+++ b/tools/perf/util/cloexec.c
@@ -25,7 +25,7 @@ static int perf_flag_probe(void)
25 return 1; 25 return 1;
26 } 26 }
27 27
28 WARN_ONCE(err != EINVAL, 28 WARN_ONCE(err != EINVAL && err != EBUSY,
29 "perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error %d (%s)\n", 29 "perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error %d (%s)\n",
30 err, strerror(err)); 30 err, strerror(err));
31 31
@@ -33,7 +33,7 @@ static int perf_flag_probe(void)
33 fd = sys_perf_event_open(&attr, 0, -1, -1, 0); 33 fd = sys_perf_event_open(&attr, 0, -1, -1, 0);
34 err = errno; 34 err = errno;
35 35
36 if (WARN_ONCE(fd < 0, 36 if (WARN_ONCE(fd < 0 && err != EBUSY,
37 "perf_event_open(..., 0) failed unexpectedly with error %d (%s)\n", 37 "perf_event_open(..., 0) failed unexpectedly with error %d (%s)\n",
38 err, strerror(err))) 38 err, strerror(err)))
39 return -1; 39 return -1;
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 92e5235f5377..0c8919decac8 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -2039,6 +2039,12 @@ int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
2039 "No APIC? If so then you can boot the kernel with the \"lapic\" boot parameter to force-enable it."); 2039 "No APIC? If so then you can boot the kernel with the \"lapic\" boot parameter to force-enable it.");
2040#endif 2040#endif
2041 break; 2041 break;
2042 case EBUSY:
2043 if (find_process("oprofiled"))
2044 return scnprintf(msg, size,
2045 "The PMU counters are busy/taken by another profiler.\n"
2046 "We found oprofile daemon running, please stop it and try again.");
2047 break;
2042 default: 2048 default:
2043 break; 2049 break;
2044 } 2050 }
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index e52e7461911b..b82a93cb1694 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -536,3 +536,39 @@ void mem_bswap_64(void *src, int byte_size)
536 ++m; 536 ++m;
537 } 537 }
538} 538}
539
540bool find_process(const char *name)
541{
542 size_t len = strlen(name);
543 DIR *dir;
544 struct dirent *d;
545 int ret = -1;
546
547 dir = opendir(procfs__mountpoint());
548 if (!dir)
549 return -1;
550
551 /* Walk through the directory. */
552 while (ret && (d = readdir(dir)) != NULL) {
553 char path[PATH_MAX];
554 char *data;
555 size_t size;
556
557 if ((d->d_type != DT_DIR) ||
558 !strcmp(".", d->d_name) ||
559 !strcmp("..", d->d_name))
560 continue;
561
562 scnprintf(path, sizeof(path), "%s/%s/comm",
563 procfs__mountpoint(), d->d_name);
564
565 if (filename__read_str(path, &data, &size))
566 continue;
567
568 ret = strncmp(name, data, len);
569 free(data);
570 }
571
572 closedir(dir);
573 return ret ? false : true;
574}
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 38af77550c75..03a1ea2266b8 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -346,4 +346,5 @@ void mem_bswap_64(void *src, int byte_size);
346void mem_bswap_32(void *src, int byte_size); 346void mem_bswap_32(void *src, int byte_size);
347 347
348const char *get_filename_for_perf_kvm(void); 348const char *get_filename_for_perf_kvm(void);
349bool find_process(const char *name);
349#endif /* GIT_COMPAT_UTIL_H */ 350#endif /* GIT_COMPAT_UTIL_H */