Skip to contentSkip to conversation

perf: improve report/annotation integration in newt browser

GIT PULL New Arnaldo Carvalho de Melo 1 participant 3 messages May 12, 2010 perf events

lore
Share & tools
lore
#0 lore raw

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

Hi Ingo,

Please pull from:

git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux-2.6 perf

Besides these the three on my previous pull request are there as well.

Regards,

- Arnaldo

Arnaldo Carvalho de Melo (2):
perf ui: Add ui_helpline methods
perf report: Librarize the annotation code and use it in the newt browser

 tools/perf/Makefile           |    5 +
 tools/perf/builtin-annotate.c |  198 +-------------------
 tools/perf/builtin-report.c   |   19 ++-
 tools/perf/util/hist.c        |  184 ++++++++++++++++++
 tools/perf/util/hist.h        |   29 +++
 tools/perf/util/newt.c        |  421 ++++++++++++++++++++++++++++++++++-------
 tools/perf/util/sort.h        |    6 -
 7 files changed, 594 insertions(+), 268 deletions(-)
#1 lore raw

PATCH 1/2 perf ui: Add ui_helpline methods

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

Initially this was just to be able to have a printf like method to prepare the formatted string and then pass to newtPushHelpLine, but as we already have for ui_progress, etc, its a step in identifying a restricted, highlevel set of widgets we can then have implementations for multiple widget sets (GTK, etc).

Cc: Frédéric Weisbecker <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Tom Zanussi <[email protected]>
LKML-Reference: <new-submission>

---
 tools/perf/util/newt.c |   69 ++++++++++++++++++++++++++++++++++-------------
 1 files changed, 50 insertions(+), 19 deletions(-)
tools/perf/util/newt.c +50 -19
index 638b519..daa86ef 100644
@@ -57,6 +57,43 @@ void ui_progress__delete(struct ui_progress *self)
 	free(self);
 }
 
+static void ui_helpline__pop(void)
+{
+	newtPopHelpLine();
+}
+
+static void ui_helpline__push(const char *msg)
+{
+	newtPushHelpLine(msg);
+}
+
+static void ui_helpline__vpush(const char *fmt, va_list ap)
+{
+	char *s;
+
+	if (vasprintf(&s, fmt, ap) < 0)
+		vfprintf(stderr, fmt, ap);
+	else {
+		ui_helpline__push(s);
+		free(s);
+	}
+}
+
+static void ui_helpline__fpush(const char *fmt, ...)
+{
+	va_list ap;
+
+	va_start(ap, fmt);
+	ui_helpline__vpush(fmt, ap);
+	va_end(ap);
+}
+
+static void ui_helpline__puts(const char *msg)
+{
+	ui_helpline__pop();
+	ui_helpline__push(msg);
+}
+
 static char browser__last_msg[1024];
 
 int browser__show_help(const char *format, va_list ap)
@@ -69,8 +106,7 @@ int browser__show_help(const char *format, va_list ap)
 	backlog += ret;
 
 	if (browser__last_msg[backlog - 1] == '\n') {
-		newtPopHelpLine();
-		newtPushHelpLine(browser__last_msg);
+		ui_helpline__puts(browser__last_msg);
 		newtRefresh();
 		backlog = 0;
 	}
@@ -340,7 +376,7 @@ static void map_symbol__annotate_browser(const struct map_symbol *self,
 	if (fp == NULL)
 		goto out_free_str;
 
-	newtPushHelpLine("Press ESC to exit");
+	ui_helpline__push("Press ESC to exit");
 	newtGetScreenSize(&cols, &rows);
 	tree = newtListbox(0, 0, rows - 5, NEWT_FLAG_SCROLL);
 
@@ -370,7 +406,7 @@ static void map_symbol__annotate_browser(const struct map_symbol *self,
 	newtFormRun(form, &es);
 	newtFormDestroy(form);
 	newtPopWindow();
-	newtPopHelpLine();
+	ui_helpline__pop();
 out_free_str:
 	free(str);
 }
@@ -539,7 +575,7 @@ int hists__browse(struct hists *self, const char *helpline, const char *input_na
 	if (browser == NULL)
 		return -1;
 
-	newtPushHelpLine(helpline);
+	ui_helpline__push(helpline);
 
 	hist_browser__title(msg, sizeof(msg), input_name,
 			    dso_filter, thread_filter);
@@ -602,8 +638,7 @@ int hists__browse(struct hists *self, const char *helpline, const char *input_na
 do_annotate:
 		if (choice == annotate) {
 			if (browser->selection->map->dso->origin == DSO__ORIG_KERNEL) {
-				newtPopHelpLine();
-				newtPushHelpLine("No vmlinux file found, can't "
+				ui_helpline__puts("No vmlinux file found, can't "
 						 "annotate with just a "
 						 "kallsyms file");
 				continue;
@@ -611,13 +646,11 @@ do_annotate:
 			map_symbol__annotate_browser(browser->selection, input_name);
 		} else if (choice == zoom_dso) {
 			if (dso_filter) {
-				newtPopHelpLine();
+				ui_helpline__pop();
 				dso_filter = NULL;
 			} else {
-				snprintf(msg, sizeof(msg),
-					 "To zoom out press -> + \"Zoom out of %s DSO\"",
-					 dso->kernel ? "the Kernel" : dso->short_name);
-				newtPushHelpLine(msg);
+				ui_helpline__fpush("To zoom out press -> + \"Zoom out of %s DSO\"",
+						   dso->kernel ? "the Kernel" : dso->short_name);
 				dso_filter = dso;
 			}
 			hists__filter_by_dso(self, dso_filter);
@@ -627,14 +660,12 @@ do_annotate:
 				goto out;
 		} else if (choice == zoom_thread) {
 			if (thread_filter) {
-				newtPopHelpLine();
+				ui_helpline__pop();
 				thread_filter = NULL;
 			} else {
-				snprintf(msg, sizeof(msg),
-					 "To zoom out press -> + \"Zoom out of %s(%d) thread\"",
-					 (thread->comm_set ? thread->comm : ""),
-					 thread->pid);
-				newtPushHelpLine(msg);
+				ui_helpline__fpush("To zoom out press -> + \"Zoom out of %s(%d) thread\"",
+						   thread->comm_set ? thread->comm : "",
+						   thread->pid);
 				thread_filter = thread;
 			}
 			hists__filter_by_thread(self, thread_filter);
@@ -658,7 +689,7 @@ void setup_browser(void)
 	use_browser = true;
 	newtInit();
 	newtCls();
-	newtPushHelpLine(" ");
+	ui_helpline__puts(" ");
 }
 
 void exit_browser(bool wait_for_ok)
Signature · 1 line
1.6.2.5
#2 lore raw

PATCH 2/2 perf report: Librarize the annotation code and use it in the newt browser

In reply to Arnaldo Carvalho de Melo

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

Now we don't anymore use popen to run 'perf annotate' for the selected symbol, instead we collect per address samplings when processing samples in 'perf report' if we're using the newt browser, then we use this data directly to do annotation.

Done this way we can actually traverse the objdump_line objects directly, matching the addresses to the collected samples and colouring them appropriately using lower level slang routines.

The new ui_browser class will be reused for the main, callchain aware, histogram browser, when it will be made generic and don't assume that the objects are always instances of the objdump_line class maintained using list_heads.

Cc: Frédéric Weisbecker <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Tom Zanussi <[email protected]>
LKML-Reference: <new-submission>

---
 tools/perf/Makefile           |    5 +
 tools/perf/builtin-annotate.c |  198 +-----------------------
 tools/perf/builtin-report.c   |   19 ++-
 tools/perf/util/hist.c        |  184 +++++++++++++++++++++
 tools/perf/util/hist.h        |   29 ++++
 tools/perf/util/newt.c        |  352 +++++++++++++++++++++++++++++++++++------
 tools/perf/util/sort.h        |    6 -
 7 files changed, 544 insertions(+), 249 deletions(-)
tools/perf/Makefile +5 -0
index 0797786..9c4dc30 100644
@@ -560,6 +560,8 @@ ifneq ($(shell sh -c "(echo '\#include <newt.h>'; echo 'int main(void) { newtIni
 	msg := $(warning newt not found, disables TUI support. Please install newt-devel or libnewt-dev);
 	BASIC_CFLAGS += -DNO_NEWT_SUPPORT
 else
+	# Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
+	BASIC_CFLAGS += -I/usr/include/slang
 	EXTLIBS += -lnewt
 	LIB_OBJS += $(OUTPUT)util/newt.o
 endif
@@ -948,6 +950,9 @@ $(OUTPUT)builtin-init-db.o: builtin-init-db.c $(OUTPUT)PERF-CFLAGS
 $(OUTPUT)util/config.o: util/config.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
 
+$(OUTPUT)util/newt.o: util/newt.c $(OUTPUT)PERF-CFLAGS
+	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $<
+
 $(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
 
tools/perf/builtin-annotate.c +2 -196

234 lines not on this page · raw message

tools/perf/builtin-report.c +18 -1
index 3d67d6b..04de338 100644
@@ -106,8 +106,18 @@ static int perf_session__add_hist_entry(struct perf_session *self,
 	if (he == NULL)
 		goto out_free_syms;
 	err = 0;
-	if (symbol_conf.use_callchain)
+	if (symbol_conf.use_callchain) {
 		err = append_chain(he->callchain, data->callchain, syms);
+		if (err)
+			goto out_free_syms;
+	}
+	/*
+	 * Only in the newt browser we are doing integrated annotation,
+	 * so we don't allocated the extra space needed because the stdio
+	 * code will not use it.
+	 */
+	if (use_browser)
+		err = hist_entry__inc_addr_samples(he, al->addr);
 out_free_syms:
 	free(syms);
 	return err;
@@ -458,6 +468,13 @@ int cmd_report(int argc, const char **argv, const char *prefix __used)
 
 	if (strcmp(input_name, "-") != 0)
 		setup_browser();
+	/*
+	 * Only in the newt browser we are doing integrated annotation,
+	 * so don't allocate extra space that won't be used in the stdio
+	 * implementation.
+	 */
+	if (use_browser)
+		symbol_conf.priv_size = sizeof(struct sym_priv);
 
 	if (symbol__init() < 0)
 		return -1;
tools/perf/util/hist.c +184 -0

187 lines not on this page · raw message

tools/perf/util/hist.h +29 -0
index 1c5f93a..ed9c067 100644
@@ -11,6 +11,32 @@ struct addr_location;
 struct symbol;
 struct rb_root;
 
+struct objdump_line {
+	struct list_head node;
+	s64		 offset;
+	char		 *line;
+};
+
+void objdump_line__free(struct objdump_line *self);
+struct objdump_line *objdump__get_next_ip_line(struct list_head *head,
+					       struct objdump_line *pos);
+
+struct sym_hist {
+	u64		sum;
+	u64		ip[0];
+};
+
+struct sym_ext {
+	struct rb_node	node;
+	double		percent;
+	char		*path;
+};
+
+struct sym_priv {
+	struct sym_hist	*hist;
+	struct sym_ext	*ext;
+};
+
 struct events_stats {
 	u64 total;
 	u64 lost;
@@ -45,6 +71,9 @@ void hists__collapse_resort(struct hists *self);
 size_t hists__fprintf(struct hists *self, struct hists *pair,
 		      bool show_displacement, FILE *fp);
 
+int hist_entry__inc_addr_samples(struct hist_entry *self, u64 ip);
+int hist_entry__annotate(struct hist_entry *self, struct list_head *head);
+
 void hists__filter_by_dso(struct hists *self, const struct dso *dso);
 void hists__filter_by_thread(struct hists *self, const struct thread *thread);
 
tools/perf/util/newt.c +306 -46

421 lines not on this page · raw message

tools/perf/util/sort.h +0 -6
index b7c54ee..af301ac 100644
@@ -48,12 +48,6 @@ struct hist_entry {
 	u64			count_us;
 	u64			count_guest_sys;
 	u64			count_guest_us;
-
-	/*
-	 * XXX WARNING!
-	 * thread _has_ to come after ms, see
-	 * hist_browser__selected_thread in util/newt.c
-	 */
 	struct map_symbol	ms;
 	struct thread		*thread;
 	u64			ip;
Signature · 1 line
1.6.2.5