Skip to contentSkip to conversation

perf report: Add support for event group view (v6)

PATCH In review Namhyung Kim 4 participants 50 messages Nov 29, 2012 – Jan 24, 2013 1 message not in the archive perf events

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

cover perf report: Add support for event group view (v6)

Hi all,

This is my 6th iteration of event group view patchset. For basic idea and usage example, please see my original post [1].

The largest change in this version is using 'pairs' list of hist_entry instead of allocating group_stats for all group members. But I needed to allocate temporary arrays for internal purpose anyway. If you have a better solution please let me know.

Jiri, sorry for the delay. I had to hunt down some nasty bugs in my patches. And I saw you submitted the multiplu diff series which will conflict my changes. I'll have a look at it soon, and I'd be glad if you take a look at my changes too. :)

You can get this series via my tree at:

git://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git perf/group-v6

Any comments are welcome, thanks,
Namhyung

v5 -> v6:
* set ->leader alse for leader evsel (Arnaldo)
* use hists__{match,link} (Arnaldo)

v4 -> v5:
* rebase onto acme/perf/core

v3 -> v4:
* patch 1-9 in previous post are merged.
* add Jiri's Acked-by
* add report.group config option

v2 -> v3:
* drop patch 1 since it's merged into acme/perf/core
* cherry-pick Jiri's hpp changes
* add missing bswap_32 on reading nr_groups (Jiri)
* remove perf_evlist__recalc_nr_groups() in favor of list_is_last (Jiri)

v1 -> v2:
* save group relation to header (Jiri)

[1] https://lkml.org/lkml/2012/7/24/81

Namhyung Kim (18):
perf evsel: Set leader evsel's ->leader to itself
perf evsel: Convert to _is_group_leader method
perf tools: Keep group information
perf header: Add HEADER_GROUP_DESC feature
perf tools: Fix typo on hist__entry_add_pair
perf hists: Link hist entry pairs to leader
perf hists: Exchange order of comparing items when collapsing hists perf hists: Add hists__{match,link}_collapsed
perf symbol: Introduce symbol_conf.event_group
perf report: Make another loop for linking group hists perf hists: Resort hist entries using group members for output perf ui/hist: Add support for event group view
perf hist browser: Add support for event group view
perf gtk/browser: Add support for event group view
perf report: Bypass non-leader events when event group is enabled perf report: Show group description when event group is enabled perf report: Add --group option
perf report: Add report.group config option

 tools/perf/Documentation/perf-report.txt |   3 +
 tools/perf/builtin-record.c              |   3 +
 tools/perf/builtin-report.c              |  47 +++-
 tools/perf/builtin-stat.c                |   2 +-
 tools/perf/tests/parse-events.c          |  20 +-
 tools/perf/ui/browsers/hists.c           | 237 ++++++++++++++++---
 tools/perf/ui/gtk/browser.c              |  99 ++++++--
 tools/perf/ui/hist.c                     | 375 ++++++++++++++++---------------
 tools/perf/ui/stdio/hist.c               |   2 +
 tools/perf/util/evlist.c                 |  12 +-
 tools/perf/util/evlist.h                 |   1 +
 tools/perf/util/evsel.c                  |  32 ++-
 tools/perf/util/evsel.h                  |  20 +-
 tools/perf/util/header.c                 | 153 +++++++++++++
 tools/perf/util/header.h                 |   2 +
 tools/perf/util/hist.c                   | 182 +++++++++++++--
 tools/perf/util/hist.h                   |   2 +
 tools/perf/util/parse-events.c           |   1 +
 tools/perf/util/parse-events.h           |   1 +
 tools/perf/util/parse-events.y           |  10 +
 tools/perf/util/sort.h                   |   2 +-
 tools/perf/util/symbol.c                 |   4 +
 tools/perf/util/symbol.h                 |   3 +-
 23 files changed, 934 insertions(+), 279 deletions(-)
Signature · 1 line
1.7.11.7
author maintainer
#1 lore raw

cover perf report: Add support for event group view (v6)

Hi all,

This is my 6th iteration of event group view patchset. For basic idea and usage example, please see my original post [1].

The largest change in this version is using 'pairs' list of hist_entry instead of allocating group_stats for all group members. But I needed to allocate temporary arrays for internal purpose anyway. If you have a better solution please let me know.

Jiri, sorry for the delay, I had to hunt down some nasty bugs in my patches. And I saw you submitted the multiplu diff series which will conflict my changes. I'll have a look at it soon, and I'd be glad if you take a look at my changes too. :)

You can get this series via my tree at:

git://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git perf/group-v6

Any comments are welcome, thanks,
Namhyung

v5 -> v6:
* set ->leader alse for leader evsel (Arnaldo)
* use hists__{match,link} (Arnaldo)

v4 -> v5:
* rebase onto acme/perf/core

v3 -> v4:
* patch 1-9 in previous post are merged.
* add Jiri's Acked-by
* add report.group config option

v2 -> v3:
* drop patch 1 since it's merged into acme/perf/core
* cherry-pick Jiri's hpp changes
* add missing bswap_32 on reading nr_groups (Jiri)
* remove perf_evlist__recalc_nr_groups() in favor of list_is_last (Jiri)

v1 -> v2:
* save group relation to header (Jiri)

[1] https://lkml.org/lkml/2012/7/24/81

Namhyung Kim (18):
perf evsel: Set leader evsel's ->leader to itself
perf evsel: Convert to _is_group_leader method
perf tools: Keep group information
perf header: Add HEADER_GROUP_DESC feature
perf tools: Fix typo on hist__entry_add_pair
perf hists: Link hist entry pairs to leader
perf hists: Exchange order of comparing items when collapsing hists perf hists: Add hists__{match,link}_collapsed
perf symbol: Introduce symbol_conf.event_group
perf report: Make another loop for linking group hists perf hists: Resort hist entries using group members for output perf ui/hist: Add support for event group view
perf hist browser: Add support for event group view
perf gtk/browser: Add support for event group view
perf report: Bypass non-leader events when event group is enabled perf report: Show group description when event group is enabled perf report: Add --group option
perf report: Add report.group config option

 tools/perf/Documentation/perf-report.txt |   3 +
 tools/perf/builtin-record.c              |   3 +
 tools/perf/builtin-report.c              |  47 +++-
 tools/perf/builtin-stat.c                |   2 +-
 tools/perf/tests/parse-events.c          |  20 +-
 tools/perf/ui/browsers/hists.c           | 237 ++++++++++++++++---
 tools/perf/ui/gtk/browser.c              |  99 ++++++--
 tools/perf/ui/hist.c                     | 375 ++++++++++++++++---------------
 tools/perf/ui/stdio/hist.c               |   2 +
 tools/perf/util/evlist.c                 |  12 +-
 tools/perf/util/evlist.h                 |   1 +
 tools/perf/util/evsel.c                  |  32 ++-
 tools/perf/util/evsel.h                  |  20 +-
 tools/perf/util/header.c                 | 153 +++++++++++++
 tools/perf/util/header.h                 |   2 +
 tools/perf/util/hist.c                   | 182 +++++++++++++--
 tools/perf/util/hist.h                   |   2 +
 tools/perf/util/parse-events.c           |   1 +
 tools/perf/util/parse-events.h           |   1 +
 tools/perf/util/parse-events.y           |  10 +
 tools/perf/util/sort.h                   |   2 +-
 tools/perf/util/symbol.c                 |   4 +
 tools/perf/util/symbol.h                 |   3 +-
 23 files changed, 934 insertions(+), 279 deletions(-)
Signature · 1 line
1.7.11.7
#2 lore raw
Quoted 10 lines · Namhyung Kim

Hi all,

This is my 6th iteration of event group view patchset. For basic idea and usage example, please see my original post [1].

The largest change in this version is using 'pairs' list of hist_entry instead of allocating group_stats for all group members. But I needed to allocate temporary arrays for internal purpose anyway. If you have a better solution please let me know.

Quoted 4 lines

Jiri, sorry for the delay, I had to hunt down some nasty bugs in my patches. And I saw you submitted the multiplu diff series which will conflict my changes. I'll have a look at it soon, and I'd be glad if you take a look at my changes too. :)

np, great.. will do ;)

thanks,
jirka

author maintainer
#3 lore raw

PATCH 1/18 perf evsel: Set leader evsel's ->leader to itself

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

Currently only non-leader members are set ->leader to the leader evsel of the group and the leader has set NULL. Thus it requires special casing for leader evsels. Set ->leader to itself will remove this.

---
 tools/perf/util/evlist.c | 1 -
 tools/perf/util/evsel.c  | 1 +
 tools/perf/util/evsel.h  | 2 +-
 3 files changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/evlist.c +0 -1
index 705293489e3c..90db2a14e4bb 100644
@@ -111,7 +111,6 @@ void __perf_evlist__set_leader(struct list_head *list)
 	struct perf_evsel *evsel, *leader;
 
 	leader = list_entry(list->next, struct perf_evsel, node);
-	leader->leader = NULL;
 
 	list_for_each_entry(evsel, list, node) {
 		if (evsel != leader)
tools/perf/util/evsel.c +1 -0
index 1fb636c550a1..ceabe05c6b12 100644
@@ -55,6 +55,7 @@ void perf_evsel__init(struct perf_evsel *evsel,
 {
 	evsel->idx	   = idx;
 	evsel->attr	   = *attr;
+	evsel->leader	   = evsel;
 	INIT_LIST_HEAD(&evsel->node);
 	hists__init(&evsel->hists);
 	evsel->sample_size = __perf_evsel__sample_size(attr->sample_type);
tools/perf/util/evsel.h +1 -1
index a4c1dd4e149f..d504668e7ae5 100644
@@ -228,6 +228,6 @@ static inline struct perf_evsel *perf_evsel__next(struct perf_evsel *evsel)
 
 static inline bool perf_evsel__is_group_member(const struct perf_evsel *evsel)
 {
-	return evsel->leader != NULL;
+	return evsel->leader != evsel;
 }
 #endif /* __PERF_EVSEL_H */
Signature · 1 line
1.7.11.7
Acked-by on v1 1/18
#4 lore raw

Re: [PATCH 01/18] perf evsel: Set leader evsel's ->leader to itself

Quoted 11 lines · Namhyung Kim

From: Namhyung Kim <[email protected]>

Currently only non-leader members are set ->leader to the leader evsel of the group and the leader has set NULL. Thus it requires special casing for leader evsels. Set ->leader to itself will remove this.

---

#5 lore raw

[tip:perf/core] perf evsel: Set leader evsel's ->leader to itself

In reply to Namhyung Kim
Commit-ID:  2cfda562da7b0b1e0575507ef3efe782d4e218e4
Gitweb:     http://git.kernel.org/tip/2cfda562da7b0b1e0575507ef3efe782d4e218e4
Author:     Namhyung Kim <[email protected]>
AuthorDate: Thu, 29 Nov 2012 15:38:29 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Sun, 9 Dec 2012 08:46:06 -0300

perf evsel: Set leader evsel's ->leader to itself

Currently only non-leader members are set ->leader to the leader evsel of the group and the leader has set NULL. Thus it requires special casing for leader evsels. Set ->leader to itself will remove this.

---
 tools/perf/util/evlist.c | 1 -
 tools/perf/util/evsel.c  | 1 +
 tools/perf/util/evsel.h  | 2 +-
 3 files changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/evlist.c +0 -1
index 7052934..90db2a1 100644
@@ -111,7 +111,6 @@ void __perf_evlist__set_leader(struct list_head *list)
 	struct perf_evsel *evsel, *leader;
 
 	leader = list_entry(list->next, struct perf_evsel, node);
-	leader->leader = NULL;
 
 	list_for_each_entry(evsel, list, node) {
 		if (evsel != leader)
tools/perf/util/evsel.c +1 -0
index 1b16dd1..7e93418 100644
@@ -55,6 +55,7 @@ void perf_evsel__init(struct perf_evsel *evsel,
 {
 	evsel->idx	   = idx;
 	evsel->attr	   = *attr;
+	evsel->leader	   = evsel;
 	INIT_LIST_HEAD(&evsel->node);
 	hists__init(&evsel->hists);
 	evsel->sample_size = __perf_evsel__sample_size(attr->sample_type);
tools/perf/util/evsel.h +1 -1
index 3d2b801..cbf6d97 100644
@@ -228,6 +228,6 @@ static inline struct perf_evsel *perf_evsel__next(struct perf_evsel *evsel)
 
 static inline bool perf_evsel__is_group_member(const struct perf_evsel *evsel)
 {
-	return evsel->leader != NULL;
+	return evsel->leader != evsel;
 }
 #endif /* __PERF_EVSEL_H */
author maintainer
#6 lore raw

PATCH 2/18 perf evsel: Convert to _is_group_leader method

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

Convert perf_evsel__is_group_member to perf_evsel__is_group_leader. This is because the most usecases are using negative form to check whether the given evsel is a leader or not and it's IMHO somewhat ambiguous - leader also *is* a member of the group.

---
 tools/perf/builtin-stat.c       |  2 +-
 tools/perf/tests/parse-events.c | 20 ++++++++++----------
 tools/perf/util/evlist.c        |  4 ++--
 tools/perf/util/evsel.c         |  6 +++---
 tools/perf/util/evsel.h         |  4 ++--
 5 files changed, 18 insertions(+), 18 deletions(-)
tools/perf/builtin-stat.c +1 -1
index c247faca7127..c12655af2b88 100644
@@ -153,7 +153,7 @@ retry:
 	}
 
 	if (!perf_target__has_task(&target) &&
-	    !perf_evsel__is_group_member(evsel)) {
+	    perf_evsel__is_group_leader(evsel)) {
 		attr->disabled = 1;
 		attr->enable_on_exec = 1;
 	}
tools/perf/tests/parse-events.c +10 -10
index 42a0c8cd3cd5..17f1cd656314 100644
@@ -521,7 +521,7 @@ static int test__group1(struct perf_evlist *evlist)
 	TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
 	TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
 	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
-	TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
+	TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
 
 	/* cycles:upp */
 	evsel = perf_evsel__next(evsel);
@@ -557,7 +557,7 @@ static int test__group2(struct perf_evlist *evlist)
 	TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
 	TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
 	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
-	TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
+	TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
 
 	/* cache-references + :u modifier */
 	evsel = perf_evsel__next(evsel);
@@ -583,7 +583,7 @@ static int test__group2(struct perf_evlist *evlist)
 	TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
 	TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
 	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
-	TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
+	TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
 
 	return 0;
 }
@@ -606,7 +606,7 @@ static int test__group3(struct perf_evlist *evlist __maybe_unused)
 	TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
 	TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
 	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
-	TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
+	TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
 	TEST_ASSERT_VAL("wrong group name",
 		!strcmp(leader->group_name, "group1"));
 
@@ -636,7 +636,7 @@ static int test__group3(struct perf_evlist *evlist __maybe_unused)
 	TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
 	TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
 	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
-	TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
+	TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
 	TEST_ASSERT_VAL("wrong group name",
 		!strcmp(leader->group_name, "group2"));
 
@@ -663,7 +663,7 @@ static int test__group3(struct perf_evlist *evlist __maybe_unused)
 	TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
 	TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
 	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
-	TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
+	TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
 
 	return 0;
 }
@@ -687,7 +687,7 @@ static int test__group4(struct perf_evlist *evlist __maybe_unused)
 	TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
 	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 1);
 	TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
-	TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
+	TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
 
 	/* instructions:kp + p */
 	evsel = perf_evsel__next(evsel);
@@ -724,7 +724,7 @@ static int test__group5(struct perf_evlist *evlist __maybe_unused)
 	TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
 	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
 	TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
-	TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
+	TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
 
 	/* instructions + G */
 	evsel = perf_evsel__next(evsel);
@@ -751,7 +751,7 @@ static int test__group5(struct perf_evlist *evlist __maybe_unused)
 	TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
 	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
 	TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
-	TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
+	TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
 
 	/* instructions:G */
 	evsel = perf_evsel__next(evsel);
@@ -777,7 +777,7 @@ static int test__group5(struct perf_evlist *evlist __maybe_unused)
 	TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
 	TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
 	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
-	TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
+	TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
 
 	return 0;
 }
tools/perf/util/evlist.c +2 -2
index 90db2a14e4bb..d0e1e821fe85 100644
@@ -221,7 +221,7 @@ void perf_evlist__disable(struct perf_evlist *evlist)
 
 	for (cpu = 0; cpu < evlist->cpus->nr; cpu++) {
 		list_for_each_entry(pos, &evlist->entries, node) {
-			if (perf_evsel__is_group_member(pos))
+			if (!perf_evsel__is_group_leader(pos))
 				continue;
 			for (thread = 0; thread < evlist->threads->nr; thread++)
 				ioctl(FD(pos, cpu, thread),
@@ -237,7 +237,7 @@ void perf_evlist__enable(struct perf_evlist *evlist)
 
 	for (cpu = 0; cpu < cpu_map__nr(evlist->cpus); cpu++) {
 		list_for_each_entry(pos, &evlist->entries, node) {
-			if (perf_evsel__is_group_member(pos))
+			if (!perf_evsel__is_group_leader(pos))
 				continue;
 			for (thread = 0; thread < evlist->threads->nr; thread++)
 				ioctl(FD(pos, cpu, thread),
tools/perf/util/evsel.c +3 -3
index ceabe05c6b12..73e6085a7294 100644
@@ -520,14 +520,14 @@ void perf_evsel__config(struct perf_evsel *evsel,
 	 * Disabling only independent events or group leaders,
 	 * keeping group members enabled.
 	 */
-	if (!perf_evsel__is_group_member(evsel))
+	if (perf_evsel__is_group_leader(evsel))
 		attr->disabled = 1;
 
 	/*
 	 * Setting enable_on_exec for independent events and
 	 * group leaders for traced executed by perf.
 	 */
-	if (perf_target__none(&opts->target) && !perf_evsel__is_group_member(evsel))
+	if (perf_target__none(&opts->target) && perf_evsel__is_group_leader(evsel))
 		attr->enable_on_exec = 1;
 }
 
@@ -708,7 +708,7 @@ static int get_group_fd(struct perf_evsel *evsel, int cpu, int thread)
 	struct perf_evsel *leader = evsel->leader;
 	int fd;
 
-	if (!perf_evsel__is_group_member(evsel))
+	if (perf_evsel__is_group_leader(evsel))
 		return -1;
 
 	/*
tools/perf/util/evsel.h +2 -2
index d504668e7ae5..46c8004ca56b 100644
@@ -226,8 +226,8 @@ static inline struct perf_evsel *perf_evsel__next(struct perf_evsel *evsel)
 	return list_entry(evsel->node.next, struct perf_evsel, node);
 }
 
-static inline bool perf_evsel__is_group_member(const struct perf_evsel *evsel)
+static inline bool perf_evsel__is_group_leader(const struct perf_evsel *evsel)
 {
-	return evsel->leader != evsel;
+	return evsel->leader == evsel;
 }
 #endif /* __PERF_EVSEL_H */
Signature · 1 line
1.7.11.7
Acked-by on v1 2/18
#7 lore raw

Re: [PATCH 02/18] perf evsel: Convert to _is_group_leader method

Quoted 9 lines · Namhyung Kim

From: Namhyung Kim <[email protected]>

Convert perf_evsel__is_group_member to perf_evsel__is_group_leader. This is because the most usecases are using negative form to check whether the given evsel is a leader or not and it's IMHO somewhat ambiguous - leader also *is* a member of the group.

---

#8 lore raw

[tip:perf/core] perf evsel: Convert to _is_group_leader method

In reply to Namhyung Kim
Commit-ID:  823254edc66eb44bf612b1dfa4829afa9840f691
Gitweb:     http://git.kernel.org/tip/823254edc66eb44bf612b1dfa4829afa9840f691
Author:     Namhyung Kim <[email protected]>
AuthorDate: Thu, 29 Nov 2012 15:38:30 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Sun, 9 Dec 2012 08:46:06 -0300

perf evsel: Convert to _is_group_leader method

Convert perf_evsel__is_group_member to perf_evsel__is_group_leader. This is because the most usecases are using negative form to check whether the given evsel is a leader or not and it's IMHO somewhat ambiguous - leader also *is* a member of the group.

---
 tools/perf/builtin-stat.c       |  2 +-
 tools/perf/tests/parse-events.c | 20 ++++++++++----------
 tools/perf/util/evlist.c        |  4 ++--
 tools/perf/util/evsel.c         |  6 +++---
 tools/perf/util/evsel.h         |  4 ++--
 5 files changed, 18 insertions(+), 18 deletions(-)
tools/perf/builtin-stat.c +1 -1
index c247fac..c12655a 100644
@@ -153,7 +153,7 @@ retry:
 	}
 
 	if (!perf_target__has_task(&target) &&
-	    !perf_evsel__is_group_member(evsel)) {
+	    perf_evsel__is_group_leader(evsel)) {
 		attr->disabled = 1;
 		attr->enable_on_exec = 1;
 	}
tools/perf/tests/parse-events.c +10 -10
index 32ee478..294ffdd 100644
@@ -521,7 +521,7 @@ static int test__group1(struct perf_evlist *evlist)
 	TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
 	TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
 	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
-	TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
+	TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
 
 	/* cycles:upp */
 	evsel = perf_evsel__next(evsel);
@@ -557,7 +557,7 @@ static int test__group2(struct perf_evlist *evlist)
 	TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
 	TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
 	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
-	TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
+	TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
 
 	/* cache-references + :u modifier */
 	evsel = perf_evsel__next(evsel);
@@ -583,7 +583,7 @@ static int test__group2(struct perf_evlist *evlist)
 	TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
 	TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
 	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
-	TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
+	TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
 
 	return 0;
 }
@@ -606,7 +606,7 @@ static int test__group3(struct perf_evlist *evlist __maybe_unused)
 	TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
 	TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
 	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
-	TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
+	TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
 	TEST_ASSERT_VAL("wrong group name",
 		!strcmp(leader->group_name, "group1"));
 
@@ -636,7 +636,7 @@ static int test__group3(struct perf_evlist *evlist __maybe_unused)
 	TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
 	TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
 	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
-	TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
+	TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
 	TEST_ASSERT_VAL("wrong group name",
 		!strcmp(leader->group_name, "group2"));
 
@@ -663,7 +663,7 @@ static int test__group3(struct perf_evlist *evlist __maybe_unused)
 	TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
 	TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
 	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
-	TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
+	TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
 
 	return 0;
 }
@@ -687,7 +687,7 @@ static int test__group4(struct perf_evlist *evlist __maybe_unused)
 	TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
 	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 1);
 	TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
-	TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
+	TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
 
 	/* instructions:kp + p */
 	evsel = perf_evsel__next(evsel);
@@ -724,7 +724,7 @@ static int test__group5(struct perf_evlist *evlist __maybe_unused)
 	TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
 	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
 	TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
-	TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
+	TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
 
 	/* instructions + G */
 	evsel = perf_evsel__next(evsel);
@@ -751,7 +751,7 @@ static int test__group5(struct perf_evlist *evlist __maybe_unused)
 	TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
 	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
 	TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
-	TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
+	TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
 
 	/* instructions:G */
 	evsel = perf_evsel__next(evsel);
@@ -777,7 +777,7 @@ static int test__group5(struct perf_evlist *evlist __maybe_unused)
 	TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
 	TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
 	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
-	TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
+	TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
 
 	return 0;
 }
tools/perf/util/evlist.c +2 -2
index 90db2a1..d0e1e82 100644
@@ -221,7 +221,7 @@ void perf_evlist__disable(struct perf_evlist *evlist)
 
 	for (cpu = 0; cpu < evlist->cpus->nr; cpu++) {
 		list_for_each_entry(pos, &evlist->entries, node) {
-			if (perf_evsel__is_group_member(pos))
+			if (!perf_evsel__is_group_leader(pos))
 				continue;
 			for (thread = 0; thread < evlist->threads->nr; thread++)
 				ioctl(FD(pos, cpu, thread),
@@ -237,7 +237,7 @@ void perf_evlist__enable(struct perf_evlist *evlist)
 
 	for (cpu = 0; cpu < cpu_map__nr(evlist->cpus); cpu++) {
 		list_for_each_entry(pos, &evlist->entries, node) {
-			if (perf_evsel__is_group_member(pos))
+			if (!perf_evsel__is_group_leader(pos))
 				continue;
 			for (thread = 0; thread < evlist->threads->nr; thread++)
 				ioctl(FD(pos, cpu, thread),
tools/perf/util/evsel.c +3 -3
index 7e93418..bb58b05 100644
@@ -520,14 +520,14 @@ void perf_evsel__config(struct perf_evsel *evsel,
 	 * Disabling only independent events or group leaders,
 	 * keeping group members enabled.
 	 */
-	if (!perf_evsel__is_group_member(evsel))
+	if (perf_evsel__is_group_leader(evsel))
 		attr->disabled = 1;
 
 	/*
 	 * Setting enable_on_exec for independent events and
 	 * group leaders for traced executed by perf.
 	 */
-	if (perf_target__none(&opts->target) && !perf_evsel__is_group_member(evsel))
+	if (perf_target__none(&opts->target) && perf_evsel__is_group_leader(evsel))
 		attr->enable_on_exec = 1;
 }
 
@@ -708,7 +708,7 @@ static int get_group_fd(struct perf_evsel *evsel, int cpu, int thread)
 	struct perf_evsel *leader = evsel->leader;
 	int fd;
 
-	if (!perf_evsel__is_group_member(evsel))
+	if (perf_evsel__is_group_leader(evsel))
 		return -1;
 
 	/*
tools/perf/util/evsel.h +2 -2
index cbf6d97..3f7ff47 100644
@@ -226,8 +226,8 @@ static inline struct perf_evsel *perf_evsel__next(struct perf_evsel *evsel)
 	return list_entry(evsel->node.next, struct perf_evsel, node);
 }
 
-static inline bool perf_evsel__is_group_member(const struct perf_evsel *evsel)
+static inline bool perf_evsel__is_group_leader(const struct perf_evsel *evsel)
 {
-	return evsel->leader != evsel;
+	return evsel->leader == evsel;
 }
 #endif /* __PERF_EVSEL_H */
author maintainer
#9 lore raw

PATCH 3/18 perf tools: Keep group information

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

Add a few of group-related field in struct perf_{evlist,evsel} so that the group information in a evlist can be known easily. It only counts groups which have more than 1 members since leader-only groups are treated as non-group events.

Cc Jiri Olsa <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/evlist.c       |  7 ++++++-
 tools/perf/util/evlist.h       |  1 +
 tools/perf/util/evsel.h        |  6 ++++++
 tools/perf/util/parse-events.c |  1 +
 tools/perf/util/parse-events.h |  1 +
 tools/perf/util/parse-events.y | 10 ++++++++++
 6 files changed, 25 insertions(+), 1 deletion(-)
tools/perf/util/evlist.c +6 -1
index d0e1e821fe85..a446b5b91530 100644
@@ -111,6 +111,9 @@ void __perf_evlist__set_leader(struct list_head *list)
 	struct perf_evsel *evsel, *leader;
 
 	leader = list_entry(list->next, struct perf_evsel, node);
+	evsel = list_entry(list->prev, struct perf_evsel, node);
+
+	leader->nr_members = evsel->idx - leader->idx + 1;
 
 	list_for_each_entry(evsel, list, node) {
 		if (evsel != leader)
@@ -120,8 +123,10 @@ void __perf_evlist__set_leader(struct list_head *list)
 
 void perf_evlist__set_leader(struct perf_evlist *evlist)
 {
-	if (evlist->nr_entries)
+	if (evlist->nr_entries) {
+		evlist->nr_groups = evlist->nr_entries > 1 ? 1 : 0;
 		__perf_evlist__set_leader(&evlist->entries);
+	}
 }
 
 int perf_evlist__add_default(struct perf_evlist *evlist)
tools/perf/util/evlist.h +1 -0
index 56003f779e60..fa76bf91c7e0 100644
@@ -21,6 +21,7 @@ struct perf_evlist {
 	struct list_head entries;
 	struct hlist_head heads[PERF_EVLIST__HLIST_SIZE];
 	int		 nr_entries;
+	int		 nr_groups;
 	int		 nr_fds;
 	int		 nr_mmaps;
 	int		 mmap_len;
tools/perf/util/evsel.h +6 -0
index 46c8004ca56b..887834ed0af1 100644
@@ -73,6 +73,7 @@ struct perf_evsel {
 	bool 			needs_swap;
 	/* parse modifier helper */
 	int			exclude_GH;
+	int			nr_members;
 	struct perf_evsel	*leader;
 	char			*group_name;
 };
@@ -230,4 +231,9 @@ static inline bool perf_evsel__is_group_leader(const struct perf_evsel *evsel)
 {
 	return evsel->leader == evsel;
 }
+
+static inline int perf_evsel__group_idx(struct perf_evsel *evsel)
+{
+	return evsel->idx - evsel->leader->idx;
+}
 #endif /* __PERF_EVSEL_H */
tools/perf/util/parse-events.c +1 -0
index 020323af3364..25a556cf74ee 100644
@@ -843,6 +843,7 @@ int parse_events(struct perf_evlist *evlist, const char *str,
 	if (!ret) {
 		int entries = data.idx - evlist->nr_entries;
 		perf_evlist__splice_list_tail(evlist, &data.list, entries);
+		evlist->nr_groups += data.nr_groups;
 		return 0;
 	}
 
tools/perf/util/parse-events.h +1 -0
index f6399373d67d..5a42c6d7cc9a 100644
@@ -65,6 +65,7 @@ struct parse_events__term {
 struct parse_events_data__events {
 	struct list_head list;
 	int idx;
+	int nr_groups;
 };
 
 struct parse_events_data__terms {
tools/perf/util/parse-events.y +10 -0
index 0f9914ae6bac..69cff676dcb1 100644
@@ -122,6 +122,11 @@ group_def:
 PE_NAME '{' events '}'
 {
 	struct list_head *list = $3;
+	struct parse_events_data__events *data = _data;
+
+	/* Count groups only have more than 1 members */
+	if (!list_is_last(list->next, list))
+		data->nr_groups++;
 
 	parse_events__set_leader($1, list);
 	$$ = list;
@@ -130,6 +135,11 @@ PE_NAME '{' events '}'
 '{' events '}'
 {
 	struct list_head *list = $2;
+	struct parse_events_data__events *data = _data;
+
+	/* Count groups only have more than 1 members */
+	if (!list_is_last(list->next, list))
+		data->nr_groups++;
 
 	parse_events__set_leader(NULL, list);
 	$$ = list;
Signature · 1 line
1.7.11.7
#10 lore raw

Re: [PATCH 03/18] perf tools: Keep group information

Quoted 1 line · Namhyung Kim

From: Namhyung Kim <[email protected]>

SNIP

Quoted 15 lines
tools/perf/util/evlist.h +1 -0
@@ -21,6 +21,7 @@ struct perf_evlist {
 	struct list_head entries;
 	struct hlist_head heads[PERF_EVLIST__HLIST_SIZE];
 	int		 nr_entries;
+	int		 nr_groups;
 	int		 nr_fds;
 	int		 nr_mmaps;
 	int		 mmap_len;
tools/perf/util/evsel.h +0 -0
index 46c8004ca56b..887834ed0af1 100644

tools/perf/util/evsel.h struct perf_evsel { · line 79

Quoted 7 lines
tools/perf/util/evsel.h +1 -0
@@ -73,6 +73,7 @@ struct perf_evsel {
 	bool 			needs_swap;
 	/* parse modifier helper */
 	int			exclude_GH;
+	int			nr_members;
 	struct perf_evsel	*leader;
 	char			*group_name;
 };

we could test both new fields in existing group tests

Quoted 3 lines
tools/perf/util/evsel.h +0 -0
@@ -230,4 +231,9 @@ static inline bool perf_evsel__is_group_leader(const struct perf_evsel *evsel)
 {
 	return evsel->leader == evsel;

SNIP

Quoted 11 lines

{

tools/perf/util/evsel.h +5 -0
 	struct list_head *list = $3;
+	struct parse_events_data__events *data = _data;
+
+	/* Count groups only have more than 1 members */
+	if (!list_is_last(list->next, list))
+		data->nr_groups++;
 
 	parse_events__set_leader($1, list);
 	$$ = list;

tools/perf/util/evsel.h PE_NAME '{' events '}' · line 142

Quoted 8 lines
tools/perf/util/evsel.h +5 -0
@@ -130,6 +135,11 @@ PE_NAME '{' events '}'
 '{' events '}'
 {
 	struct list_head *list = $2;
+	struct parse_events_data__events *data = _data;
+
+	/* Count groups only have more than 1 members */
+	if (!list_is_last(list->next, list))
+		data->nr_groups++;

nitpick.. maybe add a function for above 3 lines?

You could add static function right after ABORT_ON macro definition.

thanks,
jirka

author maintainer
#11 lore raw

Re: [PATCH 03/18] perf tools: Keep group information

2012-11-29 (목), 15:33 +0100, Jiri Olsa:

Quoted 30 lines · Namhyung Kim
Quoted 1 line

From: Namhyung Kim <[email protected]>

SNIP

Quoted 15 lines
tools/perf/util/evlist.h +1 -0
@@ -21,6 +21,7 @@ struct perf_evlist {
 	struct list_head entries;
 	struct hlist_head heads[PERF_EVLIST__HLIST_SIZE];
 	int		 nr_entries;
+	int		 nr_groups;
 	int		 nr_fds;
 	int		 nr_mmaps;
 	int		 mmap_len;
tools/perf/util/evsel.h +0 -0
index 46c8004ca56b..887834ed0af1 100644

tools/perf/util/evsel.h struct perf_evsel { · line 79

Quoted 7 lines
tools/perf/util/evsel.h +1 -0
@@ -73,6 +73,7 @@ struct perf_evsel {
 	bool 			needs_swap;
 	/* parse modifier helper */
 	int			exclude_GH;
+	int			nr_members;
 	struct perf_evsel	*leader;
 	char			*group_name;
 };

we could test both new fields in existing group tests

Quoted 4 lines

tools/perf/util/evsel.h static inline bool perf_evsel__is_group_leader(const struct perf_evsel *evsel) · line 232

Quoted 3 lines
tools/perf/util/evsel.h +0 -0
@@ -230,4 +231,9 @@ static inline bool perf_evsel__is_group_leader(const struct perf_evsel *evsel)
 {
 	return evsel->leader == evsel;

You mean adding 'evsel->nr_members > 1' to this function? For some reason, I'd like to treat non-group events as group leaders so I dropped that check from the function.

Quoted 24 lines

SNIP

Quoted 11 lines

{

tools/perf/util/evsel.h +5 -0
 	struct list_head *list = $3;
+	struct parse_events_data__events *data = _data;
+
+	/* Count groups only have more than 1 members */
+	if (!list_is_last(list->next, list))
+		data->nr_groups++;
 
 	parse_events__set_leader($1, list);
 	$$ = list;

tools/perf/util/evsel.h PE_NAME '{' events '}' · line 142

Quoted 8 lines
tools/perf/util/evsel.h +5 -0
@@ -130,6 +135,11 @@ PE_NAME '{' events '}'
 '{' events '}'
 {
 	struct list_head *list = $2;
+	struct parse_events_data__events *data = _data;
+
+	/* Count groups only have more than 1 members */
+	if (!list_is_last(list->next, list))
+		data->nr_groups++;

nitpick.. maybe add a function for above 3 lines?

Quoted 2 lines

You could add static function right after ABORT_ON macro definition.

No problem. Will do.

Thanks,
Namhyung

#12 lore raw

Re: [PATCH 03/18] perf tools: Keep group information

Quoted 31 lines · Namhyung Kim

2012-11-29 (목), 15:33 +0100, Jiri Olsa:

Quoted 30 lines · Namhyung Kim
Quoted 1 line

From: Namhyung Kim <[email protected]>

SNIP

Quoted 15 lines
tools/perf/util/evlist.h +1 -0
@@ -21,6 +21,7 @@ struct perf_evlist {
 	struct list_head entries;
 	struct hlist_head heads[PERF_EVLIST__HLIST_SIZE];
 	int		 nr_entries;
+	int		 nr_groups;
 	int		 nr_fds;
 	int		 nr_mmaps;
 	int		 mmap_len;
tools/perf/util/evsel.h +0 -0
index 46c8004ca56b..887834ed0af1 100644

tools/perf/util/evsel.h struct perf_evsel { · line 79

Quoted 7 lines
tools/perf/util/evsel.h +1 -0
@@ -73,6 +73,7 @@ struct perf_evsel {
 	bool 			needs_swap;
 	/* parse modifier helper */
 	int			exclude_GH;
+	int			nr_members;
 	struct perf_evsel	*leader;
 	char			*group_name;
 };

we could test both new fields in existing group tests

Quoted 8 lines
Quoted 4 lines

tools/perf/util/evsel.h static inline bool perf_evsel__is_group_leader(const struct perf_evsel *evsel) · line 232

Quoted 3 lines
tools/perf/util/evsel.h +0 -0
@@ -230,4 +231,9 @@ static inline bool perf_evsel__is_group_leader(const struct perf_evsel *evsel)
 {
 	return evsel->leader == evsel;

You mean adding 'evsel->nr_members > 1' to this function? For some reason, I'd like to treat non-group events as group leaders so I dropped that check from the function.

nope, the change is ok, I meant updating automated tests in tests/parse-events.c

thanks,
jirka

author maintainer
#13 lore raw

Re: [PATCH 03/18] perf tools: Keep group information

2012-11-29 (목), 16:02 +0100, Jiri Olsa:

Quoted 37 lines · Namhyung Kim
Quoted 36 lines

2012-11-29 (목), 15:33 +0100, Jiri Olsa:

Quoted 34 lines · Namhyung Kim
Quoted 1 line

From: Namhyung Kim <[email protected]>

SNIP

Quoted 15 lines
tools/perf/util/evlist.h +1 -0
@@ -21,6 +21,7 @@ struct perf_evlist {
 	struct list_head entries;
 	struct hlist_head heads[PERF_EVLIST__HLIST_SIZE];
 	int		 nr_entries;
+	int		 nr_groups;
 	int		 nr_fds;
 	int		 nr_mmaps;
 	int		 mmap_len;
tools/perf/util/evsel.h +0 -0
index 46c8004ca56b..887834ed0af1 100644

tools/perf/util/evsel.h struct perf_evsel { · line 79

Quoted 7 lines
tools/perf/util/evsel.h +1 -0
@@ -73,6 +73,7 @@ struct perf_evsel {
 	bool 			needs_swap;
 	/* parse modifier helper */
 	int			exclude_GH;
+	int			nr_members;
 	struct perf_evsel	*leader;
 	char			*group_name;
 };

we could test both new fields in existing group tests

Quoted 3 lines
tools/perf/util/evsel.h +0 -0
@@ -230,4 +231,9 @@ static inline bool perf_evsel__is_group_leader(const struct perf_evsel *evsel)
 {
 	return evsel->leader == evsel;
Quoted 5 lines
Quoted 3 lines

You mean adding 'evsel->nr_members > 1' to this function? For some reason, I'd like to treat non-group events as group leaders so I dropped that check from the function.

nope, the change is ok, I meant updating automated tests in tests/parse-events.c

Ah, okay. Always forgot to update the test. :( Will add.

Thanks,
Namhyung

#14 lore raw

Re: [PATCH 03/18] perf tools: Keep group information

Em Fri, Nov 30, 2012 at 12:09:11AM +0900, Namhyung Kim escreveu:

Quoted 8 lines

2012-11-29 (목), 16:02 +0100, Jiri Olsa:

Quoted 5 lines
Quoted 3 lines

You mean adding 'evsel->nr_members > 1' to this function? For some reason, I'd like to treat non-group events as group leaders so I dropped that check from the function.

nope, the change is ok, I meant updating automated tests in tests/parse-events.c

Ah, okay. Always forgot to update the test. :( Will add.

Also consider adding more tests, perhaps for the formatting, i.e. calling those hpp functions and then checking that the resulting formatted string is the one expected.

One thing I need to do is to create a test that uses slang to write a line with callchains and then, without updating the screen, check if what is buffered to refresh the screen is what we expect, so that we can check that that '+' char isn't lost like it happened twice :-)

- Arnaldo

author maintainer
#15 lore raw

Re: [PATCH 03/18] perf tools: Keep group information

Hi Arnaldo,

Quoted 10 lines · Arnaldo Carvalho de Melo

Em Fri, Nov 30, 2012 at 12:09:11AM +0900, Namhyung Kim escreveu:

Quoted 8 lines

2012-11-29 (목), 16:02 +0100, Jiri Olsa:

Quoted 5 lines
Quoted 3 lines

You mean adding 'evsel->nr_members > 1' to this function? For some reason, I'd like to treat non-group events as group leaders so I dropped that check from the function.

nope, the change is ok, I meant updating automated tests in tests/parse-events.c

Ah, okay. Always forgot to update the test. :( Will add.

Quoted 8 lines

Also consider adding more tests, perhaps for the formatting, i.e. calling those hpp functions and then checking that the resulting formatted string is the one expected.

One thing I need to do is to create a test that uses slang to write a line with callchains and then, without updating the screen, check if what is buffered to refresh the screen is what we expect, so that we can check that that '+' char isn't lost like it happened twice :-)

Yep, will try.

Thanks,
Namhyung

author maintainer
#16 lore raw

PATCH 4/18 perf header: Add HEADER_GROUP_DESC feature

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

Save group relationship information so that it can be restored when perf report is running.

---
 tools/perf/builtin-record.c |   3 +
 tools/perf/util/header.c    | 153 ++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/header.h    |   2 +
 3 files changed, 158 insertions(+)
tools/perf/builtin-record.c +3 -0
index f3151d3c70ce..d50f0dcfe1c1 100644
@@ -592,6 +592,9 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)
 		goto out_delete_session;
 	}
 
+	if (!evsel_list->nr_groups)
+		perf_header__clear_feat(&session->header, HEADER_GROUP_DESC);
+
 	/*
 	 * perf_session__delete(session) will be called at perf_record__exit()
 	 */
tools/perf/util/header.c +153 -0

177 lines not on this page · raw message

tools/perf/util/header.h +2 -0
index 5f1cd6884f37..e3e7fb490310 100644
@@ -29,6 +29,7 @@ enum {
 	HEADER_NUMA_TOPOLOGY,
 	HEADER_BRANCH_STACK,
 	HEADER_PMU_MAPPINGS,
+	HEADER_GROUP_DESC,
 	HEADER_LAST_FEATURE,
 	HEADER_FEAT_BITS	= 256,
 };
@@ -79,6 +80,7 @@ struct perf_session_env {
 	char			*numa_nodes;
 	int			nr_pmu_mappings;
 	char			*pmu_mappings;
+	int			nr_groups;
 };
 
 struct perf_header {
Signature · 1 line
1.7.11.7
#17 lore raw

Re: [PATCH 04/18] perf header: Add HEADER_GROUP_DESC feature

Em Thu, Nov 29, 2012 at 03:38:32PM +0900, Namhyung Kim escreveu:

Quoted 56 lines

From: Namhyung Kim <[email protected]>

Save group relationship information so that it can be restored when perf report is running.

---
 tools/perf/builtin-record.c |   3 +
 tools/perf/util/header.c    | 153 ++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/header.h    |   2 +
 3 files changed, 158 insertions(+)
tools/perf/builtin-record.c +3 -0
index f3151d3c70ce..d50f0dcfe1c1 100644
@@ -592,6 +592,9 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)
 		goto out_delete_session;
 	}
 
+	if (!evsel_list->nr_groups)
+		perf_header__clear_feat(&session->header, HEADER_GROUP_DESC);
+
 	/*
 	 * perf_session__delete(session) will be called at perf_record__exit()
 	 */
tools/perf/util/header.c +19 -0
index 195a47a8f052..6ae8185842f2 100644
@@ -1073,6 +1073,41 @@ static int write_pmu_mappings(int fd, struct perf_header *h __maybe_unused,
 }
 
 /*
+ * File format:
+ *
+ * struct group_descs {
+ *	u32	nr_groups;
+ *	struct group_desc {
+ *		char	name[];
+ *		u32	leader_idx;
+ *		u32	nr_members;
+ *	}[nr_groups];
+ * };
+ */
+static int write_group_desc(int fd, struct perf_header *h __maybe_unused,
+			    struct perf_evlist *evlist)
+{
+	u32 nr_groups = evlist->nr_groups;
+	struct perf_evsel *evsel;
+
+	do_write(fd, &nr_groups, sizeof(nr_groups));
+

tools/perf/util/header.c static int write_pmu_mappings(int fd, struct perf_header *h __maybe_unused, · line 1104

Quoted 10 lines
tools/perf/util/header.c +10 -0
+	list_for_each_entry(evsel, &evlist->entries, node) {
+		if (perf_evsel__is_group_leader(evsel) &&
+		    evsel->nr_members > 1) {
+			const char *name = evsel->group_name ?: "{anon_group}";
+			u32 leader_idx = evsel->idx;
+			u32 nr_members = evsel->nr_members;
+
+			do_write_string(fd, name);
+			do_write(fd, &leader_idx, sizeof(leader_idx));
+			do_write(fd, &nr_members, sizeof(nr_members));

You need to check do_write() return, it can fail. There are some cases in header.c that don't check it, those should be eventually fixed, most cases check it tho.

Quoted 50 lines
tools/perf/util/header.c +36 -0
+		}
+	}
+	return 0;
+}
+
+/*
  * default get_cpuid(): nothing gets recorded
  * actual implementation must be in arch/$(ARCH)/util/header.c
  */
@@ -1433,6 +1468,31 @@ error:
 	fprintf(fp, "# pmu mappings: unable to read\n");
 }
 
+static void print_group_desc(struct perf_header *ph, int fd __maybe_unused,
+			     FILE *fp)
+{
+	struct perf_session *session;
+	struct perf_evsel *evsel;
+	u32 nr = 0;
+
+	session = container_of(ph, struct perf_session, header);
+
+	list_for_each_entry(evsel, &session->evlist->entries, node) {
+		if (perf_evsel__is_group_leader(evsel) &&
+		    evsel->nr_members > 1) {
+			fprintf(fp, "# group: %s{%s", evsel->group_name ?: "",
+				perf_evsel__name(evsel));
+
+			nr = evsel->nr_members - 1;
+		} else if (nr) {
+			fprintf(fp, ",%s", perf_evsel__name(evsel));
+
+			if (--nr == 0)
+				fprintf(fp, "}\n");
+		}
+	}
+}
+
 static int __event_process_build_id(struct build_id_event *bev,
 				    char *filename,
 				    struct perf_session *session)
@@ -1947,6 +2007,98 @@ error:
 	return -1;
 }
 
+static int process_group_desc(struct perf_file_section *section __maybe_unused,
+			      struct perf_header *ph, int fd,
+			      void *data __maybe_unused)
+{
+	size_t ret = -1;

tools/perf/util/header.c error: · line 2024

Quoted 10 lines
tools/perf/util/header.c +10 -0
+	u32 i, nr, nr_groups;
+	struct perf_session *session;
+	struct perf_evsel *evsel, *leader = NULL;
+	struct group_desc {
+		char *name;
+		u32 leader_idx;
+		u32 nr_members;
+	} *desc;
+
+	if (read(fd, &nr_groups, sizeof(nr_groups)) != sizeof(nr_groups))

Please use readn() instead in all read() cases in this function.

Quoted 110 lines
tools/perf/util/header.c +78 -0
+		return -1;
+
+	if (ph->needs_swap)
+		nr_groups = bswap_32(nr_groups);
+
+	ph->env.nr_groups = nr_groups;
+	if (!nr_groups) {
+		pr_debug("group desc not available\n");
+		return 0;
+	}
+
+	desc = calloc(nr_groups, sizeof(*desc));
+	if (!desc)
+		return -1;
+
+	for (i = 0; i < nr_groups; i++) {
+		desc[i].name = do_read_string(fd, ph);
+		if (!desc[i].name)
+			goto out_free;
+
+		if (read(fd, &desc[i].leader_idx, sizeof(u32)) != sizeof(u32))
+			goto out_free;
+
+		if (read(fd, &desc[i].nr_members, sizeof(u32)) != sizeof(u32))
+			goto out_free;
+
+		if (ph->needs_swap) {
+			desc[i].leader_idx = bswap_32(desc[i].leader_idx);
+			desc[i].nr_members = bswap_32(desc[i].nr_members);
+		}
+	}
+
+	/*
+	 * Rebuild group relationship based on the group_desc
+	 */
+	session = container_of(ph, struct perf_session, header);
+	session->evlist->nr_groups = nr_groups;
+
+	i = nr = 0;
+	list_for_each_entry(evsel, &session->evlist->entries, node) {
+		if (evsel->idx == (int) desc[i].leader_idx) {
+			evsel->leader = evsel;
+			/* {anon_group} is a dummy name */
+			if (strcmp(desc[i].name, "{anon_group}"))
+				evsel->group_name = desc[i].name;
+			evsel->nr_members = desc[i].nr_members;
+
+			if (i >= nr_groups || nr > 0) {
+				pr_debug("invalid group desc\n");
+				goto out_free;
+			}
+
+			leader = evsel;
+			nr = evsel->nr_members - 1;
+			i++;
+		} else if (nr) {
+			/* This is a group member */
+			evsel->leader = leader;
+
+			nr--;
+		}
+	}
+
+	if (i != nr_groups || nr != 0) {
+		pr_debug("invalid group desc\n");
+		goto out_free;
+	}
+
+	ret = 0;
+out_free:
+	while ((int) --i >= 0)
+		free(desc[i].name);
+	free(desc);
+
+	return ret;
+}
+
 struct feature_ops {
 	int (*write)(int fd, struct perf_header *h, struct perf_evlist *evlist);
 	void (*print)(struct perf_header *h, int fd, FILE *fp);
@@ -1986,6 +2138,7 @@ static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = {
 	FEAT_OPF(HEADER_NUMA_TOPOLOGY,	numa_topology),
 	FEAT_OPA(HEADER_BRANCH_STACK,	branch_stack),
 	FEAT_OPP(HEADER_PMU_MAPPINGS,	pmu_mappings),
+	FEAT_OPP(HEADER_GROUP_DESC,	group_desc),
 };
 
 struct header_print_data {
tools/perf/util/header.h +2 -0
index 5f1cd6884f37..e3e7fb490310 100644
@@ -29,6 +29,7 @@ enum {
 	HEADER_NUMA_TOPOLOGY,
 	HEADER_BRANCH_STACK,
 	HEADER_PMU_MAPPINGS,
+	HEADER_GROUP_DESC,
 	HEADER_LAST_FEATURE,
 	HEADER_FEAT_BITS	= 256,
 };
@@ -79,6 +80,7 @@ struct perf_session_env {
 	char			*numa_nodes;
 	int			nr_pmu_mappings;
 	char			*pmu_mappings;
+	int			nr_groups;
 };
 
 struct perf_header {
Signature · 1 line
1.7.11.7
author maintainer
#18 lore raw

Re: [PATCH 04/18] perf header: Add HEADER_GROUP_DESC feature

Quoted 6 lines · Arnaldo Carvalho de Melo

Em Thu, Nov 29, 2012 at 03:38:32PM +0900, Namhyung Kim escreveu:

Quoted 5 lines

From: Namhyung Kim <[email protected]>

Save group relationship information so that it can be restored when perf report is running.

[snip]

Quoted 14 lines
Quoted 14 lines
tools/perf/util/header.c +14 -0
+static int write_group_desc(int fd, struct perf_header *h __maybe_unused,
+			    struct perf_evlist *evlist)
+{
+	u32 nr_groups = evlist->nr_groups;
+	struct perf_evsel *evsel;
+
+	do_write(fd, &nr_groups, sizeof(nr_groups));
+
+	list_for_each_entry(evsel, &evlist->entries, node) {
+		if (perf_evsel__is_group_leader(evsel) &&
+		    evsel->nr_members > 1) {
+			const char *name = evsel->group_name ?: "{anon_group}";
+			u32 leader_idx = evsel->idx;
+			u32 nr_members = evsel->nr_members;
Quoted 8 lines

tools/perf/util/header.c static int write_pmu_mappings(int fd, struct perf_header *h __maybe_unused, · line 1104

Quoted 4 lines
tools/perf/util/header.c +4 -0
+
+			do_write_string(fd, name);
+			do_write(fd, &leader_idx, sizeof(leader_idx));
+			do_write(fd, &nr_members, sizeof(nr_members));

You need to check do_write() return, it can fail. There are some cases in header.c that don't check it, those should be eventually fixed, most cases check it tho.

Okay.

Quoted 5 lines
Quoted 5 lines
tools/perf/util/header.c +4 -0
+		}
+	}
+	return 0;
+}

[snip]

Quoted 9 lines
Quoted 9 lines
tools/perf/util/header.c +9 -0
+static int process_group_desc(struct perf_file_section *section __maybe_unused,
+			      struct perf_header *ph, int fd,
+			      void *data __maybe_unused)
+{
+	size_t ret = -1;
+	u32 i, nr, nr_groups;
+	struct perf_session *session;
+	struct perf_evsel *evsel, *leader = NULL;
+	struct group_desc {
Quoted 8 lines

tools/perf/util/header.c error: · line 2024

Quoted 6 lines
tools/perf/util/header.c +6 -0
+		char *name;
+		u32 leader_idx;
+		u32 nr_members;
+	} *desc;
+
+	if (read(fd, &nr_groups, sizeof(nr_groups)) != sizeof(nr_groups))

Please use readn() instead in all read() cases in this function.

Will do.

Thanks,
Namhyung

author maintainer
#19 lore raw

PATCH 5/18 perf tools: Fix typo on hist__entry_add_pair

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

Fix a misplaced underscore. In this case, 'hist_entry' is the name of data structure and we usually put double underscores between data structure and actual function name.

---
 tools/perf/util/hist.c | 4 ++--
 tools/perf/util/sort.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
tools/perf/util/hist.c +2 -2
index cb17e2a8c6ed..d2bc05cd1708 100644
@@ -785,7 +785,7 @@ void hists__match(struct hists *leader, struct hists *other)
 		pair = hists__find_entry(other, pos);
 
 		if (pair)
-			hist__entry_add_pair(pos, pair);
+			hist_entry__add_pair(pos, pair);
 	}
 }
 
@@ -806,7 +806,7 @@ int hists__link(struct hists *leader, struct hists *other)
 			pair = hists__add_dummy_entry(leader, pos);
 			if (pair == NULL)
 				return -1;
-			hist__entry_add_pair(pair, pos);
+			hist_entry__add_pair(pair, pos);
 		}
 	}
 
tools/perf/util/sort.h +1 -1
index b4e8c3ba559d..91ae2744e7d5 100644
@@ -118,7 +118,7 @@ static inline struct hist_entry *hist_entry__next_pair(struct hist_entry *he)
 	return NULL;
 }
 
-static inline void hist__entry_add_pair(struct hist_entry *he,
+static inline void hist_entry__add_pair(struct hist_entry *he,
 					struct hist_entry *pair)
 {
 	list_add_tail(&he->pairs.head, &pair->pairs.node);
Signature · 1 line
1.7.11.7
author maintainer
#21 lore raw

PATCH 6/18 perf hists: Link hist entry pairs to leader

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

Current hists__match/link() link a leader to its pair, so if multiple pairs were linked, the leader will lose pointer to previous pairs since it was overwritten. Fix it by making leader the list head.

Cc Jiri Olsa <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/hist.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/hist.c +2 -2
index d2bc05cd1708..82df1b26f0d4 100644
@@ -785,7 +785,7 @@ void hists__match(struct hists *leader, struct hists *other)
 		pair = hists__find_entry(other, pos);
 
 		if (pair)
-			hist_entry__add_pair(pos, pair);
+			hist_entry__add_pair(pair, pos);
 	}
 }
 
@@ -806,7 +806,7 @@ int hists__link(struct hists *leader, struct hists *other)
 			pair = hists__add_dummy_entry(leader, pos);
 			if (pair == NULL)
 				return -1;
-			hist_entry__add_pair(pair, pos);
+			hist_entry__add_pair(pos, pair);
 		}
 	}
 
Signature · 1 line
1.7.11.7
#22 lore raw

[tip:perf/core] perf hists: Link hist entry pairs to leader

Commit-ID:  5fa9041bbaa7a79a67d568b9c9f947db2f23d091
Gitweb:     http://git.kernel.org/tip/5fa9041bbaa7a79a67d568b9c9f947db2f23d091
Author:     Namhyung Kim <[email protected]>
AuthorDate: Thu, 29 Nov 2012 15:38:34 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Sun, 9 Dec 2012 08:46:06 -0300

perf hists: Link hist entry pairs to leader

Current hists__match/link() link a leader to its pair, so if multiple pairs were linked, the leader will lose pointer to previous pairs since it was overwritten. Fix it by making leader the list head.

---
 tools/perf/util/hist.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/hist.c +2 -2
index d2bc05c..82df1b2 100644
@@ -785,7 +785,7 @@ void hists__match(struct hists *leader, struct hists *other)
 		pair = hists__find_entry(other, pos);
 
 		if (pair)
-			hist_entry__add_pair(pos, pair);
+			hist_entry__add_pair(pair, pos);
 	}
 }
 
@@ -806,7 +806,7 @@ int hists__link(struct hists *leader, struct hists *other)
 			pair = hists__add_dummy_entry(leader, pos);
 			if (pair == NULL)
 				return -1;
-			hist_entry__add_pair(pair, pos);
+			hist_entry__add_pair(pos, pair);
 		}
 	}
 
author maintainer
#23 lore raw

PATCH 7/18 perf hists: Exchange order of comparing items when collapsing hists

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

When comparing entries for collapsing put the given entry first, and then the iterated entry. This is for the sake of consistency and will be required by the event group report.

Cc Jiri Olsa <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/hist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/hist.c +1 -1
index 82df1b26f0d4..161c35e7ed0e 100644
@@ -433,7 +433,7 @@ static bool hists__collapse_insert_entry(struct hists *hists __maybe_unused,
 		parent = *p;
 		iter = rb_entry(parent, struct hist_entry, rb_node_in);
 
-		cmp = hist_entry__collapse(iter, he);
+		cmp = hist_entry__collapse(he, iter);
 
 		if (!cmp) {
 			he_stat__add_stat(&iter->stat, &he->stat);
Signature · 1 line
1.7.11.7
#24 lore raw

Re: [PATCH 07/18] perf hists: Exchange order of comparing items when collapsing hists

Em Thu, Nov 29, 2012 at 03:38:35PM +0900, Namhyung Kim escreveu:

Quoted 4 lines

From: Namhyung Kim <[email protected]>

When comparing entries for collapsing put the given entry first, and then the iterated entry. This is for the sake of consistency and will

consistency with what? and, see below:

Quoted 14 lines

be required by the event group report.

Cc Jiri Olsa <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/hist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/hist.c +0 -0
index 82df1b26f0d4..161c35e7ed0e 100644

tools/perf/util/hist.c static bool hists__collapse_insert_entry(struct hists *hists __maybe_unused, · line 439

Quoted 8 lines
tools/perf/util/hist.c +1 -1
@@ -433,7 +433,7 @@ static bool hists__collapse_insert_entry(struct hists *hists __maybe_unused,
 		parent = *p;
 		iter = rb_entry(parent, struct hist_entry, rb_node_in);
 
-		cmp = hist_entry__collapse(iter, he);
+		cmp = hist_entry__collapse(he, iter);
 
 		if (!cmp) {
 			he_stat__add_stat(&iter->stat, &he->stat);

doesn't this now gets inconsistent with the hist_entry__collapse() call? I.e. iter first, he after, also there is the case for callchains, below, care to elaborate here?

Quoted 2 lines
Signature · 1 line
1.7.11.7
author maintainer
#25 lore raw

Re: [PATCH 07/18] perf hists: Exchange order of comparing items when collapsing hists

Quoted 28 lines · Arnaldo Carvalho de Melo

Em Thu, Nov 29, 2012 at 03:38:35PM +0900, Namhyung Kim escreveu:

Quoted 4 lines

From: Namhyung Kim <[email protected]>

When comparing entries for collapsing put the given entry first, and then the iterated entry. This is for the sake of consistency and will

consistency with what? and, see below:

Quoted 20 lines

be required by the event group report.

Cc Jiri Olsa <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/hist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/hist.c +1 -1
index 82df1b26f0d4..161c35e7ed0e 100644
@@ -433,7 +433,7 @@ static bool hists__collapse_insert_entry(struct hists *hists __maybe_unused,
 		parent = *p;
 		iter = rb_entry(parent, struct hist_entry, rb_node_in);
 
-		cmp = hist_entry__collapse(iter, he);
+		cmp = hist_entry__collapse(he, iter);
 
Quoted 6 lines

tools/perf/util/hist.c static bool hists__collapse_insert_entry(struct hists *hists __maybe_unused, · line 439

Quoted 2 lines
tools/perf/util/hist.c +0 -0
 		if (!cmp) {
 			he_stat__add_stat(&iter->stat, &he->stat);

doesn't this now gets inconsistent with the hist_entry__collapse() call? I.e. iter first, he after, also there is the case for callchains, below, care to elaborate here?

I meant it by consistent with hist_entry__cmp() and didn't consider he_stat__add_stat and callchain_merge things - thought that they're other kind of operation.

I needed this change because I introduced hists__{match,link}_collapsed function in the patch 8 and I found that hist_entry__cmp and hist_entry__collapse received same kind of arguments in different order. Sorry about missing this in the changelog.

However on the second thought, I feel like I don't need those _collapsed functions at all and perf diff can be converted to use collapsed rb tree directly instead. IIUC perf diff use those functions to match entries by sort keys and do additional resort output rb tree by sort keys (IMHO the function names - _name_resort and _insert_by_name - are misnomers) to do the match.

Since output resorting (by period) is only needed for the baseline, other data files doesn't need to do this additional step. So I can get rid of those hists__{match,link}_collapsed functions and change plain hists__{match,link} functions to use collapsed (or input) rb tree directly.

Jiri, what do you think? What am I missing? :)

Thanks,
Namhyung

#26 lore raw

Re: [PATCH 07/18] perf hists: Exchange order of comparing items when collapsing hists

Quoted 52 lines · Namhyung Kim
Quoted 28 lines · Arnaldo Carvalho de Melo

Em Thu, Nov 29, 2012 at 03:38:35PM +0900, Namhyung Kim escreveu:

Quoted 4 lines

From: Namhyung Kim <[email protected]>

When comparing entries for collapsing put the given entry first, and then the iterated entry. This is for the sake of consistency and will

consistency with what? and, see below:

Quoted 20 lines

be required by the event group report.

Cc Jiri Olsa <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/hist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/hist.c +1 -1
index 82df1b26f0d4..161c35e7ed0e 100644
@@ -433,7 +433,7 @@ static bool hists__collapse_insert_entry(struct hists *hists __maybe_unused,
 		parent = *p;
 		iter = rb_entry(parent, struct hist_entry, rb_node_in);
 
-		cmp = hist_entry__collapse(iter, he);
+		cmp = hist_entry__collapse(he, iter);
 
Quoted 6 lines

tools/perf/util/hist.c static bool hists__collapse_insert_entry(struct hists *hists __maybe_unused, · line 439

Quoted 2 lines
tools/perf/util/hist.c +0 -0
 		if (!cmp) {
 			he_stat__add_stat(&iter->stat, &he->stat);

doesn't this now gets inconsistent with the hist_entry__collapse() call? I.e. iter first, he after, also there is the case for callchains, below, care to elaborate here?

I meant it by consistent with hist_entry__cmp() and didn't consider he_stat__add_stat and callchain_merge things - thought that they're other kind of operation.

I needed this change because I introduced hists__{match,link}_collapsed function in the patch 8 and I found that hist_entry__cmp and hist_entry__collapse received same kind of arguments in different order. Sorry about missing this in the changelog.

However on the second thought, I feel like I don't need those _collapsed functions at all and perf diff can be converted to use collapsed rb tree directly instead. IIUC perf diff use those functions to match entries by sort keys and do additional resort output rb tree by sort keys (IMHO the function names - _name_resort and _insert_by_name - are misnomers) to do the match.

Quoted 7 lines

Since output resorting (by period) is only needed for the baseline, other data files doesn't need to do this additional step. So I can get rid of those hists__{match,link}_collapsed functions and change plain hists__{match,link} functions to use collapsed (or input) rb tree directly.

Jiri, what do you think? What am I missing? :)

feels like I'm missing something now :))

right now I don't see a point in having sort__need_collapse enabled for group report.. there seems to be no special processing as it was in the initial patchset..?

It seems like you could do only stadard period resort (collapsed if needed) and afterwards run current hists__match and hists_link function they are now.

All you need at the output callback is paired leader hist entry.. where you do the temp array magic to get the data.

/me going to dishonour some whiteboard.. ;)

jirka

author maintainer
#27 lore raw

Re: [PATCH 07/18] perf hists: Exchange order of comparing items when collapsing hists

Quoted 28 lines · Jiri Olsa
Quoted 27 lines · Namhyung Kim
Quoted 3 lines · Arnaldo Carvalho de Melo

doesn't this now gets inconsistent with the hist_entry__collapse() call? I.e. iter first, he after, also there is the case for callchains, below, care to elaborate here?

I meant it by consistent with hist_entry__cmp() and didn't consider he_stat__add_stat and callchain_merge things - thought that they're other kind of operation.

I needed this change because I introduced hists__{match,link}_collapsed function in the patch 8 and I found that hist_entry__cmp and hist_entry__collapse received same kind of arguments in different order. Sorry about missing this in the changelog.

However on the second thought, I feel like I don't need those _collapsed functions at all and perf diff can be converted to use collapsed rb tree directly instead. IIUC perf diff use those functions to match entries by sort keys and do additional resort output rb tree by sort keys (IMHO the function names - _name_resort and _insert_by_name - are misnomers) to do the match.

Since output resorting (by period) is only needed for the baseline, other data files doesn't need to do this additional step. So I can get rid of those hists__{match,link}_collapsed functions and change plain hists__{match,link} functions to use collapsed (or input) rb tree directly.

Quoted 7 lines
Quoted 1 line

Jiri, what do you think? What am I missing? :)

feels like I'm missing something now :))

right now I don't see a point in having sort__need_collapse enabled for group report.. there seems to be no special processing as it was in the initial patchset..?

Right. It's not needed anymore, will remove.

Quoted 4 lines

It seems like you could do only stadard period resort (collapsed if needed) and afterwards run current hists__match and hists_link function they are now.

But hists__match/link needs the tree sorted by sort keys. That means I have to do something like:

(1) add_hist_entry (sort by keys)
(2) (optionally) hists__collapse_resort (sort by keys)
(3) hists__output_resort (sort by period)
(4) manual resort (by keys)
(5) hists__match/link
(6) (duplicated) hists__output_resort (sort by period)

I think the step (3) and (4) are unnecessary if we use input (or collapsed) tree directly.

Quoted 3 lines

All you need at the output callback is paired leader hist entry.. where you do the temp array magic to get the data.

Yeah, this is what I'm saying. So we don't need to use output tree for matching and linking entries.

Thanks,
Namhyung

author maintainer
#28 lore raw

PATCH 8/18 perf hists: Add hists__{match,link}_collapsed

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

The current hists__match/link functions are worked on the output tree (hists->entries). However for event group view it needs to be matched/linked before the final resort. Thus add new helpers for doing it on the collapsed tree.

Cc Jiri Olsa <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/hist.c | 117 +++++++++++++++++++++++++++++++++++++++++--------
 tools/perf/util/hist.h |   2 +
 2 files changed, 101 insertions(+), 18 deletions(-)
tools/perf/util/hist.c +99 -18
index 161c35e7ed0e..2af8ec6e8e26 100644
@@ -717,19 +717,72 @@ void hists__inc_nr_events(struct hists *hists, u32 type)
 	++hists->stats.nr_events[type];
 }
 
+struct rb_hist_fns {
+	struct rb_root * (*get_rb_root)(struct hists *);
+	struct rb_node * (*get_rb_node)(struct hist_entry *);
+	struct hist_entry * (*get_hist_entry)(struct rb_node *);
+	int64_t (*cmp_hist_entry)(struct hist_entry *, struct hist_entry *);
+};
+
+static struct rb_root *get_output_rb_root(struct hists *hists)
+{
+	return &hists->entries;
+}
+
+static struct rb_node *get_output_rb_node(struct hist_entry *he)
+{
+	return &he->rb_node;
+}
+
+static struct hist_entry *get_output_hist_entry(struct rb_node *node)
+{
+	return rb_entry(node, struct hist_entry, rb_node);
+}
+
+static const struct rb_hist_fns output_fns = {
+	.get_rb_root		= get_output_rb_root,
+	.get_rb_node		= get_output_rb_node,
+	.get_hist_entry		= get_output_hist_entry,
+	.cmp_hist_entry		= hist_entry__cmp,
+};
+
+static struct rb_root *get_collapsed_rb_root(struct hists *hists)
+{
+	return &hists->entries_collapsed;
+}
+
+static struct rb_node *get_collapsed_rb_node(struct hist_entry *he)
+{
+	return &he->rb_node_in;
+}
+
+static struct hist_entry *get_collapsed_hist_entry(struct rb_node *node)
+{
+	return rb_entry(node, struct hist_entry, rb_node_in);
+}
+
+static const struct rb_hist_fns collapsed_fns = {
+	.get_rb_root		= get_collapsed_rb_root,
+	.get_rb_node		= get_collapsed_rb_node,
+	.get_hist_entry		= get_collapsed_hist_entry,
+	.cmp_hist_entry		= hist_entry__collapse,
+};
+
 static struct hist_entry *hists__add_dummy_entry(struct hists *hists,
-						 struct hist_entry *pair)
+						 struct hist_entry *pair,
+						 const struct rb_hist_fns *fns)
 {
-	struct rb_node **p = &hists->entries.rb_node;
+	struct rb_root *root = fns->get_rb_root(hists);
+	struct rb_node **p = &root->rb_node;
 	struct rb_node *parent = NULL;
 	struct hist_entry *he;
 	int cmp;
 
 	while (*p != NULL) {
 		parent = *p;
-		he = rb_entry(parent, struct hist_entry, rb_node);
+		he = fns->get_hist_entry(parent);
 
-		cmp = hist_entry__cmp(pair, he);
+		cmp = fns->cmp_hist_entry(pair, he);
 
 		if (!cmp)
 			goto out;
@@ -742,10 +795,12 @@ static struct hist_entry *hists__add_dummy_entry(struct hists *hists,
 
 	he = hist_entry__new(pair);
 	if (he) {
+		struct rb_node *n = fns->get_rb_node(he);
+
 		memset(&he->stat, 0, sizeof(he->stat));
 		he->hists = hists;
-		rb_link_node(&he->rb_node, parent, p);
-		rb_insert_color(&he->rb_node, &hists->entries);
+		rb_link_node(n, parent, p);
+		rb_insert_color(n, root);
 		hists__inc_nr_entries(hists, he);
 	}
 out:
@@ -753,13 +808,15 @@ out:
 }
 
 static struct hist_entry *hists__find_entry(struct hists *hists,
-					    struct hist_entry *he)
+					    struct hist_entry *he,
+					    const struct rb_hist_fns *fns)
 {
-	struct rb_node *n = hists->entries.rb_node;
+	struct rb_root *root = fns->get_rb_root(hists);
+	struct rb_node *n = root->rb_node;
 
 	while (n) {
-		struct hist_entry *iter = rb_entry(n, struct hist_entry, rb_node);
-		int64_t cmp = hist_entry__cmp(he, iter);
+		struct hist_entry *iter = fns->get_hist_entry(n);
+		int64_t cmp = fns->cmp_hist_entry(he, iter);
 
 		if (cmp < 0)
 			n = n->rb_left;
@@ -775,35 +832,49 @@ static struct hist_entry *hists__find_entry(struct hists *hists,
 /*
  * Look for pairs to link to the leader buckets (hist_entries):
  */
-void hists__match(struct hists *leader, struct hists *other)
+static void __hists__match(struct hists *leader, struct hists *other,
+			   const struct rb_hist_fns *fns)
 {
+	struct rb_root *root = fns->get_rb_root(leader);
 	struct rb_node *nd;
 	struct hist_entry *pos, *pair;
 
-	for (nd = rb_first(&leader->entries); nd; nd = rb_next(nd)) {
-		pos  = rb_entry(nd, struct hist_entry, rb_node);
-		pair = hists__find_entry(other, pos);
+	for (nd = rb_first(root); nd; nd = rb_next(nd)) {
+		pos  = fns->get_hist_entry(nd);
+		pair = hists__find_entry(other, pos, fns);
 
 		if (pair)
 			hist_entry__add_pair(pair, pos);
 	}
 }
 
+void hists__match(struct hists *leader, struct hists *other)
+{
+	__hists__match(leader, other, &output_fns);
+}
+
+void hists__match_collapsed(struct hists *leader, struct hists *other)
+{
+	__hists__match(leader, other, &collapsed_fns);
+}
+
 /*
  * Look for entries in the other hists that are not present in the leader, if
  * we find them, just add a dummy entry on the leader hists, with period=0,
  * nr_events=0, to serve as the list header.
  */
-int hists__link(struct hists *leader, struct hists *other)
+static int __hists__link(struct hists *leader, struct hists *other,
+			 const struct rb_hist_fns *fns)
 {
+	struct rb_root *root = fns->get_rb_root(other);
 	struct rb_node *nd;
 	struct hist_entry *pos, *pair;
 
-	for (nd = rb_first(&other->entries); nd; nd = rb_next(nd)) {
-		pos = rb_entry(nd, struct hist_entry, rb_node);
+	for (nd = rb_first(root); nd; nd = rb_next(nd)) {
+		pos = fns->get_hist_entry(nd);
 
 		if (!hist_entry__has_pairs(pos)) {
-			pair = hists__add_dummy_entry(leader, pos);
+			pair = hists__add_dummy_entry(leader, pos, fns);
 			if (pair == NULL)
 				return -1;
 			hist_entry__add_pair(pos, pair);
@@ -812,3 +883,13 @@ int hists__link(struct hists *leader, struct hists *other)
 
 	return 0;
 }
+
+int hists__link(struct hists *leader, struct hists *other)
+{
+	return __hists__link(leader, other, &output_fns);
+}
+
+int hists__link_collapsed(struct hists *leader, struct hists *other)
+{
+	return __hists__link(leader, other, &collapsed_fns);
+}
tools/perf/util/hist.h +2 -0
index 8b091a51e4a2..43ee5e4fc33e 100644
@@ -116,7 +116,9 @@ void hists__reset_col_len(struct hists *hists);
 void hists__calc_col_len(struct hists *hists, struct hist_entry *he);
 
 void hists__match(struct hists *leader, struct hists *other);
+void hists__match_collapsed(struct hists *leader, struct hists *other);
 int hists__link(struct hists *leader, struct hists *other);
+int hists__link_collapsed(struct hists *leader, struct hists *other);
 
 struct perf_hpp {
 	char *buf;
Signature · 1 line
1.7.11.7
author maintainer
#29 lore raw

PATCH 9/18 perf symbol: Introduce symbol_conf.event_group

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

The event_group field is for enabling event group view on perf report and other commands. It requires collapsing hist entries since every member in a group needs to be linked before final output resorting.

Cc Jiri Olsa <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/symbol.c | 4 ++++
 tools/perf/util/symbol.h | 3 ++-
 2 files changed, 6 insertions(+), 1 deletion(-)
tools/perf/util/symbol.c +4 -0
index 295f8d4feedf..a64b0bf77f32 100644
@@ -15,6 +15,7 @@
 #include "machine.h"
 #include "symbol.h"
 #include "strlist.h"
+#include "sort.h"
 
 #include <elf.h>
 #include <limits.h>
@@ -1650,6 +1651,9 @@ int symbol__init(void)
 
 	symbol_conf.kptr_restrict = symbol__read_kptr_restrict();
 
+	if (symbol_conf.event_group)
+		sort__need_collapse = 1;
+
 	symbol_conf.initialized = true;
 	return 0;
 
tools/perf/util/symbol.h +2 -1
index de68f98b236d..8bef1452675f 100644
@@ -96,7 +96,8 @@ struct symbol_conf {
 			initialized,
 			kptr_restrict,
 			annotate_asm_raw,
-			annotate_src;
+			annotate_src,
+			event_group;
 	const char	*vmlinux_name,
 			*kallsyms_name,
 			*source_prefix,
Signature · 1 line
1.7.11.7
author maintainer
#30 lore raw

PATCH 10/18 perf report: Make another loop for linking group hists

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

Now the event grouping viewing requires linking all member hists in a group to the leader's. Thus hists__output_resort should be called after linking all events in evlist.

Cc Jiri Olsa <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/builtin-report.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
tools/perf/builtin-report.c +12 -1
index fc251005dd3d..13a2cd20a1cd 100644
@@ -416,8 +416,16 @@ static int __cmd_report(struct perf_report *rep)
 			hists->symbol_filter_str = rep->symbol_filter_str;
 
 		hists__collapse_resort(hists);
-		hists__output_resort(hists);
 		nr_samples += hists->stats.nr_events[PERF_RECORD_SAMPLE];
+
+		/* Non-group events are considered as leader */
+		if (symbol_conf.event_group &&
+		    !perf_evsel__is_group_leader(pos)) {
+			struct hists *leader_hists = &pos->leader->hists;
+
+			hists__match_collapsed(leader_hists, hists);
+			hists__link_collapsed(leader_hists, hists);
+		}
 	}
 
 	if (nr_samples == 0) {
@@ -425,6 +433,9 @@ static int __cmd_report(struct perf_report *rep)
 		goto out_delete;
 	}
 
+	list_for_each_entry(pos, &session->evlist->entries, node)
+		hists__output_resort(&pos->hists);
+
 	if (use_browser > 0) {
 		if (use_browser == 1) {
 			perf_evlist__tui_browse_hists(session->evlist, help,
Signature · 1 line
1.7.11.7
author maintainer
#31 lore raw

PATCH 11/18 perf hists: Resort hist entries using group members for output

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

When event group is enabled, sorting hist entries on periods for output should consider groups members' period also. To do that, build period table using link/pair information and compare the table.

Cc Jiri Olsa <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/evsel.h |  2 ++
 tools/perf/util/hist.c  | 59 ++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 60 insertions(+), 1 deletion(-)
tools/perf/util/evsel.h +2 -0
index 887834ed0af1..54a8efbd8dcb 100644
@@ -78,6 +78,8 @@ struct perf_evsel {
 	char			*group_name;
 };
 
+#define hists_to_evsel(h) container_of(h, struct perf_evsel, hists)
+
 struct cpu_map;
 struct thread_map;
 struct perf_evlist;
tools/perf/util/hist.c +58 -1

77 lines not on this page · raw message

Signature · 1 line
1.7.11.7
author maintainer
#32 lore raw

PATCH 12/18 perf ui/hist: Add support for event group view

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

Show group members' overhead also when showing the leader's if event group is enabled. Use macro for defining hpp functions which looks almost identical.

Cc Jiri Olsa <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/ui/hist.c       | 370 +++++++++++++++++++++++----------------------
 tools/perf/ui/stdio/hist.c |   2 +
 2 files changed, 191 insertions(+), 181 deletions(-)
tools/perf/ui/hist.c +189 -181
index aa84130024d5..b42bd15af3f5 100644
@@ -3,152 +3,198 @@
 #include "../util/hist.h"
 #include "../util/util.h"
 #include "../util/sort.h"
-
+#include "../util/evsel.h"
 
 /* hist period print (hpp) functions */
-static int hpp__header_overhead(struct perf_hpp *hpp)
-{
-	return scnprintf(hpp->buf, hpp->size, "Overhead");
-}
-
-static int hpp__width_overhead(struct perf_hpp *hpp __maybe_unused)
-{
-	return 8;
-}
-
-static int hpp__color_overhead(struct perf_hpp *hpp, struct hist_entry *he)
-{
-	struct hists *hists = he->hists;
-	double percent = 100.0 * he->stat.period / hists->stats.total_period;
-
-	return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent);
-}
-
-static int hpp__entry_overhead(struct perf_hpp *hpp, struct hist_entry *he)
-{
-	struct hists *hists = he->hists;
-	double percent = 100.0 * he->stat.period / hists->stats.total_period;
-	const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%%";
-
-	return scnprintf(hpp->buf, hpp->size, fmt, percent);
-}
-
-static int hpp__header_overhead_sys(struct perf_hpp *hpp)
-{
-	const char *fmt = symbol_conf.field_sep ? "%s" : "%7s";
-
-	return scnprintf(hpp->buf, hpp->size, fmt, "sys");
-}
-
-static int hpp__width_overhead_sys(struct perf_hpp *hpp __maybe_unused)
-{
-	return 7;
-}
-
-static int hpp__color_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he)
-{
-	struct hists *hists = he->hists;
-	double percent = 100.0 * he->stat.period_sys / hists->stats.total_period;
-
-	return percent_color_snprintf(hpp->buf, hpp->size, "%6.2f%%", percent);
-}
-
-static int hpp__entry_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he)
-{
-	struct hists *hists = he->hists;
-	double percent = 100.0 * he->stat.period_sys / hists->stats.total_period;
-	const char *fmt = symbol_conf.field_sep ? "%.2f" : "%6.2f%%";
-
-	return scnprintf(hpp->buf, hpp->size, fmt, percent);
-}
-
-static int hpp__header_overhead_us(struct perf_hpp *hpp)
-{
-	const char *fmt = symbol_conf.field_sep ? "%s" : "%7s";
-
-	return scnprintf(hpp->buf, hpp->size, fmt, "user");
-}
-
-static int hpp__width_overhead_us(struct perf_hpp *hpp __maybe_unused)
-{
-	return 7;
-}
-
-static int hpp__color_overhead_us(struct perf_hpp *hpp, struct hist_entry *he)
-{
-	struct hists *hists = he->hists;
-	double percent = 100.0 * he->stat.period_us / hists->stats.total_period;
-
-	return percent_color_snprintf(hpp->buf, hpp->size, "%6.2f%%", percent);
-}
-
-static int hpp__entry_overhead_us(struct perf_hpp *hpp, struct hist_entry *he)
-{
-	struct hists *hists = he->hists;
-	double percent = 100.0 * he->stat.period_us / hists->stats.total_period;
-	const char *fmt = symbol_conf.field_sep ? "%.2f" : "%6.2f%%";
-
-	return scnprintf(hpp->buf, hpp->size, fmt, percent);
-}
-
-static int hpp__header_overhead_guest_sys(struct perf_hpp *hpp)
-{
-	return scnprintf(hpp->buf, hpp->size, "guest sys");
-}
-
-static int hpp__width_overhead_guest_sys(struct perf_hpp *hpp __maybe_unused)
-{
-	return 9;
-}
-
-static int hpp__color_overhead_guest_sys(struct perf_hpp *hpp,
-					 struct hist_entry *he)
-{
-	struct hists *hists = he->hists;
-	double percent = 100.0 * he->stat.period_guest_sys / hists->stats.total_period;
-
-	return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%% ", percent);
-}
-
-static int hpp__entry_overhead_guest_sys(struct perf_hpp *hpp,
-					 struct hist_entry *he)
-{
-	struct hists *hists = he->hists;
-	double percent = 100.0 * he->stat.period_guest_sys / hists->stats.total_period;
-	const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%% ";
-
-	return scnprintf(hpp->buf, hpp->size, fmt, percent);
-}
-
-static int hpp__header_overhead_guest_us(struct perf_hpp *hpp)
-{
-	return scnprintf(hpp->buf, hpp->size, "guest usr");
-}
-
-static int hpp__width_overhead_guest_us(struct perf_hpp *hpp __maybe_unused)
-{
-	return 9;
-}
-
-static int hpp__color_overhead_guest_us(struct perf_hpp *hpp,
-					struct hist_entry *he)
-{
-	struct hists *hists = he->hists;
-	double percent = 100.0 * he->stat.period_guest_us / hists->stats.total_period;
-
-	return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%% ", percent);
-}
-
-static int hpp__entry_overhead_guest_us(struct perf_hpp *hpp,
-					struct hist_entry *he)
-{
-	struct hists *hists = he->hists;
-	double percent = 100.0 * he->stat.period_guest_us / hists->stats.total_period;
-	const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%% ";
-
-	return scnprintf(hpp->buf, hpp->size, fmt, percent);
-}
 
+#define __HPP_HEADER_FN(_type, _str, _min_width, _unit_width) 		\
+static int hpp__header_##_type(struct perf_hpp *hpp)			\
+{									\
+	int len = _min_width;						\
+									\
+	if (symbol_conf.event_group) {					\
+		struct perf_evsel *evsel = hpp->ptr;			\
+									\
+		len = max(len, evsel->nr_members * _unit_width);	\
+	}								\
+	return scnprintf(hpp->buf, hpp->size, "%*s", len, _str);	\
+}
+
+#define __HPP_WIDTH_FN(_type, _min_width, _unit_width) 			\
+static int hpp__width_##_type(struct perf_hpp *hpp)			\
+{									\
+	int len = _min_width;						\
+									\
+	if (symbol_conf.event_group) {					\
+		struct perf_evsel *evsel = hpp->ptr;			\
+									\
+		len = max(len, evsel->nr_members * _unit_width);	\
+	}								\
+	return len;							\
+}
+
+#define __HPP_COLOR_PERCENT_FN(_type, _field)					\
+static int hpp__color_##_type(struct perf_hpp *hpp, struct hist_entry *he) 	\
+{										\
+	int ret;								\
+	double percent = 0.0;							\
+	struct hists *hists = he->hists;					\
+										\
+	if (hists->stats.total_period)						\
+		percent = 100.0 * he->stat._field / hists->stats.total_period; 	\
+										\
+	ret = percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent);	\
+										\
+	if (symbol_conf.event_group) {						\
+		int i;								\
+		struct perf_evsel *evsel = hists_to_evsel(hists);		\
+		struct hist_entry *pair;					\
+		int nr_members = evsel->nr_members;				\
+		double *percents;						\
+										\
+		if (nr_members <= 1)						\
+			return ret;						\
+										\
+		percents = zalloc(sizeof(*percents) * nr_members);		\
+		if (percents == NULL) {						\
+			pr_warning("Not enough memory!\n");			\
+			return ret;						\
+		}								\
+										\
+		list_for_each_entry(pair, &he->pairs.head, pairs.node) { 	\
+			u64 period = pair->stat._field;				\
+			u64 total = pair->hists->stats.total_period;		\
+										\
+			if (!total)						\
+				continue;					\
+										\
+			evsel = hists_to_evsel(pair->hists);			\
+			i = perf_evsel__group_idx(evsel);			\
+			percents[i] = 100.0 * period / total;			\
+		}								\
+										\
+		for (i = 1; i < nr_members; i++) {				\
+			ret += percent_color_snprintf(hpp->buf + ret,		\
+						      hpp->size - ret,		\
+						      " %6.2f%%", percents[i]);	\
+		}								\
+		free(percents);							\
+	}									\
+	return ret;								\
+}
+
+#define __HPP_ENTRY_PERCENT_FN(_type, _field)					\
+static int hpp__entry_##_type(struct perf_hpp *hpp, struct hist_entry *he) 	\
+{										\
+	int ret;								\
+	double percent = 0.0;							\
+	struct hists *hists = he->hists;					\
+	const char *fmt = symbol_conf.field_sep ? " %.2f" : " %6.2f%%";		\
+										\
+	if (hists->stats.total_period)						\
+		percent = 100.0 * he->stat._field / hists->stats.total_period; 	\
+										\
+	ret = scnprintf(hpp->buf, hpp->size, fmt, percent);			\
+										\
+	if (symbol_conf.event_group) {						\
+		int i;								\
+		struct perf_evsel *evsel = hists_to_evsel(hists);		\
+		struct hist_entry *pair;					\
+		int nr_members = evsel->nr_members;				\
+		double *percents;						\
+										\
+		if (nr_members <= 1)						\
+			return ret;						\
+										\
+		percents = zalloc(sizeof(*percents) * nr_members);		\
+		if (percents == NULL) {						\
+			pr_warning("Not enough memory!\n");			\
+			return ret;						\
+		}								\
+										\
+		list_for_each_entry(pair, &he->pairs.head, pairs.node) { 	\
+			u64 period = pair->stat._field;				\
+			u64 total = pair->hists->stats.total_period;		\
+										\
+			if (!total)						\
+				continue;					\
+										\
+			evsel = hists_to_evsel(pair->hists);			\
+			i = perf_evsel__group_idx(evsel);			\
+			percents[i] = 100.0 * period / total;			\
+		}								\
+										\
+		for (i = 1; i < nr_members; i++) {				\
+			ret += scnprintf(hpp->buf + ret, hpp->size - ret,	\
+					 fmt, percents[i]);			\
+		}								\
+		free(percents);							\
+	}									\
+	return ret;								\
+}
+
+#define __HPP_ENTRY_RAW_FN(_type, _field)					\
+static int hpp__entry_##_type(struct perf_hpp *hpp, struct hist_entry *he) 	\
+{										\
+	int ret;								\
+	const char *fmt = symbol_conf.field_sep ? " %"PRIu64 : " %11"PRIu64; 	\
+										\
+	ret = scnprintf(hpp->buf, hpp->size, fmt, he->stat._field);		\
+										\
+	if (symbol_conf.event_group) {						\
+		int i;								\
+		struct perf_evsel *evsel = hists_to_evsel(he->hists);		\
+		struct hist_entry *pair;					\
+		int nr_members = evsel->nr_members;				\
+		u64 *numbers;							\
+										\
+		if (nr_members <= 1)						\
+			return ret;						\
+										\
+		numbers = zalloc(sizeof(*numbers) * nr_members);		\
+		if (numbers == NULL) {						\
+			pr_warning("Not enough memory!\n");			\
+			return ret;						\
+		}								\
+										\
+		list_for_each_entry(pair, &he->pairs.head, pairs.node) { 	\
+			evsel = hists_to_evsel(pair->hists);			\
+			i = perf_evsel__group_idx(evsel);			\
+			numbers[i] = pair->stat._field;				\
+		}								\
+										\
+		for (i = 1; i < nr_members; i++) {				\
+			ret += scnprintf(hpp->buf + ret, hpp->size - ret,	\
+					 fmt, numbers[i]);			\
+		}								\
+		free(numbers);							\
+	}									\
+	return ret;								\
+}
+
+#define HPP_PERCENT_FNS(_type, _str, _field, _min_width, _unit_width)	\
+__HPP_HEADER_FN(_type, _str, _min_width, _unit_width)			\
+__HPP_WIDTH_FN(_type, _min_width, _unit_width)				\
+__HPP_COLOR_PERCENT_FN(_type, _field)					\
+__HPP_ENTRY_PERCENT_FN(_type, _field)
+
+#define HPP_RAW_FNS(_type, _str, _field, _min_width, _unit_width)	\
+__HPP_HEADER_FN(_type, _str, _min_width, _unit_width)			\
+__HPP_WIDTH_FN(_type, _min_width, _unit_width)				\
+__HPP_ENTRY_RAW_FN(_type, _field)
+
+
+HPP_PERCENT_FNS(overhead, "Overhead", period, 8, 8)
+HPP_PERCENT_FNS(overhead_sys, "sys", period_sys, 8, 8)
+HPP_PERCENT_FNS(overhead_us, "usr", period_sys, 8, 8)
+HPP_PERCENT_FNS(overhead_guest_sys, "guest sys", period_sys, 9, 8)
+HPP_PERCENT_FNS(overhead_guest_us, "guest usr", period_sys, 9, 8)
+
+HPP_RAW_FNS(samples, "Samples", nr_events, 12, 12)
+HPP_RAW_FNS(period, "Period", period, 12, 12)
+
+
+/* diff-specific hpp functions */
 static int hpp__header_baseline(struct perf_hpp *hpp)
 {
 	return scnprintf(hpp->buf, hpp->size, "Baseline");
@@ -196,44 +242,6 @@ static int hpp__entry_baseline(struct perf_hpp *hpp, struct hist_entry *he)
 		return scnprintf(hpp->buf, hpp->size, "            ");
 }
 
-static int hpp__header_samples(struct perf_hpp *hpp)
-{
-	const char *fmt = symbol_conf.field_sep ? "%s" : "%11s";
-
-	return scnprintf(hpp->buf, hpp->size, fmt, "Samples");
-}
-
-static int hpp__width_samples(struct perf_hpp *hpp __maybe_unused)
-{
-	return 11;
-}
-
-static int hpp__entry_samples(struct perf_hpp *hpp, struct hist_entry *he)
-{
-	const char *fmt = symbol_conf.field_sep ? "%" PRIu64 : "%11" PRIu64;
-
-	return scnprintf(hpp->buf, hpp->size, fmt, he->stat.nr_events);
-}
-
-static int hpp__header_period(struct perf_hpp *hpp)
-{
-	const char *fmt = symbol_conf.field_sep ? "%s" : "%12s";
-
-	return scnprintf(hpp->buf, hpp->size, fmt, "Period");
-}
-
-static int hpp__width_period(struct perf_hpp *hpp __maybe_unused)
-{
-	return 12;
-}
-
-static int hpp__entry_period(struct perf_hpp *hpp, struct hist_entry *he)
-{
-	const char *fmt = symbol_conf.field_sep ? "%" PRIu64 : "%12" PRIu64;
-
-	return scnprintf(hpp->buf, hpp->size, fmt, he->stat.period);
-}
-
 static int hpp__header_period_baseline(struct perf_hpp *hpp)
 {
 	const char *fmt = symbol_conf.field_sep ? "%s" : "%12s";
tools/perf/ui/stdio/hist.c +2 -0
index f0ee204f99bb..07421d6da5a2 100644
@@ -3,6 +3,7 @@
 #include "../../util/util.h"
 #include "../../util/hist.h"
 #include "../../util/sort.h"
+#include "../../util/evsel.h"
 
 
 static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)
@@ -346,6 +347,7 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
 	struct perf_hpp dummy_hpp = {
 		.buf	= bf,
 		.size	= sizeof(bf),
+		.ptr	= hists_to_evsel(hists),
 	};
 	bool first = true;
 
Signature · 1 line
1.7.11.7

A message that is not in the archive (sent off-list or not yet received): [email protected]

#34 lore raw

Re: [PATCH 12/18] perf ui/hist: Add support for event group view

Em Fri, Nov 30, 2012 at 02:29:43PM +0100, Jiri Olsa escreveu:

Quoted 20 lines · Namhyung Kim
Quoted 19 lines
tools/perf/ui/hist.c +19 -0
+#define __HPP_COLOR_PERCENT_FN(_type, _field)					\
+static int hpp__color_##_type(struct perf_hpp *hpp, struct hist_entry *he) 	\
+{										\
+	int ret;								\
+	double percent = 0.0;							\
+	struct hists *hists = he->hists;					\
+										\
+	if (hists->stats.total_period)						\
+		percent = 100.0 * he->stat._field / hists->stats.total_period; 	\
+										\
+	ret = percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent);	\
+										\
+	if (symbol_conf.event_group) {						\
+		int i;								\
+		struct perf_evsel *evsel = hists_to_evsel(hists);		\
+		struct hist_entry *pair;					\
+		int nr_members = evsel->nr_members;				\
+		double *percents;						\
+										\
Quoted 8 lines

tools/perf/ui/hist.c line 62

Quoted 8 lines
tools/perf/ui/hist.c +8 -0
+		if (nr_members <= 1)						\
+			return ret;						\
+										\
+		percents = zalloc(sizeof(*percents) * nr_members);		\
+		if (percents == NULL) {						\
+			pr_warning("Not enough memory!\n");			\
+			return ret;						\
+		}								\

Why do we need to zalloc this percents array?

Quoted 10 lines

tools/perf/ui/hist.c line 73

Quoted 10 lines
tools/perf/ui/hist.c +10 -0
+		list_for_each_entry(pair, &he->pairs.head, pairs.node) { 	\
+			u64 period = pair->stat._field;				\
+			u64 total = pair->hists->stats.total_period;		\
+										\
+			if (!total)						\
+				continue;					\
+										\
+			evsel = hists_to_evsel(pair->hists);			\
+			i = perf_evsel__group_idx(evsel);			\
+			percents[i] = 100.0 * period / total;			\

Why not use percent_color_snprintf here, using some "%*s" thing that uses i to position the output in the right column? This way the following loop can be ditched as well. No?

Quoted 10 lines

tools/perf/ui/hist.c line 83

Quoted 10 lines
tools/perf/ui/hist.c +10 -0
+		}								\
+										\
+		for (i = 1; i < nr_members; i++) {				\
+			ret += percent_color_snprintf(hpp->buf + ret,		\
+						      hpp->size - ret,		\
+						      " %6.2f%%", percents[i]);	\
+		}								\
+		free(percents);							\
+	}									\
+	return ret;								\

- Arnaldo

author maintainer
#35 lore raw

Re: [PATCH 12/18] perf ui/hist: Add support for event group view

Quoted 32 lines · Arnaldo Carvalho de Melo

Em Fri, Nov 30, 2012 at 02:29:43PM +0100, Jiri Olsa escreveu:

Quoted 20 lines · Namhyung Kim
Quoted 19 lines
tools/perf/ui/hist.c +19 -0
+#define __HPP_COLOR_PERCENT_FN(_type, _field)					\
+static int hpp__color_##_type(struct perf_hpp *hpp, struct hist_entry *he) 	\
+{										\
+	int ret;								\
+	double percent = 0.0;							\
+	struct hists *hists = he->hists;					\
+										\
+	if (hists->stats.total_period)						\
+		percent = 100.0 * he->stat._field / hists->stats.total_period; 	\
+										\
+	ret = percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent);	\
+										\
+	if (symbol_conf.event_group) {						\
+		int i;								\
+		struct perf_evsel *evsel = hists_to_evsel(hists);		\
+		struct hist_entry *pair;					\
+		int nr_members = evsel->nr_members;				\
+		double *percents;						\
+										\
Quoted 8 lines

tools/perf/ui/hist.c line 62

Quoted 8 lines
tools/perf/ui/hist.c +8 -0
+		if (nr_members <= 1)						\
+			return ret;						\
+										\
+		percents = zalloc(sizeof(*percents) * nr_members);		\
+		if (percents == NULL) {						\
+			pr_warning("Not enough memory!\n");			\
+			return ret;						\
+		}								\

Why do we need to zalloc this percents array?

Quoted 14 lines
Quoted 10 lines

tools/perf/ui/hist.c line 73

Quoted 10 lines
tools/perf/ui/hist.c +10 -0
+		list_for_each_entry(pair, &he->pairs.head, pairs.node) { 	\
+			u64 period = pair->stat._field;				\
+			u64 total = pair->hists->stats.total_period;		\
+										\
+			if (!total)						\
+				continue;					\
+										\
+			evsel = hists_to_evsel(pair->hists);			\
+			i = perf_evsel__group_idx(evsel);			\
+			percents[i] = 100.0 * period / total;			\

Why not use percent_color_snprintf here, using some "%*s" thing that uses i to position the output in the right column? This way the following loop can be ditched as well. No?

It's because it's possible that an entry didn't have pairs for every group member. Say, there's a group consists of 3 members (1 leader + 2 member). It's quite legitimate that a leader hist entry has just one pair for a member and miss another. So I allocated a zero-filled array, and filled what it has, and print them all in the for loop below.

Thanks,
Namhyung

Quoted 13 lines
Quoted 11 lines

tools/perf/ui/hist.c line 83

Quoted 11 lines
tools/perf/ui/hist.c +10 -0
+		}								\
+										\
+		for (i = 1; i < nr_members; i++) {				\
+			ret += percent_color_snprintf(hpp->buf + ret,		\
+						      hpp->size - ret,		\
+						      " %6.2f%%", percents[i]);	\
+		}								\
+		free(percents);							\
+	}									\
+	return ret;								\

- Arnaldo

author maintainer
#36 lore raw

Re: [PATCH 12/18] perf ui/hist: Add support for event group view

In reply to Arnaldo Carvalho de Melo
Quoted 58 lines · Arnaldo Carvalho de Melo

Em Fri, Nov 30, 2012 at 02:29:43PM +0100, Jiri Olsa escreveu:

Quoted 20 lines · Namhyung Kim
Quoted 19 lines
tools/perf/ui/hist.c +19 -0
+#define __HPP_COLOR_PERCENT_FN(_type, _field)                                      \
+static int hpp__color_##_type(struct perf_hpp *hpp, struct hist_entry *he)         \
+{                                                                          \
+   int ret;                                                                \
+   double percent = 0.0;                                                   \
+   struct hists *hists = he->hists;                                        \
+                                                                           \
+   if (hists->stats.total_period)                                          \
+           percent = 100.0 * he->stat._field / hists->stats.total_period;  \
+                                                                           \
+   ret = percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent); \
+                                                                           \
+   if (symbol_conf.event_group) {                                          \
+           int i;                                                          \
+           struct perf_evsel *evsel = hists_to_evsel(hists);               \
+           struct hist_entry *pair;                                        \
+           int nr_members = evsel->nr_members;                             \
+           double *percents;                                               \
+                                                                           \
Quoted 8 lines

tools/perf/ui/hist.c line 62

Quoted 8 lines
tools/perf/ui/hist.c +8 -0
+           if (nr_members <= 1)                                            \
+                   return ret;                                             \
+                                                                           \
+           percents = zalloc(sizeof(*percents) * nr_members);              \
+           if (percents == NULL) {                                         \
+                   pr_warning("Not enough memory!\n");                     \
+                   return ret;                                             \
+           }                                                               \

Why do we need to zalloc this percents array?

Quoted 10 lines

tools/perf/ui/hist.c line 73

Quoted 10 lines
tools/perf/ui/hist.c +10 -0
+           list_for_each_entry(pair, &he->pairs.head, pairs.node) {        \
+                   u64 period = pair->stat._field;                         \
+                   u64 total = pair->hists->stats.total_period;            \
+                                                                           \
+                   if (!total)                                             \
+                           continue;                                       \
+                                                                           \
+                   evsel = hists_to_evsel(pair->hists);                    \
+                   i = perf_evsel__group_idx(evsel);                       \
+                   percents[i] = 100.0 * period / total;                   \

Why not use percent_color_snprintf here, using some "%*s" thing that uses i to position the output in the right column? This way the following loop can be ditched as well. No?

Quoted 10 lines

tools/perf/ui/hist.c line 83

Quoted 10 lines
tools/perf/ui/hist.c +10 -0
+           }                                                               \
+                                                                           \
+           for (i = 1; i < nr_members; i++) {                              \
+                   ret += percent_color_snprintf(hpp->buf + ret,           \
+                                                 hpp->size - ret,          \
+                                                 " %6.2f%%", percents[i]); \
+           }                                                               \
+           free(percents);                                                 \
+   }                                                                       \
+   return ret;                                                             \
Quoted 1 line

- Arnaldo

Ah, I missed your point. Just got it now, will try this approach. So you want to see no "0.00%" for a dummy entry, right?

Thanks,
Namhyung

#37 lore raw

Re: [PATCH 12/18] perf ui/hist: Add support for event group view

Em Tue, Dec 04, 2012 at 06:16:59PM +0900, Namhyung Kim escreveu:

Quoted 4 lines · Arnaldo Carvalho de Melo

Ah, I missed your point. Just got it now, will try this approach. So you want to see no "0.00%" for a dummy entry, right?

That wasn't the point, and perhaps printing 0.00% pollutes the screen needlessly or may be a help in seeing the columns more clearly, no strong opinion at this point, please experiment.

The point was that there seems to be no need for the temporary array.

- Arnaldo

author maintainer
#38 lore raw

Re: [PATCH 12/18] perf ui/hist: Add support for event group view

Hi Arnaldo,

Quoted 11 lines · Arnaldo Carvalho de Melo

Em Tue, Dec 04, 2012 at 06:16:59PM +0900, Namhyung Kim escreveu:

Quoted 4 lines · Arnaldo Carvalho de Melo

Ah, I missed your point. Just got it now, will try this approach. So you want to see no "0.00%" for a dummy entry, right?

That wasn't the point, and perhaps printing 0.00% pollutes the screen needlessly or may be a help in seeing the columns more clearly, no strong opinion at this point, please experiment.

The point was that there seems to be no need for the temporary array.

Yeah, it shows my really bad writing skill. :(

I meant I got your point of not using a temporary array. And asked additional question of your preference in a dummy entry.

Sorry for confusing you.

Btw, I found that printing 0.00% is useful for a case of field_sep and GTK+ output. So unless someone objects, I'll keep it.

Thanks,
Namhyung

author maintainer
#39 lore raw

Re: [PATCH 12/18] perf ui/hist: Add support for event group view

In reply to a message not in the archive

Hi Jiri,

Quoted 107 lines · Jiri Olsa

On Thu, Nov 29, 2012 at 03:38:40PM +0900, Namhyung Kim wrote:

SNIP

Quoted 39 lines
tools/perf/ui/hist.c +39 -0
+#define __HPP_COLOR_PERCENT_FN(_type, _field)                                        \
+static int hpp__color_##_type(struct perf_hpp *hpp, struct hist_entry *he)   \
+{                                                                            \
+     int ret;                                                                \
+     double percent = 0.0;                                                   \
+     struct hists *hists = he->hists;                                        \
+                                                                             \
+     if (hists->stats.total_period)                                          \
+             percent = 100.0 * he->stat._field / hists->stats.total_period;  \
+                                                                             \
+     ret = percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent); \
+                                                                             \
+     if (symbol_conf.event_group) {                                          \
+             int i;                                                          \
+             struct perf_evsel *evsel = hists_to_evsel(hists);               \
+             struct hist_entry *pair;                                        \
+             int nr_members = evsel->nr_members;                             \
+             double *percents;                                               \
+                                                                             \
+             if (nr_members <= 1)                                            \
+                     return ret;                                             \
+                                                                             \
+             percents = zalloc(sizeof(*percents) * nr_members);              \
+             if (percents == NULL) {                                         \
+                     pr_warning("Not enough memory!\n");                     \
+                     return ret;                                             \
+             }                                                               \
+                                                                             \
+             list_for_each_entry(pair, &he->pairs.head, pairs.node) {        \
+                     u64 period = pair->stat._field;                         \
+                     u64 total = pair->hists->stats.total_period;            \
+                                                                             \
+                     if (!total)                                             \
+                             continue;                                       \
+                                                                             \
+                     evsel = hists_to_evsel(pair->hists);                    \
+                     i = perf_evsel__group_idx(evsel);                       \
+                     percents[i] = 100.0 * period / total;                   \
+             }                                                               \

tools/perf/ui/hist.c line 84

Quoted 10 lines
tools/perf/ui/hist.c +10 -0
+                                                                             \
+             for (i = 1; i < nr_members; i++) {                              \
+                     ret += percent_color_snprintf(hpp->buf + ret,           \
+                                                   hpp->size - ret,          \
+                                                   " %6.2f%%", percents[i]); \
+             }                                                               \
+             free(percents);                                                 \
+     }                                                                       \
+     return ret;                                                             \
+}

ok, so this is the part thats common for both multi diff and group report and hugely depends on how we link matching hist_entry

To sum to what group report does here:

1) starting with event group
2) the function 'he' belongs to leader hists
3) display leaders data value
4) if 'symbol_conf.event_group' is enabled, we want to display all group members data values in a column
5) say we have group of 3 events 'e1,e2,e3' and e1 being the leader, we have following possibilities:
- e1 have no pairs
- e1 is paired with e2
- e1 is paired with e3
- e1 is paired with e2 and e3 (e1 could also be dummy one)
6) need to display 3 values wrt to e1,e2,e3 output order
7) because events belongs to a group, each evsel carries group idx
8) so we walk all pairs and compute the eX value and put it into temporary array based on its group idx
9) finally we display all temporary array values

To sum up what multi diff needs to do here:

1) starting with 3 separate matching events from different evlists(sessions)
2 - 5) are similar
6) need to display single diff value of hist_entry that belongs to evsel, that belongs to a column we are just displaying value for
7) events are not part of group; based on
[PATCH 02/14] perf tool: Add struct perf_hpp_fmt into hpp callbacks we can tell what column we are in -> session -> evlist
8) we need to walk all pairs and for each hist_entry:
- compare all evsels (from point 7 evlist)
and match hists pointer
- when found, we have a matching hist_entry for this column
9) print out the value of matching hist_entry

I think both this processing could be simplified by having hist_entry pairs connected via array and not linked list.

For group report, each leader hist_entry would have 'pairs' array with the size of event group. Then we could omit the temporary array creation by:
- walking the leaders pairs
- when pair is found -> compute data -> display
- when pair is NULL -> display 0

Quoted 7 lines

For multi diff, each baseline hist_entry would have 'pairs' array with the size equal to number of data files on diff command input. This way we could use the data from point 7 to directly access related hist_entry.

ufff... thoughts? ;-)

Nice summary, really! :)

Yeah, I do think it's better to use array for this. If Arnaldo has no objection to this approach, I'll convert my code to use the array.

And please see my another post for thoughts on the hists__{link,match} too. ;-)

Thanks,
Namhyung

#40 lore raw

Re: [PATCH 12/18] perf ui/hist: Add support for event group view

Quoted 116 lines · Namhyung Kim

Hi Jiri,

Quoted 113 lines · Jiri Olsa

On Thu, Nov 29, 2012 at 03:38:40PM +0900, Namhyung Kim wrote:

SNIP

Quoted 39 lines
tools/perf/ui/hist.c +39 -0
+#define __HPP_COLOR_PERCENT_FN(_type, _field)                                        \
+static int hpp__color_##_type(struct perf_hpp *hpp, struct hist_entry *he)   \
+{                                                                            \
+     int ret;                                                                \
+     double percent = 0.0;                                                   \
+     struct hists *hists = he->hists;                                        \
+                                                                             \
+     if (hists->stats.total_period)                                          \
+             percent = 100.0 * he->stat._field / hists->stats.total_period;  \
+                                                                             \
+     ret = percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent); \
+                                                                             \
+     if (symbol_conf.event_group) {                                          \
+             int i;                                                          \
+             struct perf_evsel *evsel = hists_to_evsel(hists);               \
+             struct hist_entry *pair;                                        \
+             int nr_members = evsel->nr_members;                             \
+             double *percents;                                               \
+                                                                             \
+             if (nr_members <= 1)                                            \
+                     return ret;                                             \
+                                                                             \
+             percents = zalloc(sizeof(*percents) * nr_members);              \
+             if (percents == NULL) {                                         \
+                     pr_warning("Not enough memory!\n");                     \
+                     return ret;                                             \
+             }                                                               \
+                                                                             \
+             list_for_each_entry(pair, &he->pairs.head, pairs.node) {        \
+                     u64 period = pair->stat._field;                         \
+                     u64 total = pair->hists->stats.total_period;            \
+                                                                             \
+                     if (!total)                                             \
+                             continue;                                       \
+                                                                             \
+                     evsel = hists_to_evsel(pair->hists);                    \
+                     i = perf_evsel__group_idx(evsel);                       \
+                     percents[i] = 100.0 * period / total;                   \
+             }                                                               \

tools/perf/ui/hist.c line 84

Quoted 10 lines
tools/perf/ui/hist.c +10 -0
+                                                                             \
+             for (i = 1; i < nr_members; i++) {                              \
+                     ret += percent_color_snprintf(hpp->buf + ret,           \
+                                                   hpp->size - ret,          \
+                                                   " %6.2f%%", percents[i]); \
+             }                                                               \
+             free(percents);                                                 \
+     }                                                                       \
+     return ret;                                                             \
+}

ok, so this is the part thats common for both multi diff and group report and hugely depends on how we link matching hist_entry

To sum to what group report does here:

1) starting with event group
2) the function 'he' belongs to leader hists
3) display leaders data value
4) if 'symbol_conf.event_group' is enabled, we want to display all group members data values in a column
5) say we have group of 3 events 'e1,e2,e3' and e1 being the leader, we have following possibilities:
- e1 have no pairs
- e1 is paired with e2
- e1 is paired with e3
- e1 is paired with e2 and e3 (e1 could also be dummy one)
6) need to display 3 values wrt to e1,e2,e3 output order
7) because events belongs to a group, each evsel carries group idx
8) so we walk all pairs and compute the eX value and put it into temporary array based on its group idx
9) finally we display all temporary array values

To sum up what multi diff needs to do here:

1) starting with 3 separate matching events from different evlists(sessions)
2 - 5) are similar
6) need to display single diff value of hist_entry that belongs to evsel, that belongs to a column we are just displaying value for
7) events are not part of group; based on
[PATCH 02/14] perf tool: Add struct perf_hpp_fmt into hpp callbacks we can tell what column we are in -> session -> evlist
8) we need to walk all pairs and for each hist_entry:
- compare all evsels (from point 7 evlist)
and match hists pointer
- when found, we have a matching hist_entry for this column
9) print out the value of matching hist_entry

I think both this processing could be simplified by having hist_entry pairs connected via array and not linked list.

For group report, each leader hist_entry would have 'pairs' array with the size of event group. Then we could omit the temporary array creation by:
- walking the leaders pairs
- when pair is found -> compute data -> display
- when pair is NULL -> display 0

For multi diff, each baseline hist_entry would have 'pairs' array with the size equal to number of data files on diff command input. This way we could use the data from point 7 to directly access related hist_entry.

Quoted 6 lines
Quoted 1 line

ufff... thoughts? ;-)

Nice summary, really! :)

Yeah, I do think it's better to use array for this. If Arnaldo has no objection to this approach, I'll convert my code to use the array.

we discussed with Arnaldo and decided to stay with current approach and make the change later if needed.. to be able to see/meassure the benefit

I made some initial attempt to workaround this and it appears to be not that bad ;) I'll repost my changes shortly..

Quoted 2 lines

And please see my another post for thoughts on the hists__{link,match} too. ;-)

yep, answered ;)

thanks,
jirka

author maintainer
#41 lore raw

Re: [PATCH 12/18] perf ui/hist: Add support for event group view

Quoted 65 lines · Jiri Olsa
Quoted 64 lines · Namhyung Kim
Quoted 53 lines · Jiri Olsa

ok, so this is the part thats common for both multi diff and group report and hugely depends on how we link matching hist_entry

To sum to what group report does here:

1) starting with event group
2) the function 'he' belongs to leader hists
3) display leaders data value
4) if 'symbol_conf.event_group' is enabled, we want to display all group members data values in a column
5) say we have group of 3 events 'e1,e2,e3' and e1 being the leader, we have following possibilities:
- e1 have no pairs
- e1 is paired with e2
- e1 is paired with e3
- e1 is paired with e2 and e3 (e1 could also be dummy one)
6) need to display 3 values wrt to e1,e2,e3 output order
7) because events belongs to a group, each evsel carries group idx
8) so we walk all pairs and compute the eX value and put it into temporary array based on its group idx
9) finally we display all temporary array values

To sum up what multi diff needs to do here:

1) starting with 3 separate matching events from different evlists(sessions)
2 - 5) are similar
6) need to display single diff value of hist_entry that belongs to evsel, that belongs to a column we are just displaying value for
7) events are not part of group; based on
[PATCH 02/14] perf tool: Add struct perf_hpp_fmt into hpp callbacks we can tell what column we are in -> session -> evlist
8) we need to walk all pairs and for each hist_entry:
- compare all evsels (from point 7 evlist)
and match hists pointer
- when found, we have a matching hist_entry for this column
9) print out the value of matching hist_entry

I think both this processing could be simplified by having hist_entry pairs connected via array and not linked list.

For group report, each leader hist_entry would have 'pairs' array with the size of event group. Then we could omit the temporary array creation by:
- walking the leaders pairs
- when pair is found -> compute data -> display
- when pair is NULL -> display 0

Quoted 7 lines

For multi diff, each baseline hist_entry would have 'pairs' array with the size equal to number of data files on diff command input. This way we could use the data from point 7 to directly access related hist_entry.

ufff... thoughts? ;-)

Nice summary, really! :)

Quoted 8 lines
Quoted 2 lines

Yeah, I do think it's better to use array for this. If Arnaldo has no objection to this approach, I'll convert my code to use the array.

we discussed with Arnaldo and decided to stay with current approach and make the change later if needed.. to be able to see/meassure the benefit

I made some initial attempt to workaround this and it appears to be not that bad ;) I'll repost my changes shortly..

Hmm.. so are you OK with this patch now?

Thanks,
Namhyung

#42 lore raw

Re: [PATCH 12/18] perf ui/hist: Add support for event group view

Quoted 5 lines · Namhyung Kim
Quoted 4 lines · Jiri Olsa
Quoted 3 lines · Namhyung Kim
Quoted 2 lines · Jiri Olsa

ok, so this is the part thats common for both multi diff and group report and hugely depends on how we link matching hist_entry

SNIP

Quoted 7 lines
Quoted 5 lines

we discussed with Arnaldo and decided to stay with current approach and make the change later if needed.. to be able to see/meassure the benefit

I made some initial attempt to workaround this and it appears to be not that bad ;) I'll repost my changes shortly..

Hmm.. so are you OK with this patch now?

yep, well except for following macros:

	__HPP_COLOR_PERCENT_FN
	__HPP_ENTRY_PERCENT_FN
	__HPP_ENTRY_RAW_FN

being so long.. any chance the main part of it being in function?

Seems like '_type' is just in function name, but the '_field' might be the killer ;) maybe it could be 'used' in such function via PERF_HPP__* enums instead..?

thanks,
jirka

author maintainer
#43 lore raw

Re: [PATCH 12/18] perf ui/hist: Add support for event group view

Quoted 23 lines · Jiri Olsa
Quoted 5 lines · Namhyung Kim
Quoted 4 lines · Jiri Olsa
Quoted 3 lines · Namhyung Kim
Quoted 2 lines · Jiri Olsa

ok, so this is the part thats common for both multi diff and group report and hugely depends on how we link matching hist_entry

SNIP

Quoted 7 lines
Quoted 5 lines

we discussed with Arnaldo and decided to stay with current approach and make the change later if needed.. to be able to see/meassure the benefit

I made some initial attempt to workaround this and it appears to be not that bad ;) I'll repost my changes shortly..

Hmm.. so are you OK with this patch now?

yep, well except for following macros:

	__HPP_COLOR_PERCENT_FN
	__HPP_ENTRY_PERCENT_FN
	__HPP_ENTRY_RAW_FN
Quoted 5 lines

being so long.. any chance the main part of it being in function?

Seems like '_type' is just in function name, but the '_field' might be the killer ;) maybe it could be 'used' in such function via PERF_HPP__* enums instead..?

Okay, I'll re-think about it tomorrow.

Thanks,
Namhyung

author maintainer
#44 lore raw

PATCH 13/18 perf hist browser: Add support for event group view

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

Show group members' overhead also when showing the leader's if event group is enabled. Use macro for defining hpp functions which looks almost identical.

Cc Jiri Olsa <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/ui/browsers/hists.c | 171 ++++++++++++++++++++++++++++++++++-------
 tools/perf/ui/hist.c           |   5 +-
 2 files changed, 146 insertions(+), 30 deletions(-)
tools/perf/ui/browsers/hists.c +142 -29
index ccc4bd161420..7ac47adc8e09 100644
@@ -567,23 +567,145 @@ static int hist_browser__show_callchain(struct hist_browser *browser,
 	return row - first_row;
 }
 
-#define HPP__COLOR_FN(_name, _field)					\
-static int hist_browser__hpp_color_ ## _name(struct perf_hpp *hpp,	\
-					     struct hist_entry *he)	\
-{									\
-	struct hists *hists = he->hists;				\
-	double percent = 100.0 * he->stat._field / hists->stats.total_period; \
-	*(double *)hpp->ptr = percent;					\
-	return scnprintf(hpp->buf, hpp->size, "%6.2f%%", percent);	\
+struct hpp_arg {
+	struct ui_browser *b;
+	char folded_sign;
+	bool current_entry;
+};
+
+static int hist_browser__hpp_color_overhead(struct perf_hpp *hpp,
+					    struct hist_entry *he)
+{
+	int ret;
+	double percent = 0.0;
+	struct hists *hists = he->hists;
+	struct hpp_arg *arg = hpp->ptr;
+
+	if (hists->stats.total_period)
+		percent = 100.0 * he->stat.period / hists->stats.total_period;
+
+	ui_browser__set_percent_color(arg->b, percent, arg->current_entry);
+
+	if (symbol_conf.use_callchain) {
+		slsmg_printf("%c ", arg->folded_sign);
+		ret += 2;
+	}
+
+	ret = scnprintf(hpp->buf, hpp->size, "%6.2f%%", percent);
+	slsmg_printf("%s", hpp->buf);
+
+	if (symbol_conf.event_group) {
+		int i;
+		struct perf_evsel *evsel = hists_to_evsel(hists);
+		struct hist_entry *pair;
+		int nr_members = evsel->nr_members;
+		double *percents;
+
+		if (nr_members <= 1)
+			goto out;
+
+		percents = zalloc(sizeof(*percents) * nr_members);
+		if (percents == NULL) {
+			pr_warning("Not enough memory!\n");
+			goto out;
+		}
+
+		list_for_each_entry(pair, &he->pairs.head, pairs.node) {
+			int idx;
+			u64 period = pair->stat.period;
+			u64 total = pair->hists->stats.total_period;
+
+			if (!total)
+				continue;
+
+			evsel = hists_to_evsel(pair->hists);
+			idx = perf_evsel__group_idx(evsel);
+			percents[idx] = 100.0 * period / total;
+		}
+
+		for (i = 1; i < nr_members; i++) {
+			ui_browser__set_percent_color(arg->b, percents[i],
+						      arg->current_entry);
+			ret += scnprintf(hpp->buf, hpp->size,
+					 " %6.2f%%", percents[i]);
+			slsmg_printf("%s", hpp->buf);
+		}
+		free(percents);
+	}
+out:
+	if (!arg->current_entry || !arg->b->navkeypressed)
+		ui_browser__set_color(arg->b, HE_COLORSET_NORMAL);
+
+	return ret;
+}
+
+#define __HPP_COLOR_PERCENT_FN(_type, _field)					\
+static int hist_browser__hpp_color_##_type(struct perf_hpp *hpp, 		\
+					   struct hist_entry *he)		\
+{										\
+	int ret;								\
+	double percent = 0.0;							\
+	struct hists *hists = he->hists;					\
+	struct hpp_arg *arg = hpp->ptr;						\
+										\
+	if (hists->stats.total_period)						\
+		percent = 100.0 * he->stat._field / hists->stats.total_period;	\
+										\
+	ui_browser__set_percent_color(arg->b, percent, arg->current_entry); 	\
+	ret = scnprintf(hpp->buf, hpp->size, "%6.2f%%", percent);		\
+	slsmg_printf("%s", hpp->buf);						\
+										\
+	if (symbol_conf.event_group) {						\
+		int i;								\
+		struct perf_evsel *evsel = hists_to_evsel(hists);		\
+		struct hist_entry *pair;					\
+		int nr_members = evsel->nr_members;				\
+		double *percents;						\
+										\
+		if (nr_members <= 1)						\
+			goto out;						\
+										\
+		percents = zalloc(sizeof(*percents) * nr_members);		\
+		if (percents == NULL) {						\
+			pr_warning("Not enough memory!\n");			\
+			goto out;						\
+		}								\
+										\
+		list_for_each_entry(pair, &he->pairs.head, pairs.node) { 	\
+			int idx;						\
+			u64 period = pair->stat._field;				\
+			u64 total = pair->hists->stats.total_period;		\
+										\
+			if (!total)						\
+				continue;					\
+										\
+			evsel = hists_to_evsel(pair->hists);			\
+			idx = perf_evsel__group_idx(evsel);			\
+			percents[idx] = 100.0 * period / total;			\
+		}								\
+										\
+		for (i = 1; i < nr_members; i++) {				\
+			ui_browser__set_percent_color(arg->b, percents[i],	\
+						      arg->current_entry); 	\
+			ret += scnprintf(hpp->buf, hpp->size,			\
+					 " %6.2f%%", percents[i]);		\
+			slsmg_printf("%s", hpp->buf);				\
+		}								\
+		free(percents);							\
+	}									\
+out:										\
+	if (!arg->current_entry || !arg->b->navkeypressed)			\
+		ui_browser__set_color(arg->b, HE_COLORSET_NORMAL);		\
+										\
+	return ret;								\
 }
 
-HPP__COLOR_FN(overhead, period)
-HPP__COLOR_FN(overhead_sys, period_sys)
-HPP__COLOR_FN(overhead_us, period_us)
-HPP__COLOR_FN(overhead_guest_sys, period_guest_sys)
-HPP__COLOR_FN(overhead_guest_us, period_guest_us)
+__HPP_COLOR_PERCENT_FN(overhead_sys, period_sys)
+__HPP_COLOR_PERCENT_FN(overhead_us, period_us)
+__HPP_COLOR_PERCENT_FN(overhead_guest_sys, period_guest_sys)
+__HPP_COLOR_PERCENT_FN(overhead_guest_us, period_guest_us)
 
-#undef HPP__COLOR_FN
+#undef __HPP_COLOR_PERCENT_FN
 
 void hist_browser__init_hpp(void)
 {
@@ -606,7 +728,6 @@ static int hist_browser__show_entry(struct hist_browser *browser,
 				    unsigned short row)
 {
 	char s[256];
-	double percent;
 	int i, printed = 0;
 	int width = browser->b.width;
 	char folded_sign = ' ';
@@ -625,9 +746,15 @@ static int hist_browser__show_entry(struct hist_browser *browser,
 	}
 
 	if (row_offset == 0) {
+		struct hpp_arg arg = {
+			.b		= &browser->b,
+			.folded_sign	= folded_sign,
+			.current_entry	= current_entry,
+		};
 		struct perf_hpp hpp = {
 			.buf		= s,
 			.size		= sizeof(s),
+			.ptr		= &arg,
 		};
 
 		ui_browser__gotorc(&browser->b, row, 0);
@@ -643,21 +770,7 @@ static int hist_browser__show_entry(struct hist_browser *browser,
 			first = false;
 
 			if (perf_hpp__format[i].color) {
-				hpp.ptr = &percent;
-				/* It will set percent for us. See HPP__COLOR_FN above. */
 				width -= perf_hpp__format[i].color(&hpp, entry);
-
-				ui_browser__set_percent_color(&browser->b, percent, current_entry);
-
-				if (i == PERF_HPP__OVERHEAD && symbol_conf.use_callchain) {
-					slsmg_printf("%c ", folded_sign);
-					width -= 2;
-				}
-
-				slsmg_printf("%s", s);
-
-				if (!current_entry || !browser->b.navkeypressed)
-					ui_browser__set_color(&browser->b, HE_COLORSET_NORMAL);
 			} else {
 				width -= perf_hpp__format[i].entry(&hpp, entry);
 				slsmg_printf("%s", s);
tools/perf/ui/hist.c +4 -1
index b42bd15af3f5..118274f29bb7 100644
@@ -514,6 +514,9 @@ unsigned int hists__sort_list_width(struct hists *hists)
 {
 	struct sort_entry *se;
 	int i, ret = 0;
+	struct perf_hpp dummy_hpp = {
+		.ptr	= hists_to_evsel(hists),
+	};
 
 	for (i = 0; i < PERF_HPP__MAX_INDEX; i++) {
 		if (!perf_hpp__format[i].cond)
@@ -521,7 +524,7 @@ unsigned int hists__sort_list_width(struct hists *hists)
 		if (i)
 			ret += 2;
 
-		ret += perf_hpp__format[i].width(NULL);
+		ret += perf_hpp__format[i].width(&dummy_hpp);
 	}
 
 	list_for_each_entry(se, &hist_entry__sort_list, list)
Signature · 1 line
1.7.11.7
author maintainer
#45 lore raw

PATCH 14/18 perf gtk/browser: Add support for event group view

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

Show group members' overhead also when showing the leader's if event group is enabled. Use macro for defining hpp functions which looks almost identical.

Cc Jiri Olsa <[email protected]>
Cc Stephane Eranian <[email protected]>
Cc Pekka Enberg <[email protected]>
---
 tools/perf/ui/gtk/browser.c | 87 ++++++++++++++++++++++++++++++++++++---------
 1 file changed, 70 insertions(+), 17 deletions(-)
tools/perf/ui/gtk/browser.c +70 -17
index 253b6219a39e..04ed0cbbc090 100644
@@ -45,30 +45,82 @@ static const char *perf_gtk__get_percent_color(double percent)
 	return NULL;
 }
 
-#define HPP__COLOR_FN(_name, _field)						\
-static int perf_gtk__hpp_color_ ## _name(struct perf_hpp *hpp,			\
-					 struct hist_entry *he)			\
+static int perf_gtk__percent_color_snprintf(char *buf, size_t size,
+					    double percent)
+{
+	int ret = 0;
+	const char *markup;
+
+	markup = perf_gtk__get_percent_color(percent);
+	if (markup)
+		ret += scnprintf(buf, size, markup);
+
+	ret += scnprintf(buf + ret, size - ret, "%6.2f%%", percent);
+
+	if (markup)
+		ret += scnprintf(buf + ret, size - ret, "</span>");
+
+	return ret;
+}
+
+
+#define __HPP_COLOR_PERCENT_FN(_type, _field)					\
+static int perf_gtk__hpp_color_##_type(struct perf_hpp *hpp,			\
+				       struct hist_entry *he)			\
 {										\
+	int ret;								\
+	double percent = 0.0;							\
 	struct hists *hists = he->hists;					\
-	double percent = 100.0 * he->stat._field / hists->stats.total_period;	\
-	const char *markup;							\
-	int ret = 0;								\
 										\
-	markup = perf_gtk__get_percent_color(percent);				\
-	if (markup)								\
-		ret += scnprintf(hpp->buf, hpp->size, "%s", markup);		\
-	ret += scnprintf(hpp->buf + ret, hpp->size - ret, "%6.2f%%", percent); 	\
-	if (markup)								\
-		ret += scnprintf(hpp->buf + ret, hpp->size - ret, "</span>"); 	\
+	if (hists->stats.total_period)						\
+		percent = 100.0 * he->stat._field / hists->stats.total_period; 	\
+										\
+	ret = perf_gtk__percent_color_snprintf(hpp->buf, hpp->size, percent);	\
+										\
+	if (symbol_conf.event_group) {						\
+		int i;								\
+		struct perf_evsel *evsel = hists_to_evsel(hists);		\
+		struct hist_entry *pair;					\
+		int nr_members = evsel->nr_members;				\
+		double *percents;						\
+										\
+		if (nr_members <= 1)						\
+			return ret;						\
+										\
+		percents = zalloc(sizeof(*percents) * nr_members);		\
+		if (percents == NULL) {						\
+			pr_warning("Not enough memory!\n");			\
+			return ret;						\
+		}								\
+										\
+		list_for_each_entry(pair, &he->pairs.head, pairs.node) { 	\
+			u64 period = pair->stat._field;				\
+			u64 total = pair->hists->stats.total_period;		\
+										\
+			if (!total)						\
+				continue;					\
+										\
+			evsel = hists_to_evsel(pair->hists);			\
+			i = perf_evsel__group_idx(evsel);			\
+			percents[i] = 100.0 * period / total;			\
+		}								\
 										\
+		for (i = 1; i < nr_members; i++) {				\
+			ret += scnprintf(hpp->buf + ret, hpp->size -ret, " ");	\
+			ret += perf_gtk__percent_color_snprintf(hpp->buf + ret,	\
+								hpp->size - ret,\
+								percents[i]);	\
+		}								\
+		free(percents);							\
+	}									\
 	return ret;								\
 }
 
-HPP__COLOR_FN(overhead, period)
-HPP__COLOR_FN(overhead_sys, period_sys)
-HPP__COLOR_FN(overhead_us, period_us)
-HPP__COLOR_FN(overhead_guest_sys, period_guest_sys)
-HPP__COLOR_FN(overhead_guest_us, period_guest_us)
+__HPP_COLOR_PERCENT_FN(overhead, period)
+__HPP_COLOR_PERCENT_FN(overhead_sys, period_sys)
+__HPP_COLOR_PERCENT_FN(overhead_us, period_us)
+__HPP_COLOR_PERCENT_FN(overhead_guest_sys, period_guest_sys)
+__HPP_COLOR_PERCENT_FN(overhead_guest_us, period_guest_us)
 
 #undef HPP__COLOR_FN
 
@@ -103,6 +155,7 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists)
 	struct perf_hpp hpp = {
 		.buf		= s,
 		.size		= sizeof(s),
+		.ptr		= hists_to_evsel(hists),
 	};
 
 	nr_cols = 0;
Signature · 1 line
1.7.11.7
author maintainer
#46 lore raw

PATCH 15/18 perf report: Bypass non-leader events when event group is enabled

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

Since we have all necessary information in the leader events and other members don't, bypass members. Member events will be shown along with the leaders if event group is enabled.

Cc Jiri Olsa <[email protected]>
Cc Stephane Eranian <[email protected]>
Cc Pekka Enberg <[email protected]>
---
 tools/perf/builtin-report.c    |  4 ++++
 tools/perf/ui/browsers/hists.c | 41 +++++++++++++++++++++++++++++++++++------
 tools/perf/ui/gtk/browser.c    |  4 ++++
 3 files changed, 43 insertions(+), 6 deletions(-)
tools/perf/builtin-report.c +4 -0
index 13a2cd20a1cd..87af38bd75a8 100644
@@ -319,6 +319,10 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist,
 		struct hists *hists = &pos->hists;
 		const char *evname = perf_evsel__name(pos);
 
+		if (symbol_conf.event_group &&
+		    !perf_evsel__is_group_leader(pos))
+			continue;
+
 		hists__fprintf_nr_sample_events(hists, evname, stdout);
 		hists__fprintf(hists, true, 0, 0, stdout);
 		fprintf(stdout, "\n\n");
tools/perf/ui/browsers/hists.c +35 -6

70 lines not on this page · raw message

tools/perf/ui/gtk/browser.c +4 -0
index 04ed0cbbc090..3b1642dc0e31 100644
@@ -325,6 +325,10 @@ int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist,
 		GtkWidget *scrolled_window;
 		GtkWidget *tab_label;
 
+		if (symbol_conf.event_group &&
+		    !perf_evsel__is_group_leader(pos))
+			continue;
+
 		scrolled_window = gtk_scrolled_window_new(NULL, NULL);
 
 		gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
Signature · 1 line
1.7.11.7
author maintainer
#47 lore raw

cover perf report: Add support for event group view (v6)

In reply to Namhyung Kim

Hi all,

This is my 6th iteration of event group view patchset. For basic idea and usage example, please see my original post [1].

The largest change in this version is using 'pairs' list of hist_entry instead of allocating group_stats for all group members. But I needed to allocate temporary arrays for internal purpose anyway. If you have a better solution please let me know.

Jiri, sorry for the delay. I had to hunt down some nasty bugs in my patches. And I saw you submitted the multiplu diff series which will conflict my changes. I'll have a look at it soon, and I'd be glad if you take a look at my changes too. :)

You can get this series via my tree at:

git://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git perf/group-v6

Any comments are welcome, thanks,
Namhyung

v5 -> v6:
* set ->leader alse for leader evsel (Arnaldo)
* use hists__{match,link} (Arnaldo)

v4 -> v5:
* rebase onto acme/perf/core

v3 -> v4:
* patch 1-9 in previous post are merged.
* add Jiri's Acked-by
* add report.group config option

v2 -> v3:
* drop patch 1 since it's merged into acme/perf/core
* cherry-pick Jiri's hpp changes
* add missing bswap_32 on reading nr_groups (Jiri)
* remove perf_evlist__recalc_nr_groups() in favor of list_is_last (Jiri)

v1 -> v2:
* save group relation to header (Jiri)

[1] https://lkml.org/lkml/2012/7/24/81

Namhyung Kim (18):
perf evsel: Set leader evsel's ->leader to itself
perf evsel: Convert to _is_group_leader method
perf tools: Keep group information
perf header: Add HEADER_GROUP_DESC feature
perf tools: Fix typo on hist__entry_add_pair
perf hists: Link hist entry pairs to leader
perf hists: Exchange order of comparing items when collapsing hists perf hists: Add hists__{match,link}_collapsed
perf symbol: Introduce symbol_conf.event_group
perf report: Make another loop for linking group hists perf hists: Resort hist entries using group members for output perf ui/hist: Add support for event group view
perf hist browser: Add support for event group view
perf gtk/browser: Add support for event group view
perf report: Bypass non-leader events when event group is enabled perf report: Show group description when event group is enabled perf report: Add --group option
perf report: Add report.group config option

 tools/perf/Documentation/perf-report.txt |   3 +
 tools/perf/builtin-record.c              |   3 +
 tools/perf/builtin-report.c              |  47 +++-
 tools/perf/builtin-stat.c                |   2 +-
 tools/perf/tests/parse-events.c          |  20 +-
 tools/perf/ui/browsers/hists.c           | 237 ++++++++++++++++---
 tools/perf/ui/gtk/browser.c              |  99 ++++++--
 tools/perf/ui/hist.c                     | 375 ++++++++++++++++---------------
 tools/perf/ui/stdio/hist.c               |   2 +
 tools/perf/util/evlist.c                 |  12 +-
 tools/perf/util/evlist.h                 |   1 +
 tools/perf/util/evsel.c                  |  32 ++-
 tools/perf/util/evsel.h                  |  20 +-
 tools/perf/util/header.c                 | 153 +++++++++++++
 tools/perf/util/header.h                 |   2 +
 tools/perf/util/hist.c                   | 182 +++++++++++++--
 tools/perf/util/hist.h                   |   2 +
 tools/perf/util/parse-events.c           |   1 +
 tools/perf/util/parse-events.h           |   1 +
 tools/perf/util/parse-events.y           |  10 +
 tools/perf/util/sort.h                   |   2 +-
 tools/perf/util/symbol.c                 |   4 +
 tools/perf/util/symbol.h                 |   3 +-
 23 files changed, 934 insertions(+), 279 deletions(-)
Signature · 1 line
1.7.11.7
author maintainer
#48 lore raw

PATCH 16/18 perf report: Show group description when event group is enabled

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

When using event group viewer, it's better to show the group description rather than the leader information alone.

If a leader did not contain any member, it's a non-group event.

Cc Jiri Olsa <[email protected]>
Cc Stephane Eranian <[email protected]>
Cc Pekka Enberg <[email protected]>
---
 tools/perf/builtin-report.c    | 15 +++++++++++++++
 tools/perf/ui/browsers/hists.c | 25 +++++++++++++++++++++++++
 tools/perf/ui/gtk/browser.c    | 14 +++++++++++---
 tools/perf/util/evsel.c        | 25 +++++++++++++++++++++++++
 tools/perf/util/evsel.h        |  8 ++++++++
 5 files changed, 84 insertions(+), 3 deletions(-)
tools/perf/builtin-report.c +15 -0
index 87af38bd75a8..e5b53f6554f4 100644
@@ -299,6 +299,21 @@ static size_t hists__fprintf_nr_sample_events(struct hists *self,
 	char unit;
 	unsigned long nr_samples = self->stats.nr_events[PERF_RECORD_SAMPLE];
 	u64 nr_events = self->stats.total_period;
+	struct perf_evsel *evsel = hists_to_evsel(self);
+	char buf[512];
+	size_t size = sizeof(buf);
+
+	if (symbol_conf.event_group && evsel->nr_members > 1) {
+		struct perf_evsel *pos;
+
+		perf_evsel__group_desc(evsel, buf, size);
+		evname = buf;
+
+		for_each_group_member(pos, evsel) {
+			nr_samples += pos->hists.stats.nr_events[PERF_RECORD_SAMPLE];
+			nr_events += pos->hists.stats.total_period;
+		}
+	}
 
 	nr_samples = convert_unit(nr_samples, &unit);
 	ret = fprintf(fp, "# Samples: %lu%c", nr_samples, unit);
tools/perf/ui/browsers/hists.c +25 -0
index 0d8b0143cd9b..3e31534fcc47 100644
@@ -1211,6 +1211,21 @@ static int hists__browser_title(struct hists *hists, char *bf, size_t size,
 	const struct thread *thread = hists->thread_filter;
 	unsigned long nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE];
 	u64 nr_events = hists->stats.total_period;
+	struct perf_evsel *evsel = hists_to_evsel(hists);
+	char buf[512];
+	size_t buflen = sizeof(buf);
+
+	if (symbol_conf.event_group && evsel->nr_members > 1) {
+		struct perf_evsel *pos;
+
+		perf_evsel__group_desc(evsel, buf, buflen);
+		ev_name = buf;
+
+		for_each_group_member(pos, evsel) {
+			nr_samples += pos->hists.stats.nr_events[PERF_RECORD_SAMPLE];
+			nr_events += pos->hists.stats.total_period;
+		}
+	}
 
 	nr_samples = convert_unit(nr_samples, &unit);
 	printed = scnprintf(bf, size,
@@ -1607,6 +1622,16 @@ static void perf_evsel_menu__write(struct ui_browser *browser,
 	ui_browser__set_color(browser, current_entry ? HE_COLORSET_SELECTED :
 						       HE_COLORSET_NORMAL);
 
+	if (symbol_conf.event_group && evsel->nr_members > 1) {
+		struct perf_evsel *pos;
+
+		ev_name = perf_evsel__group_name(evsel);
+
+		for_each_group_member(pos, evsel) {
+			nr_events += pos->hists.stats.nr_events[PERF_RECORD_SAMPLE];
+		}
+	}
+
 	nr_events = convert_unit(nr_events, &unit);
 	printed = scnprintf(bf, sizeof(bf), "%lu%c%s%s", nr_events,
 			   unit, unit == ' ' ? "" : " ", ev_name);
tools/perf/ui/gtk/browser.c +11 -3
index 3b1642dc0e31..e7e11df829ed 100644
@@ -324,10 +324,18 @@ int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist,
 		const char *evname = perf_evsel__name(pos);
 		GtkWidget *scrolled_window;
 		GtkWidget *tab_label;
+		char buf[512];
+		size_t size = sizeof(buf);
 
-		if (symbol_conf.event_group &&
-		    !perf_evsel__is_group_leader(pos))
-			continue;
+		if (symbol_conf.event_group) {
+			if (!perf_evsel__is_group_leader(pos))
+				continue;
+
+			if (pos->nr_members > 1) {
+				perf_evsel__group_desc(pos, buf, size);
+				evname = buf;
+			}
+		}
 
 		scrolled_window = gtk_scrolled_window_new(NULL, NULL);
 
tools/perf/util/evsel.c +25 -0
index 73e6085a7294..a35e2547a7eb 100644
@@ -405,6 +405,31 @@ const char *perf_evsel__name(struct perf_evsel *evsel)
 	return evsel->name ?: "unknown";
 }
 
+const char *perf_evsel__group_name(struct perf_evsel *evsel)
+{
+	return evsel->group_name ?: "anon group";
+}
+
+int perf_evsel__group_desc(struct perf_evsel *evsel, char *buf, size_t size)
+{
+	int ret;
+	struct perf_evsel *pos;
+	const char *group_name = perf_evsel__group_name(evsel);
+
+	ret = scnprintf(buf, size, "%s", group_name);
+
+	ret += scnprintf(buf + ret, size - ret, " { %s",
+			 perf_evsel__name(evsel));
+
+	for_each_group_member(pos, evsel)
+		ret += scnprintf(buf + ret, size - ret, ", %s",
+				 perf_evsel__name(pos));
+
+	ret += scnprintf(buf + ret, size - ret, " }");
+
+	return ret;
+}
+
 /*
  * The enable_on_exec/disabled value strategy:
  *
tools/perf/util/evsel.h +8 -0
index 54a8efbd8dcb..d2d1870928df 100644
@@ -113,6 +113,8 @@ extern const char *perf_evsel__sw_names[PERF_COUNT_SW_MAX];
 int __perf_evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result,
 					    char *bf, size_t size);
 const char *perf_evsel__name(struct perf_evsel *evsel);
+const char *perf_evsel__group_name(struct perf_evsel *evsel);
+int perf_evsel__group_desc(struct perf_evsel *evsel, char *buf, size_t size);
 
 int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
 int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
@@ -238,4 +240,10 @@ static inline int perf_evsel__group_idx(struct perf_evsel *evsel)
 {
 	return evsel->idx - evsel->leader->idx;
 }
+
+#define for_each_group_member(_evsel, _leader) 					\
+for ((_evsel) = list_entry((_leader)->node.next, struct perf_evsel, node); 	\
+     (_evsel) && (_evsel)->leader == (_leader);					\
+     (_evsel) = list_entry((_evsel)->node.next, struct perf_evsel, node))
+
 #endif /* __PERF_EVSEL_H */
Signature · 1 line
1.7.11.7
author maintainer
#49 lore raw

PATCH 17/18 perf report: Add --group option

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

Add --group option to enable event grouping. When enabled, all the group members information will be shown together with the leader.

---
 tools/perf/Documentation/perf-report.txt | 3 +++
 tools/perf/builtin-report.c              | 2 ++
 2 files changed, 5 insertions(+)
tools/perf/Documentation/perf-report.txt +3 -0
index f4d91bebd59d..b3e8fcb9bbce 100644
@@ -171,6 +171,9 @@ OPTIONS
 --objdump=<path>::
         Path to objdump binary.
 
+--group::
+	Show event group information together.
+
 SEE ALSO
 --------
 linkperf:perf-stat[1], linkperf:perf-annotate[1]
tools/perf/builtin-report.c +2 -0
index e5b53f6554f4..c7079dff7411 100644
@@ -668,6 +668,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
 		   "Specify disassembler style (e.g. -M intel for intel syntax)"),
 	OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period,
 		    "Show a column with the sum of periods"),
+	OPT_BOOLEAN(0, "group", &symbol_conf.event_group,
+		    "Show event group information together"),
 	OPT_CALLBACK_NOOPT('b', "branch-stack", &sort__branch_mode, "",
 		    "use branch records for histogram filling", parse_branch_mode),
 	OPT_STRING(0, "objdump", &objdump_path, "path",
Signature · 1 line
1.7.11.7
author maintainer
#50 lore raw

PATCH 18/18 perf report: Add report.group config option

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

Add report.group config option for setting default value of event group view. It affects the report output only if perf.data contains event group info.

A user can write .perfconfig file like below to enable group view by default:

  $ cat ~/.perfconfig
  [report]
  group = true

And it can be disabled through command line:

  $ perf report --no-group
Cc Jiri Olsa <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/builtin-report.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
tools/perf/builtin-report.c +13 -0
index c7079dff7411..f35e489156dc 100644
@@ -8,6 +8,7 @@
 #include "builtin.h"
 
 #include "util/util.h"
+#include "util/cache.h"
 
 #include "util/annotate.h"
 #include "util/color.h"
@@ -54,6 +55,16 @@ struct perf_report {
 	DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
 };
 
+static int perf_report_config(const char *var, const char *value, void *cb)
+{
+	if (!strcmp(var, "report.group")) {
+		symbol_conf.event_group = perf_config_bool(var, value);
+		return 0;
+	}
+
+	return perf_default_config(var, value, cb);
+}
+
 static int perf_report__add_branch_hist_entry(struct perf_tool *tool,
 					struct addr_location *al,
 					struct perf_sample *sample,
@@ -677,6 +688,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
 	OPT_END()
 	};
 
+	perf_config(perf_report_config, NULL);
+
 	argc = parse_options(argc, argv, options, report_usage, 0);
 
 	if (report.use_stdio)
Signature · 1 line
1.7.11.7