Skip to contentSkip to conversation

perf top: Use active evsel for non-sample events on old kernel

PATCH New Namhyung Kim 1 participant 3 messages Jan 8, 2012 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 perf top: Use active evsel for non-sample events on old kernel

If multiple events are specified on old kernel, perf_evlist__id2evsel() returns NULL for non-sampling events since the sample.id doesn't contain valid value, and it triggers assert below. If only one event is given, the function returns the evsel regardless of sample.id, this is why most case cause no problem on old kernel.

Fix it by using active evsel.

---
 tools/perf/builtin-top.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
tools/perf/builtin-top.c +8 -0
index d89dec90103e..2c9fa1e48854 100644
@@ -762,6 +762,14 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
 		}
 
 		evsel = perf_evlist__id2evsel(session->evlist, sample.id);
+		if (evsel == NULL && !session->sample_id_all &&
+		    event->header.type != PERF_RECORD_SAMPLE) {
+			/*
+			 * Old kernel, no sample_id_all field.
+			 * Just use active evsel.
+			 */
+			evsel = top->sym_evsel;
+		}
 		assert(evsel != NULL);
 
 		origin = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
Signature · 1 line
1.7.8.2
#1 lore raw

PATCH 2/3 perf record: Add error message for EMFILE

When a user tries to open so many events, perf_event_oen syscall may fail with EMFILE. Provide an advice for that case.

---
 tools/perf/builtin-record.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
tools/perf/builtin-record.c +4 -0
index 0abfb18b911f..d47b8277ca78 100644
@@ -248,6 +248,10 @@ try_again:
 				ui__warning("The %s event is not supported.\n",
 					    event_name(pos));
 				exit(EXIT_FAILURE);
+			} else if (err == EMFILE) {
+				ui__warning("Too many events are opened.\n"
+					    "Try again after reducing the number of events.\n");
+				exit(EXIT_FAILURE);
 			}
 
 			printf("\n");
Signature · 1 line
1.7.8.2
#2 lore raw

PATCH 3/3 perf stat: Add error message for EMFILE

In reply to Namhyung Kim

When a user tries to open so many events, perf_event_oen syscall may fail with EMFILE. Provide an advice for that case.

---
 tools/perf/builtin-stat.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
tools/perf/builtin-stat.c +3 -0
index f5d2a63eba66..3e6c8dd8417f 100644
@@ -477,6 +477,9 @@ static int run_perf_stat(int argc __used, const char **argv)
 				      "\t Consider tweaking"
 				      " /proc/sys/kernel/perf_event_paranoid or running as root.",
 				      system_wide ? "system-wide " : "");
+			} else if (errno == EMFILE) {
+				error("Too many events are opened.\n"
+				      "\t Try again after reducing the number of events.\n");
 			} else {
 				error("open_counter returned with %d (%s). "
 				      "/bin/dmesg may provide additional information.\n",
Signature · 1 line
1.7.8.2