Skip to contentSkip to conversation

perf/core fixes and improvements

GIT PULL New Arnaldo Carvalho de Melo 2 participants 5 messages Oct 29, 2011 – Oct 30, 2011 perf events

lore
Share & tools
lore
#3 lore raw

PATCH 3/3 perf report: Add progress bar when processing time ordered events

In reply to Arnaldo Carvalho de Melo

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

So that for large perf.data files the user can have visual feedback that activity is being performed.

Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/session.c |    9 +++++++++
 tools/perf/util/session.h |    1 +
 2 files changed, 10 insertions(+), 0 deletions(-)
tools/perf/util/session.c +9 -0
index da354fe..85c1e6b 100644
@@ -502,6 +502,7 @@ static void flush_sample_queue(struct perf_session *s,
 	struct perf_sample sample;
 	u64 limit = os->next_flush;
 	u64 last_ts = os->last_sample ? os->last_sample->timestamp : 0ULL;
+	unsigned idx = 0, progress_next = os->nr_samples / 16;
 	int ret;
 
 	if (!ops->ordered_samples || !limit)
@@ -521,6 +522,11 @@ static void flush_sample_queue(struct perf_session *s,
 		os->last_flush = iter->timestamp;
 		list_del(&iter->list);
 		list_add(&iter->list, &os->sample_cache);
+		if (++idx >= progress_next) {
+			progress_next += os->nr_samples / 16;
+			ui_progress__update(idx, os->nr_samples,
+					    "Processing time ordered events...");
+		}
 	}
 
 	if (list_empty(head)) {
@@ -529,6 +535,8 @@ static void flush_sample_queue(struct perf_session *s,
 		os->last_sample =
 			list_entry(head->prev, struct sample_queue, list);
 	}
+
+	os->nr_samples = 0;
 }
 
 /*
@@ -588,6 +596,7 @@ static void __queue_event(struct sample_queue *new, struct perf_session *s)
 	u64 timestamp = new->timestamp;
 	struct list_head *p;
 
+	++os->nr_samples;
 	os->last_sample = new;
 
 	if (!sample) {
tools/perf/util/session.h +1 -0
index 514b06d..6e393c9 100644
@@ -23,6 +23,7 @@ struct ordered_samples {
 	struct sample_queue	*sample_buffer;
 	struct sample_queue	*last_sample;
 	int			sample_buffer_idx;
+	unsigned int		nr_samples;
 };
 
 struct perf_session {
Signature · 1 line
1.6.2.5
#0 lore raw

Hi Ingo,

Please consider pulling from:

git://github.com/acmel/linux.git perf/core

Regards,

- Arnaldo

Arnaldo Carvalho de Melo (2):
perf hists browser: Warn about lost events
perf report: Add progress bar when processing time ordered events

Masami Hiramatsu (1):
perf tools: Fix a typo of command name as trace-cmd

 tools/perf/builtin-top.c            |   41 +++++++++++++++++++++--------
 tools/perf/util/hist.h              |    1 +
 tools/perf/util/session.c           |   38 ++++++++++++++++++++++----
 tools/perf/util/session.h           |    1 +
 tools/perf/util/top.h               |    1 -
 tools/perf/util/trace-event-info.c  |    2 +-
 tools/perf/util/ui/browser.c        |   21 ++++++++++++---
 tools/perf/util/ui/browser.h        |    3 +-
 tools/perf/util/ui/browsers/hists.c |   49 ++++++++++++++++++++++++++++++----
 9 files changed, 127 insertions(+), 30 deletions(-)
#1 lore raw

PATCH 1/3 perf tools: Fix a typo of command name as trace-cmd

From: Masami Hiramatsu <[email protected]>

Fix a typo which may be introduced when original code has been copied from trace-cmd.

---
 tools/perf/util/trace-event-info.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/util/trace-event-info.c +1 -1
index 2d530cf..d2655f0 100644
@@ -80,7 +80,7 @@ static void die(const char *fmt, ...)
 	int ret = errno;
 
 	if (errno)
-		perror("trace-cmd");
+		perror("perf");
 	else
 		ret = -1;
 
Signature · 1 line
1.6.2.5
#2 lore raw

PATCH 2/3 perf hists browser: Warn about lost events

In reply to Arnaldo Carvalho de Melo

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

Just like the old perf top --tui and the --stdio version.

But because we have the initial menu to choose which event to show in a session with multiple events we can see how many chunks were lost in each of the event types, clarifying which events are being affected the most.

Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/builtin-top.c            |   41 +++++++++++++++++++++--------
 tools/perf/util/hist.h              |    1 +
 tools/perf/util/session.c           |   29 ++++++++++++++++----
 tools/perf/util/top.h               |    1 -
 tools/perf/util/ui/browser.c        |   21 ++++++++++++---
 tools/perf/util/ui/browser.h        |    3 +-
 tools/perf/util/ui/browsers/hists.c |   49 ++++++++++++++++++++++++++++++----
 7 files changed, 116 insertions(+), 29 deletions(-)
tools/perf/builtin-top.c +30 -11
index 31aa82c..c8d31d9 100644
@@ -89,6 +89,7 @@ static bool			vmlinux_warned;
 static bool			inherit				=  false;
 static int			realtime_prio			=      0;
 static bool			group				=  false;
+static bool			sample_id_all_avail		=   true;
 static unsigned int		mmap_pages			=    128;
 
 static bool			dump_symtab                     =  false;
@@ -289,11 +290,13 @@ static void print_sym_table(void)
 
 	printf("%-*.*s\n", win_width, win_width, graph_dotted_line);
 
-	if (top.total_lost_warned != top.session->hists.stats.total_lost) {
-		top.total_lost_warned = top.session->hists.stats.total_lost;
-		color_fprintf(stdout, PERF_COLOR_RED, "WARNING:");
-		printf(" LOST %" PRIu64 " events, Check IO/CPU overload\n",
-		       top.total_lost_warned);
+	if (top.sym_evsel->hists.stats.nr_lost_warned !=
+	    top.sym_evsel->hists.stats.nr_events[PERF_RECORD_LOST]) {
+		top.sym_evsel->hists.stats.nr_lost_warned =
+			top.sym_evsel->hists.stats.nr_events[PERF_RECORD_LOST];
+		color_fprintf(stdout, PERF_COLOR_RED,
+			      "WARNING: LOST %d chunks, Check IO/CPU overload",
+			      top.sym_evsel->hists.stats.nr_lost_warned);
 		++printed;
 	}
 
@@ -671,6 +674,7 @@ static int symbol_filter(struct map *map __used, struct symbol *sym)
 }
 
 static void perf_event__process_sample(const union perf_event *event,
+				       struct perf_evsel *evsel,
 				       struct perf_sample *sample,
 				       struct perf_session *session)
 {
@@ -770,12 +774,8 @@ static void perf_event__process_sample(const union perf_event *event,
 	}
 
 	if (al.sym == NULL || !al.sym->ignore) {
-		struct perf_evsel *evsel;
 		struct hist_entry *he;
 
-		evsel = perf_evlist__id2evsel(top.evlist, sample->id);
-		assert(evsel != NULL);
-
 		if ((sort__has_parent || symbol_conf.use_callchain) &&
 		    sample->callchain) {
 			err = perf_session__resolve_callchain(session, al.thread,
@@ -807,10 +807,13 @@ static void perf_event__process_sample(const union perf_event *event,
 static void perf_session__mmap_read_idx(struct perf_session *self, int idx)
 {
 	struct perf_sample sample;
+	struct perf_evsel *evsel;
 	union perf_event *event;
 	int ret;
 
 	while ((event = perf_evlist__mmap_read(top.evlist, idx)) != NULL) {
+		u64 id;
+
 		ret = perf_session__parse_sample(self, event, &sample);
 		if (ret) {
 			pr_err("Can't parse sample, err = %d\n", ret);
@@ -818,9 +821,17 @@ static void perf_session__mmap_read_idx(struct perf_session *self, int idx)
 		}
 
 		if (event->header.type == PERF_RECORD_SAMPLE)
-			perf_event__process_sample(event, &sample, self);
-		else
+			id = sample.id;
+		evsel = perf_evlist__id2evsel(self->evlist, sample.id);
+		assert(evsel != NULL);
+
+		if (event->header.type == PERF_RECORD_SAMPLE)
+			perf_event__process_sample(event, evsel, &sample, self);
+		else if (event->header.type < PERF_RECORD_MAX) {
+			hists__inc_nr_events(&evsel->hists, event->header.type);
 			perf_event__process(event, &sample, self);
+		} else
+			++self->hists.stats.nr_unknown_events;
 	}
 }
 
@@ -864,6 +875,8 @@ static void start_counters(struct perf_evlist *evlist)
 		attr->mmap = 1;
 		attr->comm = 1;
 		attr->inherit = inherit;
+retry_sample_id:
+		attr->sample_id_all = sample_id_all_avail ? 1 : 0;
 try_again:
 		if (perf_evsel__open(counter, top.evlist->cpus,
 				     top.evlist->threads, group,
@@ -873,6 +886,12 @@ try_again:
 			if (err == EPERM || err == EACCES) {
 				ui__error_paranoid();
 				goto out_err;
+			} else if (err == EINVAL && sample_id_all_avail) {
+				/*
+				 * Old kernel, no attr->sample_id_type_all field
+				 */
+				sample_id_all_avail = false;
+				goto retry_sample_id;
 			}
 			/*
 			 * If it's cycles then fall back to hrtimer
tools/perf/util/hist.h +1 -0
index ff93ddc..c86c1d2 100644
@@ -28,6 +28,7 @@ struct events_stats {
 	u64 total_lost;
 	u64 total_invalid_chains;
 	u32 nr_events[PERF_RECORD_HEADER_MAX];
+	u32 nr_lost_warned;
 	u32 nr_unknown_events;
 	u32 nr_invalid_chains;
 	u32 nr_unknown_id;
tools/perf/util/session.c +23 -6
index 91c6442..da354fe 100644
@@ -738,10 +738,27 @@ static int perf_session_deliver_event(struct perf_session *session,
 
 	dump_event(session, event, file_offset, sample);
 
+	evsel = perf_evlist__id2evsel(session->evlist, sample->id);
+	if (evsel != NULL && event->header.type != PERF_RECORD_SAMPLE) {
+		/*
+		 * XXX We're leaving PERF_RECORD_SAMPLE unnacounted here
+		 * because the tools right now may apply filters, discarding
+		 * some of the samples. For consistency, in the future we
+		 * should have something like nr_filtered_samples and remove
+		 * the sample->period from total_sample_period, etc, KISS for
+		 * now tho.
+		 *
+		 * Also testing against NULL allows us to handle files without
+		 * attr.sample_id_all and/or without PERF_SAMPLE_ID. In the
+		 * future probably it'll be a good idea to restrict event
+		 * processing via perf_session to files with both set.
+		 */
+		hists__inc_nr_events(&evsel->hists, event->header.type);
+	}
+
 	switch (event->header.type) {
 	case PERF_RECORD_SAMPLE:
 		dump_sample(session, event, sample);
-		evsel = perf_evlist__id2evsel(session->evlist, sample->id);
 		if (evsel == NULL) {
 			++session->hists.stats.nr_unknown_id;
 			return -1;
@@ -874,11 +891,11 @@ static void perf_session__warn_about_errors(const struct perf_session *session,
 					    const struct perf_event_ops *ops)
 {
 	if (ops->lost == perf_event__process_lost &&
-	    session->hists.stats.total_lost != 0) {
-		ui__warning("Processed %" PRIu64 " events and LOST %" PRIu64
-			    "!\n\nCheck IO/CPU overload!\n\n",
-			    session->hists.stats.total_period,
-			    session->hists.stats.total_lost);
+	    session->hists.stats.nr_events[PERF_RECORD_LOST] != 0) {
+		ui__warning("Processed %d events and lost %d chunks!\n\n"
+			    "Check IO/CPU overload!\n\n",
+			    session->hists.stats.nr_events[0],
+			    session->hists.stats.nr_events[PERF_RECORD_LOST]);
 	}
 
 	if (session->hists.stats.nr_unknown_events != 0) {
tools/perf/util/top.h +0 -1
index 01d1057..3996509 100644
@@ -19,7 +19,6 @@ struct perf_top {
 	u64		   kernel_samples, us_samples;
 	u64		   exact_samples;
 	u64		   guest_us_samples, guest_kernel_samples;
-	u64		   total_lost_warned;
 	int		   print_entries, count_filter, delay_secs;
 	int		   freq;
 	pid_t		   target_pid, target_tid;
tools/perf/util/ui/browser.c +17 -4
index d2051be..5568291 100644
@@ -176,16 +176,29 @@ void ui_browser__handle_resize(struct ui_browser *browser)
 	ui_browser__refresh(browser);
 }
 
-int ui_browser__warning(struct ui_browser *browser, const char *format, ...)
+int ui_browser__warning(struct ui_browser *browser, int timeout,
+			const char *format, ...)
 {
 	va_list args;
-	int key;
+	char *text;
+	int key = 0, err;
 
 	va_start(args, format);
-	while ((key = __ui__warning("Warning!", format, args)) == K_RESIZE)
-		ui_browser__handle_resize(browser);
+	err = vasprintf(&text, format, args);
 	va_end(args);
 
+	if (err < 0) {
+		va_start(args, format);
+		ui_helpline__vpush(format, args);
+		va_end(args);
+	} else {
+		while ((key == ui__question_window("Warning!", text,
+						   "Press any key...",
+						   timeout)) == K_RESIZE)
+			ui_browser__handle_resize(browser);
+		free(text);
+	}
+
 	return key;
 }
 
tools/perf/util/ui/browser.h +2 -1
index fb1c598..84d761b 100644
@@ -45,7 +45,8 @@ int ui_browser__run(struct ui_browser *browser, int delay_secs);
 void ui_browser__update_nr_entries(struct ui_browser *browser, u32 nr_entries);
 void ui_browser__handle_resize(struct ui_browser *browser);
 
-int ui_browser__warning(struct ui_browser *browser, const char *format, ...);
+int ui_browser__warning(struct ui_browser *browser, int timeout,
+			const char *format, ...);
 int ui_browser__help_window(struct ui_browser *browser, const char *text);
 bool ui_browser__dialog_yesno(struct ui_browser *browser, const char *text);
 
tools/perf/util/ui/browsers/hists.c +43 -6

90 lines not on this page · raw message

Signature · 1 line
1.6.2.5
#4 lore raw
In reply to Arnaldo Carvalho de Melo
Quoted 17 lines · Arnaldo Carvalho de Melo

Hi Ingo,

Please consider pulling from:

git://github.com/acmel/linux.git perf/core

Regards,

- Arnaldo

Arnaldo Carvalho de Melo (2):
perf hists browser: Warn about lost events
perf report: Add progress bar when processing time ordered events

Masami Hiramatsu (1):
perf tools: Fix a typo of command name as trace-cmd

Quoted 10 lines
 tools/perf/builtin-top.c            |   41 +++++++++++++++++++++--------
 tools/perf/util/hist.h              |    1 +
 tools/perf/util/session.c           |   38 ++++++++++++++++++++++----
 tools/perf/util/session.h           |    1 +
 tools/perf/util/top.h               |    1 -
 tools/perf/util/trace-event-info.c  |    2 +-
 tools/perf/util/ui/browser.c        |   21 ++++++++++++---
 tools/perf/util/ui/browser.h        |    3 +-
 tools/perf/util/ui/browsers/hists.c |   49 ++++++++++++++++++++++++++++++----
 9 files changed, 127 insertions(+), 30 deletions(-)

Pulled, thanks a lot Arnaldo!

Ingo