Skip to contentSkip to conversation

perf improvements and fixes

GIT PULL New Arnaldo Carvalho de Melo 2 participants 6 messages May 10, 2010 perf events

lore
Share & tools
lore
#0 lore raw

Hi Ingo,

Please pull from:

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

The 3rd is important as it fixes a recently introduced bug (yesterday,
I believe), that makes perf record segfault.

Regards,

Arnaldo Carvalho de Melo (4):
perf newt: Use newtAddComponent()
perf callchains: Use zalloc to allocate objects
perf session: create_kernel_maps should use ->host_machine perf hist: Introduce hists class and move lots of methods to it

 tools/perf/builtin-annotate.c |   17 ++++----
 tools/perf/builtin-diff.c     |   50 ++++++++++------------
 tools/perf/builtin-report.c   |   71 +++++++++++++++----------------
 tools/perf/builtin-trace.c    |    2 +-
 tools/perf/util/callchain.c   |    6 +-
 tools/perf/util/event.c       |    2 +-
 tools/perf/util/event.h       |   14 ------
 tools/perf/util/hist.c        |   92 ++++++++++++++++++----------------------
 tools/perf/util/hist.h        |   48 ++++++++++++---------
 tools/perf/util/newt.c        |    6 +-
 tools/perf/util/session.c     |    7 +--
 tools/perf/util/session.h     |   12 ++++-
 12 files changed, 154 insertions(+), 173 deletions(-)
#1 lore raw

PATCH 1/4 perf newt: Use newtAddComponent()

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

Instead of newtAddComponents(just-one-entry, NULL), that is not needed if, like in this browser, we're adding just one component at a time.

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 |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
tools/perf/util/newt.c +3 -3
index 7a123a9..e283a6e 100644
@@ -31,7 +31,7 @@ struct ui_progress *ui_progress__new(const char *title, u64 total)
 		self->scale = newtScale(0, 0, cols, total);
 		if (self->scale == NULL)
 			goto out_free_form;
-		newtFormAddComponents(self->form, self->scale, NULL);
+		newtFormAddComponent(self->form, self->scale);
 		newtRefresh();
 	}
 
@@ -107,7 +107,7 @@ static int popup_menu(int argc, char * const argv[])
 	if (listbox == NULL)
 		goto out_destroy_form;
 
-	newtFormAddComponents(form, listbox, NULL);
+	newtFormAddComponent(form, listbox);
 
 	for (i = 0; i < argc; ++i) {
 		int len = strlen(argv[i]);
@@ -365,7 +365,7 @@ static void map_symbol__annotate_browser(const struct map_symbol *self,
 
 	newtCenteredWindow(max_line_len + 2, rows - 5, self->sym->name);
 	form = newt_form__new();
-	newtFormAddComponents(form, tree, NULL);
+	newtFormAddComponent(form, tree);
 
 	newtFormRun(form, &es);
 	newtFormDestroy(form);
Signature · 1 line
1.6.2.5
#2 lore raw

PATCH 2/4 perf callchains: Use zalloc to allocate objects

In reply to Arnaldo Carvalho de Melo

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

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/callchain.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
tools/perf/util/callchain.c +3 -3
index ac14861..21a52e0 100644
@@ -167,7 +167,7 @@ create_child(struct callchain_node *parent, bool inherit_children)
 {
 	struct callchain_node *new;
 
-	new = malloc(sizeof(*new));
+	new = zalloc(sizeof(*new));
 	if (!new) {
 		perror("not enough memory to create child for code path tree");
 		return NULL;
@@ -213,7 +213,7 @@ fill_node(struct callchain_node *node, struct resolved_chain *chain, int start)
 	for (i = start; i < chain->nr; i++) {
 		struct callchain_list *call;
 
-		call = malloc(sizeof(*call));
+		call = zalloc(sizeof(*call));
 		if (!call) {
 			perror("not enough memory for the code path tree");
 			return;
@@ -386,7 +386,7 @@ int append_chain(struct callchain_node *root, struct ip_callchain *chain,
 	if (!chain->nr)
 		return 0;
 
-	filtered = malloc(sizeof(*filtered) +
+	filtered = zalloc(sizeof(*filtered) +
 			  chain->nr * sizeof(struct resolved_ip));
 	if (!filtered)
 		return -ENOMEM;
Signature · 1 line
1.6.2.5
#3 lore raw

PATCH 3/4 perf session: create_kernel_maps should use ->host_machine

In reply to Arnaldo Carvalho de Melo

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

Using machines__create_kernel_maps(..., HOST_KERNEL_ID) it would create another machine instance for the host machine, and since 1f626bc we have it out of the machines rb_tree.

Fix it by using machine__create_kernel_maps(&self->host_machine) directly.

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/session.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
tools/perf/util/session.c +2 -3
index c088d8f..4130036 100644
@@ -69,11 +69,10 @@ void perf_session__update_sample_type(struct perf_session *self)
 
 int perf_session__create_kernel_maps(struct perf_session *self)
 {
-	struct rb_root *machines = &self->machines;
-	int ret = machines__create_kernel_maps(machines, HOST_KERNEL_ID);
+	int ret = machine__create_kernel_maps(&self->host_machine);
 
 	if (ret >= 0)
-		ret = machines__create_guest_kernel_maps(machines);
+		ret = machines__create_guest_kernel_maps(&self->machines);
 	return ret;
 }
 
Signature · 1 line
1.6.2.5
#4 lore raw

PATCH 4/4 perf hist: Introduce hists class and move lots of methods to it

In reply to Arnaldo Carvalho de Melo

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

In cbbc79a we introduced support for multiple events by introducing a new "event_stat_id" struct and then made several perf_session methods receive a point to it instead of a pointer to perf_session, and kept the event_stats and hists rb_tree in perf_session.

While working on the new newt based browser, I realised that it would be better to introduce a new class, "hists" (short for "histograms"), renaming the "event_stat_id" struct and the perf_session methods that were really "hists" methods, as they manipulate only struct hists members, not touching anything in the other perf_session members.

Other optimizations, such as calculating the maximum lenght of a symbol name present in an hists instance will be possible as we add them, avoiding a re-traversal just for finding that information.

The rationale for the name "hists" to replace "event_stat_id" is that we may have multiple sets of hists for the same event_stat id, as, for instance, the 'perf diff' tool has, so event stat id is not what characterizes what this struct and the functions that manipulate it do.

Cc: Eric B Munson <[email protected]>
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/builtin-annotate.c |   17 ++++----
 tools/perf/builtin-diff.c     |   50 ++++++++++------------
 tools/perf/builtin-report.c   |   71 +++++++++++++++----------------
 tools/perf/builtin-trace.c    |    2 +-
 tools/perf/util/event.c       |    2 +-
 tools/perf/util/event.h       |   14 ------
 tools/perf/util/hist.c        |   92 ++++++++++++++++++----------------------
 tools/perf/util/hist.h        |   48 ++++++++++++---------
 tools/perf/util/session.c     |    2 +-
 tools/perf/util/session.h     |   12 ++++-
 10 files changed, 146 insertions(+), 164 deletions(-)
tools/perf/builtin-annotate.c +8 -9
index c7ac45a..3940964 100644
@@ -96,8 +96,7 @@ static int annotate__hist_hit(struct hist_entry *he, u64 ip)
 	return 0;
 }
 
-static int perf_session__add_hist_entry(struct perf_session *self,
-					struct addr_location *al)
+static int hists__add_entry(struct hists *self, struct addr_location *al)
 {
 	struct hist_entry *he;
 
@@ -112,7 +111,7 @@ static int perf_session__add_hist_entry(struct perf_session *self,
 		return 0;
 	}
 
-	he = __perf_session__add_hist_entry(&self->hists, al, NULL, 1);
+	he = __hists__add_entry(self, al, NULL, 1);
 	if (he == NULL)
 		return -ENOMEM;
 
@@ -132,7 +131,7 @@ static int process_sample_event(event_t *event, struct perf_session *session)
 		return -1;
 	}
 
-	if (!al.filtered && perf_session__add_hist_entry(session, &al)) {
+	if (!al.filtered && hists__add_entry(&session->hists, &al)) {
 		pr_warning("problem incrementing symbol count, "
 			   "skipping event\n");
 		return -1;
@@ -514,11 +513,11 @@ static void annotate_sym(struct hist_entry *he)
 		free_source_line(he, len);
 }
 
-static void perf_session__find_annotations(struct perf_session *self)
+static void hists__find_annotations(struct hists *self)
 {
 	struct rb_node *nd;
 
-	for (nd = rb_first(&self->hists); nd; nd = rb_next(nd)) {
+	for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) {
 		struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);
 		struct sym_priv *priv;
 
@@ -570,9 +569,9 @@ static int __cmd_annotate(void)
 	if (verbose > 2)
 		perf_session__fprintf_dsos(session, stdout);
 
-	perf_session__collapse_resort(&session->hists);
-	perf_session__output_resort(&session->hists, session->event_total[0]);
-	perf_session__find_annotations(session);
+	hists__collapse_resort(&session->hists);
+	hists__output_resort(&session->hists);
+	hists__find_annotations(&session->hists);
 out_delete:
 	perf_session__delete(session);
 
tools/perf/builtin-diff.c +23 -27

109 lines not on this page · raw message

tools/perf/builtin-report.c +35 -36

139 lines not on this page · raw message

tools/perf/builtin-trace.c +1 -1
index 9c483e9..6e268ca 100644
@@ -107,7 +107,7 @@ static int process_sample_event(event_t *event, struct perf_session *session)
 					     data.time, thread->comm);
 	}
 
-	session->events_stats.total += data.period;
+	session->hists.stats.total += data.period;
 	return 0;
 }
 
tools/perf/util/event.c +1 -1
index d2ea9dd..cce006e 100644
@@ -368,7 +368,7 @@ int event__process_comm(event_t *self, struct perf_session *session)
 int event__process_lost(event_t *self, struct perf_session *session)
 {
 	dump_printf(": id:%Ld: lost:%Ld\n", self->lost.id, self->lost.lost);
-	session->events_stats.lost += self->lost.lost;
+	session->hists.stats.lost += self->lost.lost;
 	return 0;
 }
 
tools/perf/util/event.h +0 -14
index 6cc1b1d..48c2cc9 100644
@@ -131,20 +131,6 @@ typedef union event_union {
 	struct build_id_event		build_id;
 } event_t;
 
-struct events_stats {
-	u64 total;
-	u64 lost;
-};
-
-struct event_stat_id {
-	struct rb_node		rb_node;
-	struct rb_root		hists;
-	struct events_stats	stats;
-	u64			config;
-	u64			event_stream;
-	u32			type;
-};
-
 void event__print_totals(void);
 
 struct perf_session;
tools/perf/util/hist.c +41 -51

220 lines not on this page · raw message

tools/perf/util/hist.h +27 -21

61 lines not on this page · raw message

tools/perf/util/session.c +1 -1
index 4130036..72a7f6a 100644
@@ -89,7 +89,7 @@ struct perf_session *perf_session__new(const char *filename, int mode, bool forc
 
 	memcpy(self->filename, filename, len);
 	self->threads = RB_ROOT;
-	self->stats_by_id = RB_ROOT;
+	self->hists_tree = RB_ROOT;
 	self->last_match = NULL;
 	self->mmap_window = 32;
 	self->cwd = NULL;
tools/perf/util/session.h +9 -3
index 242d528..46190f9 100644
@@ -1,6 +1,7 @@
 #ifndef __PERF_SESSION_H
 #define __PERF_SESSION_H
 
+#include "hist.h"
 #include "event.h"
 #include "header.h"
 #include "symbol.h"
@@ -28,11 +29,16 @@ struct perf_session {
 	struct thread		*last_match;
 	struct machine		host_machine;
 	struct rb_root		machines;
-	struct events_stats	events_stats;
-	struct rb_root		stats_by_id;
+	struct rb_root		hists_tree;
 	unsigned long		event_total[PERF_RECORD_MAX];
 	unsigned long		unknown_events;
-	struct rb_root		hists;
+	/*
+	 * FIXME: should point to the first entry in hists_tree and
+	 *        be a hists instance. Right now its only 'report'
+	 *        that is using ->hists_tree while all the rest use
+	 *        ->hists.
+	 */
+	struct hists		hists;
 	u64			sample_type;
 	int			fd;
 	bool			fd_pipe;
Signature · 1 line
1.6.2.5
#5 lore raw
In reply to Arnaldo Carvalho de Melo
Quoted 17 lines · Arnaldo Carvalho de Melo

Hi Ingo,

Please pull from:

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

The 3rd is important as it fixes a recently introduced bug (yesterday,
I believe), that makes perf record segfault.

Regards,

Arnaldo Carvalho de Melo (4):
perf newt: Use newtAddComponent()
perf callchains: Use zalloc to allocate objects
perf session: create_kernel_maps should use ->host_machine perf hist: Introduce hists class and move lots of methods to it

Quoted 13 lines
 tools/perf/builtin-annotate.c |   17 ++++----
 tools/perf/builtin-diff.c     |   50 ++++++++++------------
 tools/perf/builtin-report.c   |   71 +++++++++++++++----------------
 tools/perf/builtin-trace.c    |    2 +-
 tools/perf/util/callchain.c   |    6 +-
 tools/perf/util/event.c       |    2 +-
 tools/perf/util/event.h       |   14 ------
 tools/perf/util/hist.c        |   92 ++++++++++++++++++----------------------
 tools/perf/util/hist.h        |   48 ++++++++++++---------
 tools/perf/util/newt.c        |    6 +-
 tools/perf/util/session.c     |    7 +--
 tools/perf/util/session.h     |   12 ++++-
 12 files changed, 154 insertions(+), 173 deletions(-)

Pulled, thanks Arnaldo!

Ingo