mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Stephane Eranian <eranian@google.com>,
	Jiri Olsa <jolsa@redhat.com>, Ulrich Drepper <drepper@gmail.com>,
	Andi Kleen <andi@firstfloor.org>
Subject: [PATCH 03/12] perf hist: Collapse group hist_entries to a leader
Date: Tue, 24 Jul 2012 18:01:24 +0900	[thread overview]
Message-ID: <1343120493-23059-4-git-send-email-namhyung@kernel.org> (raw)
In-Reply-To: <1343120493-23059-1-git-send-email-namhyung@kernel.org>

To support viewing an event group together, collapse all of members
in the group to the leader's tree. The entries in the leader's tree
will have group_stats to store those information.

Cc: Stephane Eranian <eranian@google.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/hist.c   |  114 ++++++++++++++++++++++++++++++++++++++++++----
 tools/perf/util/symbol.c |    4 ++
 tools/perf/util/symbol.h |    3 +-
 3 files changed, 111 insertions(+), 10 deletions(-)

diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index d2a76d379f87..a8f4c56261a0 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -4,6 +4,7 @@
 #include "hist.h"
 #include "session.h"
 #include "sort.h"
+#include "evsel.h"
 #include <math.h>
 
 static bool hists__filter_entry_by_dso(struct hists *hists,
@@ -394,17 +395,50 @@ void hist_entry__free(struct hist_entry *he)
 	free(he);
 }
 
+static void hist_entry__add_stat(struct he_stat *left, struct he_stat *right)
+{
+	left->period		+= right->period;
+	left->period_sys	+= right->period_sys;
+	left->period_us		+= right->period_us;
+	left->period_guest_sys	+= right->period_guest_sys;
+	left->period_guest_us	+= right->period_guest_us;
+	left->nr_events		+= right->nr_events;
+}
+
+static void hist_entry__add_group_stat(struct perf_evsel *evsel,
+				       struct hist_entry *iter,
+				       struct hist_entry *he)
+{
+	struct perf_evsel *leader = evsel->leader;
+	if (!leader)
+		leader = evsel;
+
+	if (!iter->group_stats) {
+		iter->group_stats = calloc(leader->nr_children,
+					   sizeof(struct he_stat));
+		if (!iter->group_stats)
+			return;
+	}
+
+	if (!perf_evsel__is_group_leader(evsel))
+		hist_entry__add_stat(&iter->group_stats[evsel->group_idx],
+				     &he->stat);
+	else
+		hist_entry__add_stat(&iter->stat, &he->stat);
+}
+
 /*
  * collapse the histogram
  */
 
-static bool hists__collapse_insert_entry(struct hists *hists __used,
+static bool hists__collapse_insert_entry(struct hists *hists,
 					 struct rb_root *root,
 					 struct hist_entry *he)
 {
 	struct rb_node **p = &root->rb_node;
 	struct rb_node *parent = NULL;
 	struct hist_entry *iter;
+	struct perf_evsel *evsel = hists_2_evsel(hists);
 	int64_t cmp;
 
 	while (*p != NULL) {
@@ -414,8 +448,11 @@ static bool hists__collapse_insert_entry(struct hists *hists __used,
 		cmp = hist_entry__collapse(iter, he);
 
 		if (!cmp) {
-			iter->stat.period += he->stat.period;
-			iter->stat.nr_events += he->stat.nr_events;
+			if (symbol_conf.report_group)
+				hist_entry__add_group_stat(evsel, iter, he);
+			else
+				hist_entry__add_stat(&iter->stat, &he->stat);
+
 			if (symbol_conf.use_callchain) {
 				callchain_cursor_reset(&callchain_cursor);
 				callchain_merge(&callchain_cursor,
@@ -432,6 +469,16 @@ static bool hists__collapse_insert_entry(struct hists *hists __used,
 			p = &(*p)->rb_right;
 	}
 
+	if (symbol_conf.report_group) {
+		/*
+		 * 'he' is not found in the leader tree.
+		 * Insert it to the tree and setup stats properly.
+		 */
+		hist_entry__add_group_stat(evsel, he, he);
+		if (!perf_evsel__is_group_leader(evsel))
+			memset(&he->stat, 0, sizeof(struct he_stat));
+	}
+
 	rb_link_node(&he->rb_node_in, parent, p);
 	rb_insert_color(&he->rb_node_in, root);
 	return true;
@@ -462,6 +509,7 @@ static void hists__apply_filters(struct hists *hists, struct hist_entry *he)
 static void __hists__collapse_resort(struct hists *hists, bool threaded)
 {
 	struct rb_root *root;
+	struct rb_root *dest;
 	struct rb_node *next;
 	struct hist_entry *n;
 
@@ -470,13 +518,26 @@ static void __hists__collapse_resort(struct hists *hists, bool threaded)
 
 	root = hists__get_rotate_entries_in(hists);
 	next = rb_first(root);
+	dest = &hists->entries_collapsed;
+
+	if (symbol_conf.report_group) {
+		struct perf_evsel *leader;
+
+		/*
+		 * Collapse hist entries to the leader's tree.
+		 * If evsel->leader == NULL, it's the leader.
+		 */
+		leader = hists_2_evsel(hists)->leader;
+		if (leader)
+			dest = &leader->hists.entries_collapsed;
+	}
 
 	while (next) {
 		n = rb_entry(next, struct hist_entry, rb_node_in);
 		next = rb_next(&n->rb_node_in);
 
 		rb_erase(&n->rb_node_in, root);
-		if (hists__collapse_insert_entry(hists, &hists->entries_collapsed, n)) {
+		if (hists__collapse_insert_entry(hists, dest, n)) {
 			/*
 			 * If it wasn't combined with one of the entries already
 			 * collapsed, we need to apply the filters that may have
@@ -501,13 +562,38 @@ void hists__collapse_resort_threaded(struct hists *hists)
  * reverse the map, sort on period.
  */
 
-static void __hists__insert_output_entry(struct rb_root *entries,
+static int __hists__output_cmd_period(struct hist_entry *left,
+				      struct hist_entry *right,
+				      int nr_group)
+{
+	if (left->stat.period > right->stat.period)
+		return 1;
+	if (left->stat.period < right->stat.period)
+		return -1;
+
+	if (symbol_conf.report_group) {
+		int i;
+
+		for (i = 0; i < nr_group; i++) {
+			if (left->group_stats[i].period >
+			    right->group_stats[i].period)
+				return 1;
+			if (left->group_stats[i].period <
+			    right->group_stats[i].period)
+				return -1;
+		}
+	}
+	return 0;
+}
+
+static void __hists__insert_output_entry(struct hists *hists,
 					 struct hist_entry *he,
 					 u64 min_callchain_hits)
 {
-	struct rb_node **p = &entries->rb_node;
+	struct rb_node **p = &hists->entries.rb_node;
 	struct rb_node *parent = NULL;
 	struct hist_entry *iter;
+	struct perf_evsel *evsel = hists_2_evsel(hists);
 
 	if (symbol_conf.use_callchain)
 		callchain_param.sort(&he->sorted_chain, he->callchain,
@@ -517,14 +603,14 @@ static void __hists__insert_output_entry(struct rb_root *entries,
 		parent = *p;
 		iter = rb_entry(parent, struct hist_entry, rb_node);
 
-		if (he->stat.period > iter->stat.period)
+		if (__hists__output_cmd_period(he, iter, evsel->nr_children) > 0)
 			p = &(*p)->rb_left;
 		else
 			p = &(*p)->rb_right;
 	}
 
 	rb_link_node(&he->rb_node, parent, p);
-	rb_insert_color(&he->rb_node, entries);
+	rb_insert_color(&he->rb_node, &hists->entries);
 }
 
 static void __hists__output_resort(struct hists *hists, bool threaded)
@@ -536,6 +622,16 @@ static void __hists__output_resort(struct hists *hists, bool threaded)
 
 	min_callchain_hits = hists->stats.total_period * (callchain_param.min_percent / 100);
 
+	if (symbol_conf.report_group) {
+		struct perf_evsel *evsel = hists_2_evsel(hists);
+
+		/*
+		 * We've collapsed all of non-leader entries to the leader.
+		 */
+		if (!perf_evsel__is_group_leader(evsel))
+			return;
+	}
+
 	if (sort__need_collapse || threaded)
 		root = &hists->entries_collapsed;
 	else
@@ -552,7 +648,7 @@ static void __hists__output_resort(struct hists *hists, bool threaded)
 		n = rb_entry(next, struct hist_entry, rb_node_in);
 		next = rb_next(&n->rb_node_in);
 
-		__hists__insert_output_entry(&hists->entries, n, min_callchain_hits);
+		__hists__insert_output_entry(hists, n, min_callchain_hits);
 		hists__inc_nr_entries(hists, n);
 	}
 }
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 50958bbeb26a..753faa76b7c3 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -14,6 +14,7 @@
 #include "debug.h"
 #include "symbol.h"
 #include "strlist.h"
+#include "sort.h"
 
 #include <libelf.h>
 #include <gelf.h>
@@ -2733,6 +2734,9 @@ int symbol__init(void)
 
 	symbol_conf.kptr_restrict = symbol__read_kptr_restrict();
 
+	if (symbol_conf.report_group)
+		sort__need_collapse = 1;
+
 	symbol_conf.initialized = true;
 	return 0;
 
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index a884b99017f0..9da14d6b1729 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -88,7 +88,8 @@ struct symbol_conf {
 			initialized,
 			kptr_restrict,
 			annotate_asm_raw,
-			annotate_src;
+			annotate_src,
+			report_group;
 	const char	*vmlinux_name,
 			*kallsyms_name,
 			*source_prefix,
-- 
1.7.10.4


  parent reply	other threads:[~2012-07-24  9:07 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-24  9:01 [RFC/PATCHSET 00/12] perf report: Add support to event group viewing (v1) Namhyung Kim
2012-07-24  9:01 ` [PATCH 01/12] perf tools: Add a couple of helper routines to handle groups Namhyung Kim
2012-07-24  9:01 ` [PATCH 02/12] perf hist: Convert to struct he_stat Namhyung Kim
2012-07-24  9:01 ` Namhyung Kim [this message]
2012-07-24  9:01 ` [PATCH 04/12] perf hist: Maintain total periods of group members in the leader Namhyung Kim
2012-07-24  9:01 ` [PATCH 05/12] perf report: Make another loop for output resorting Namhyung Kim
2012-07-24  9:01 ` [PATCH 06/12] perf header: Reconstruct group relationship by parsing cmdline Namhyung Kim
2012-07-25 15:39   ` Jiri Olsa
2012-07-25 15:52     ` Namhyung Kim
2012-07-24  9:01 ` [PATCH 07/12] perf ui/hist: Add support to group viewing Namhyung Kim
2012-07-24  9:01 ` [PATCH 08/12] perf ui/browser: " Namhyung Kim
2012-07-24  9:01 ` [PATCH 09/12] perf ui/gtk: " Namhyung Kim
2012-07-24  9:01 ` [PATCH 10/12] perf report: Show leader events only when event group is enabled Namhyung Kim
2012-07-24  9:01 ` [PATCH 11/12] perf report: Show group description " Namhyung Kim
2012-07-24  9:01 ` [PATCH 12/12] perf report: Add --group option Namhyung Kim
2012-07-24  9:13 ` [RFC/PATCHSET 00/12] perf report: Add support to event group viewing (v1) Namhyung Kim
2012-07-24 21:17 ` Andi Kleen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1343120493-23059-4-git-send-email-namhyung@kernel.org \
    --to=namhyung@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@ghostprotocols.net \
    --cc=andi@firstfloor.org \
    --cc=drepper@gmail.com \
    --cc=eranian@google.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®