Skip to contentSkip to conversation

perf tool: Add new event group management

PATCH Superseded Jiri Olsa 9 participants 36 messages Jun 29, 2012 – Jul 18, 2012 perf events

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
author
#12 lore raw

PATCH v3 3/3 perf, test: Add automated tests for event group parsing

In reply to Jiri Olsa

Adding 3 more tests for new event group syntax. Tests are executed within the 'perf test parse' test suite.

---
 tools/perf/util/parse-events-test.c |  152 +++++++++++++++++++++++++++++++++++
 1 files changed, 152 insertions(+), 0 deletions(-)
tools/perf/util/parse-events-test.c +152 -0
index 229af6d..66e6cc1 100644
@@ -473,6 +473,146 @@ static int test__checkterms_simple(struct list_head *terms)
 	return 0;
 }
 
+static int test__group1(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel, *leader;
+
+	TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
+
+	/* instructions:k */
+	evsel = leader = list_entry(evlist->entries.next,
+				    struct perf_evsel, node);
+	TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong config",
+			PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+	TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
+
+	/* cycles:upp */
+	evsel = list_entry(evsel->node.next, struct perf_evsel, node);
+	TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong config",
+			PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
+	TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
+
+	return 0;
+}
+
+static int test__group2(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel, *leader;
+
+	TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
+
+	/* faults + :u modifier */
+	evsel = leader = list_entry(evlist->entries.next,
+				    struct perf_evsel, node);
+	TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong config",
+			PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+	TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
+
+	/* cache-references + :u modifier */
+	evsel = list_entry(evsel->node.next, struct perf_evsel, node);
+	TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong config",
+			PERF_COUNT_HW_CACHE_REFERENCES == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+	TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
+
+	/* cycles:k */
+	evsel = list_entry(evsel->node.next, struct perf_evsel, node);
+	TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong config",
+			PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+	TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
+
+	return 0;
+}
+
+static int test__group3(struct perf_evlist *evlist __used)
+{
+	struct perf_evsel *evsel, *leader;
+
+	TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
+
+	/* group1 syscalls:sys_enter_open:H */
+	evsel = leader = list_entry(evlist->entries.next,
+				    struct perf_evsel, node);
+	TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong sample_type",
+		(PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | PERF_SAMPLE_CPU) ==
+		evsel->attr.sample_type);
+	TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
+	TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
+	TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
+	TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
+	TEST_ASSERT_VAL("wrong group name",
+		!strcmp(leader->group_name, "group1"));
+
+	/* group1 cycles:kppp */
+	evsel = list_entry(evsel->node.next, struct perf_evsel, node);
+	TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong config",
+			PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 3);
+	TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
+	TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
+
+	/* group2 cycles + G modifier */
+	evsel = leader = list_entry(evsel->node.next, struct perf_evsel, node);
+	TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong config",
+			PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
+	TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
+	TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
+	TEST_ASSERT_VAL("wrong group name",
+		!strcmp(leader->group_name, "group2"));
+
+	/* group2 1:3 + G modifier */
+	evsel = list_entry(evsel->node.next, struct perf_evsel, node);
+	TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong config", 3 == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
+	TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
+	TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
+
+	/* instructions:u */
+	evsel = list_entry(evsel->node.next, struct perf_evsel, node);
+	TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
+	TEST_ASSERT_VAL("wrong config",
+			PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
+	TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
+	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
+	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
+	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
+	TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
+
+	return 0;
+}
+
 struct test__event_st {
 	const char *name;
 	__u32 type;
@@ -584,6 +724,18 @@ static struct test__event_st test__events[] = {
 		.name  = "instructions:H",
 		.check = test__checkevent_exclude_guest_modifier,
 	},
+	[26] = {
+		.name  = "{instructions:k,cycles:upp}",
+		.check = test__group1,
+	},
+	[27] = {
+		.name  = "{faults:k,cache-references}:u,cycles:k",
+		.check = test__group2,
+	},
+	[28] = {
+		.name  = "group1{syscalls:sys_enter_open:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
+		.check = test__group3,
+	},
 };
 
 #define TEST__EVENTS_CNT (sizeof(test__events) / sizeof(struct test__event_st))
Signature · 1 line
1.7.7.6

Jiri Olsa

author
#0 lore raw

v3 cover perf tool: Add new event group management

hi,
adding support for creating event groups based on the way they are specified on the command line.

This patchset adds the '{}' style grammar to express event group, allowing so far only the 'event modifier' as group modifier.

The sample/leader modifier changes are ready, but I'm getting some weird numbers in tests, so I'll send it later. Meanwhile, it'd be nice to have at least this patchset in.. ;)

Attached patches:
1/3 perf, tool: Add support to parse event group syntax 2/3 perf, tool: Enable grouping logic for parsed events 3/3 perf, test: Add automated tests for event group parsing

wbr,
jirka

---
 tools/perf/builtin-record.c         |   13 +--
 tools/perf/builtin-stat.c           |   13 +--
 tools/perf/builtin-test.c           |    8 +-
 tools/perf/builtin-top.c            |   12 +--
 tools/perf/util/evlist.c            |   20 ++---
 tools/perf/util/evlist.h            |    3 +-
 tools/perf/util/evsel.c             |   51 ++++++++----
 tools/perf/util/evsel.h             |   11 +--
 tools/perf/util/parse-events-test.c |  152 +++++++++++++++++++++++++++++++++++
 tools/perf/util/parse-events.c      |   32 +++++++-
 tools/perf/util/parse-events.h      |    5 +-
 tools/perf/util/parse-events.l      |    2 +
 tools/perf/util/parse-events.y      |   93 ++++++++++++++++++---
 tools/perf/util/python.c            |    7 +-
 14 files changed, 341 insertions(+), 81 deletions(-)
author
#2 lore raw

PATCH v3 2/3 perf, tool: Enable grouping logic for parsed events

This patch adds a functionality that allows to create event groups based on the way they are specified on the command line. Adding functionality to the '{}' group syntax introduced in earlier patch.

The current '--group/-g' option behaviour remains intact. If you specify it for record/stat/top command, all the specified events become members of a single group with the first event as a group leader.

With the new '{}' group syntax you can create group like:

  # perf record -e '{cycles,faults}' ls

resulting in single event group containing 'cycles' and 'faults' events, with cycles event as group leader.

All groups are created with regards to threads and cpus. Thus recording an event group within a 2 threads on server with 4 CPUs will create 8 separate groups.

Examples (first event in brackets is group leader):

  # 1 group (cpu-clock,task-clock)
  perf record --group -e cpu-clock,task-clock ls
  perf record -e '{cpu-clock,task-clock}' ls

# 2 groups (cpu-clock,task-clock) (minor-faults,major-faults) perf record -e '{cpu-clock,task-clock},{minor-faults,major-faults}' ls

  # 1 group (cpu-clock,task-clock,minor-faults,major-faults)
  perf record --group -e cpu-clock,task-clock -e minor-faults,major-faults ls
  perf record -e '{cpu-clock,task-clock,minor-faults,major-faults}' ls

  # 2 groups (cpu-clock,task-clock) (minor-faults,major-faults)
  perf record -e '{cpu-clock,task-clock} -e '{minor-faults,major-faults}' \
   -e instructions ls

  # 1 group (cpu-clock,task-clock,minor-faults,major-faults,instructions)
  perf record --group -e cpu-clock,task-clock \
   -e minor-faults,major-faults -e instructions ls
  perf record -e '{cpu-clock,task-clock,minor-faults,major-faults,instructions}' ls

It's possible to use standard event modifier for a group, which spans over all events in the group and overrides any event modifier settings, for example:

  # perf record -r '{faults:k,cache-references}:u'

resulting in ':u' modifier being used for both 'faults' and 'cache-references' events, regardless of their modifier setup (':k' for faults event).

---
 tools/perf/builtin-record.c    |   13 ++++------
 tools/perf/builtin-stat.c      |   13 ++++------
 tools/perf/builtin-test.c      |    8 +++---
 tools/perf/builtin-top.c       |   12 +++------
 tools/perf/util/evlist.c       |   20 +++++++--------
 tools/perf/util/evlist.h       |    3 +-
 tools/perf/util/evsel.c        |   51 ++++++++++++++++++++++++++-------------
 tools/perf/util/evsel.h        |   11 ++++----
 tools/perf/util/parse-events.c |   26 +++++++++++++++++---
 tools/perf/util/parse-events.h |    1 +
 tools/perf/util/python.c       |    7 ++++-
 11 files changed, 96 insertions(+), 69 deletions(-)
tools/perf/builtin-record.c +5 -8
index f5a6452..94d6b12 100644
@@ -176,18 +176,18 @@ static bool perf_evlist__equal(struct perf_evlist *evlist,
 
 static void perf_record__open(struct perf_record *rec)
 {
-	struct perf_evsel *pos, *first;
+	struct perf_evsel *pos;
 	struct perf_evlist *evlist = rec->evlist;
 	struct perf_session *session = rec->session;
 	struct perf_record_opts *opts = &rec->opts;
 
-	first = list_entry(evlist->entries.next, struct perf_evsel, node);
-
 	perf_evlist__config_attrs(evlist, opts);
 
+	if (opts->group)
+		perf_evlist__group(evlist);
+
 	list_for_each_entry(pos, &evlist->entries, node) {
 		struct perf_event_attr *attr = &pos->attr;
-		struct xyarray *group_fd = NULL;
 		/*
 		 * Check if parse_single_tracepoint_event has already asked for
 		 * PERF_SAMPLE_TIME.
@@ -202,16 +202,13 @@ static void perf_record__open(struct perf_record *rec)
 		 */
 		bool time_needed = attr->sample_type & PERF_SAMPLE_TIME;
 
-		if (opts->group && pos != first)
-			group_fd = first->fd;
 fallback_missing_features:
 		if (opts->exclude_guest_missing)
 			attr->exclude_guest = attr->exclude_host = 0;
 retry_sample_id:
 		attr->sample_id_all = opts->sample_id_all_missing ? 0 : 1;
 try_again:
-		if (perf_evsel__open(pos, evlist->cpus, evlist->threads,
-				     opts->group, group_fd) < 0) {
+		if (perf_evsel__open(pos, evlist->cpus, evlist->threads) < 0) {
 			int err = errno;
 
 			if (err == EPERM || err == EACCES) {
tools/perf/builtin-stat.c +5 -8
index 861f0ae..23908a8 100644
@@ -281,13 +281,9 @@ static int create_perf_stat_counter(struct perf_evsel *evsel,
 				    struct perf_evsel *first)
 {
 	struct perf_event_attr *attr = &evsel->attr;
-	struct xyarray *group_fd = NULL;
 	bool exclude_guest_missing = false;
 	int ret;
 
-	if (group && evsel != first)
-		group_fd = first->fd;
-
 	if (scale)
 		attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
 				    PERF_FORMAT_TOTAL_TIME_RUNNING;
@@ -299,8 +295,7 @@ retry:
 		evsel->attr.exclude_guest = evsel->attr.exclude_host = 0;
 
 	if (perf_target__has_cpu(&target)) {
-		ret = perf_evsel__open_per_cpu(evsel, evsel_list->cpus,
-					       group, group_fd);
+		ret = perf_evsel__open_per_cpu(evsel, evsel_list->cpus);
 		if (ret)
 			goto check_ret;
 		return 0;
@@ -311,8 +306,7 @@ retry:
 		attr->enable_on_exec = 1;
 	}
 
-	ret = perf_evsel__open_per_thread(evsel, evsel_list->threads,
-					  group, group_fd);
+	ret = perf_evsel__open_per_thread(evsel, evsel_list->threads);
 	if (!ret)
 		return 0;
 	/* fall through */
@@ -483,6 +477,9 @@ static int run_perf_stat(int argc __used, const char **argv)
 		close(child_ready_pipe[0]);
 	}
 
+	if (group)
+		perf_evlist__group(evsel_list);
+
 	first = list_entry(evsel_list->entries.next, struct perf_evsel, node);
 
 	list_for_each_entry(counter, &evsel_list->entries, node) {
tools/perf/builtin-test.c +4 -4
index 5ce3030..03568b8 100644
@@ -294,7 +294,7 @@ static int test__open_syscall_event(void)
 		goto out_thread_map_delete;
 	}
 
-	if (perf_evsel__open_per_thread(evsel, threads, false, NULL) < 0) {
+	if (perf_evsel__open_per_thread(evsel, threads) < 0) {
 		pr_debug("failed to open counter: %s, "
 			 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
 			 strerror(errno));
@@ -369,7 +369,7 @@ static int test__open_syscall_event_on_all_cpus(void)
 		goto out_thread_map_delete;
 	}
 
-	if (perf_evsel__open(evsel, cpus, threads, false, NULL) < 0) {
+	if (perf_evsel__open(evsel, cpus, threads) < 0) {
 		pr_debug("failed to open counter: %s, "
 			 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
 			 strerror(errno));
@@ -534,7 +534,7 @@ static int test__basic_mmap(void)
 
 		perf_evlist__add(evlist, evsels[i]);
 
-		if (perf_evsel__open(evsels[i], cpus, threads, false, NULL) < 0) {
+		if (perf_evsel__open(evsels[i], cpus, threads) < 0) {
 			pr_debug("failed to open counter: %s, "
 				 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
 				 strerror(errno));
@@ -739,7 +739,7 @@ static int test__PERF_RECORD(void)
 	 * Call sys_perf_event_open on all the fds on all the evsels,
 	 * grouping them if asked to.
 	 */
-	err = perf_evlist__open(evlist, opts.group);
+	err = perf_evlist__open(evlist);
 	if (err < 0) {
 		pr_debug("perf_evlist__open: %s\n", strerror(errno));
 		goto out_delete_evlist;
tools/perf/builtin-top.c +4 -8
index e3cab5f..c5cc2ab 100644
@@ -875,17 +875,14 @@ static void perf_top__mmap_read(struct perf_top *top)
 
 static void perf_top__start_counters(struct perf_top *top)
 {
-	struct perf_evsel *counter, *first;
+	struct perf_evsel *counter;
 	struct perf_evlist *evlist = top->evlist;
 
-	first = list_entry(evlist->entries.next, struct perf_evsel, node);
+	if (top->group)
+		perf_evlist__group(evlist);
 
 	list_for_each_entry(counter, &evlist->entries, node) {
 		struct perf_event_attr *attr = &counter->attr;
-		struct xyarray *group_fd = NULL;
-
-		if (top->group && counter != first)
-			group_fd = first->fd;
 
 		attr->sample_type = PERF_SAMPLE_IP | PERF_SAMPLE_TID;
 
@@ -916,8 +913,7 @@ retry_sample_id:
 		attr->sample_id_all = top->sample_id_all_missing ? 0 : 1;
 try_again:
 		if (perf_evsel__open(counter, top->evlist->cpus,
-				     top->evlist->threads, top->group,
-				     group_fd) < 0) {
+				     top->evlist->threads) < 0) {
 			int err = errno;
 
 			if (err == EPERM || err == EACCES) {
tools/perf/util/evlist.c +9 -11
index 7400fb3..5fa9257 100644
@@ -108,6 +108,12 @@ void perf_evlist__splice_list_tail(struct perf_evlist *evlist,
 	evlist->nr_entries += nr_entries;
 }
 
+void perf_evlist__group(struct perf_evlist *evlist)
+{
+	if (evlist->nr_entries)
+		parse_events__group_leader(&evlist->entries);
+}
+
 int perf_evlist__add_default(struct perf_evlist *evlist)
 {
 	struct perf_event_attr attr = {
@@ -757,21 +763,13 @@ void perf_evlist__set_selected(struct perf_evlist *evlist,
 	evlist->selected = evsel;
 }
 
-int perf_evlist__open(struct perf_evlist *evlist, bool group)
+int perf_evlist__open(struct perf_evlist *evlist)
 {
-	struct perf_evsel *evsel, *first;
+	struct perf_evsel *evsel;
 	int err, ncpus, nthreads;
 
-	first = list_entry(evlist->entries.next, struct perf_evsel, node);
-
 	list_for_each_entry(evsel, &evlist->entries, node) {
-		struct xyarray *group_fd = NULL;
-
-		if (group && evsel != first)
-			group_fd = first->fd;
-
-		err = perf_evsel__open(evsel, evlist->cpus, evlist->threads,
-				       group, group_fd);
+		err = perf_evsel__open(evsel, evlist->cpus, evlist->threads);
 		if (err < 0)
 			goto out_err;
 	}
tools/perf/util/evlist.h +2 -1
index 989bee9..d842931 100644
@@ -82,7 +82,7 @@ struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id);
 
 union perf_event *perf_evlist__mmap_read(struct perf_evlist *self, int idx);
 
-int perf_evlist__open(struct perf_evlist *evlist, bool group);
+int perf_evlist__open(struct perf_evlist *evlist);
 
 void perf_evlist__config_attrs(struct perf_evlist *evlist,
 			       struct perf_record_opts *opts);
@@ -126,4 +126,5 @@ void perf_evlist__splice_list_tail(struct perf_evlist *evlist,
 				   struct list_head *list,
 				   int nr_entries);
 
+void perf_evlist__group(struct perf_evlist *evlist);
 #endif /* __PERF_EVLIST_H */
tools/perf/util/evsel.c +34 -17

108 lines not on this page · raw message

tools/perf/util/evsel.h +5 -6
index 67cc503..b39f3db 100644
@@ -66,6 +66,8 @@ struct perf_evsel {
 		void		*data;
 	} handler;
 	bool 			supported;
+	struct perf_evsel	*leader;
+	char			*group_name;
 };
 
 struct cpu_map;
@@ -105,14 +107,11 @@ void perf_evsel__free_id(struct perf_evsel *evsel);
 void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
 
 int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
-			     struct cpu_map *cpus, bool group,
-			     struct xyarray *group_fds);
+			     struct cpu_map *cpus);
 int perf_evsel__open_per_thread(struct perf_evsel *evsel,
-				struct thread_map *threads, bool group,
-				struct xyarray *group_fds);
+				struct thread_map *threads);
 int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
-		     struct thread_map *threads, bool group,
-		     struct xyarray *group_fds);
+		     struct thread_map *threads);
 void perf_evsel__close(struct perf_evsel *evsel, int ncpus, int nthreads);
 
 #define perf_evsel__match(evsel, t, c)		\
tools/perf/util/parse-events.c +22 -4
index f62cbee..40ad468 100644
@@ -547,14 +547,32 @@ int parse_events_add_pmu(struct list_head **list, int *idx,
 			 pmu_event_name(head_config));
 }
 
-int parse_events__modifier_group(struct list_head *list __used,
-				 char *event_mod __used)
+struct perf_evsel *parse_events__group_leader(struct list_head *list)
 {
-	return 0;
+	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)
+			evsel->leader = leader;
+
+	return leader;
 }
 
-void parse_events__group(char *name __used, struct list_head *list __used)
+int parse_events__modifier_group(struct list_head *list,
+				 char *event_mod)
 {
+	return parse_events__modifier_event(list, event_mod);
+}
+
+void parse_events__group(char *name, struct list_head *list)
+{
+	struct perf_evsel *leader;
+
+	leader = parse_events__group_leader(list);
+	leader->group_name = name ? strdup(name) : NULL;
 }
 
 void parse_events_update_lists(struct list_head *list_event,
tools/perf/util/parse-events.h +1 -0
index c2f2ed9..fdbc72a 100644
@@ -92,6 +92,7 @@ int parse_events_add_breakpoint(struct list_head **list, int *idx,
 				void *ptr, char *type);
 int parse_events_add_pmu(struct list_head **list, int *idx,
 			 char *pmu , struct list_head *head_config);
+struct perf_evsel *parse_events__group_leader(struct list_head *list);
 void parse_events__group(char *name, struct list_head *list);
 void parse_events_update_lists(struct list_head *list_event,
 			       struct list_head *list_all);
tools/perf/util/python.c +5 -2
index e03b58a..419c29e 100644
@@ -627,7 +627,7 @@ static PyObject *pyrf_evsel__open(struct pyrf_evsel *pevsel,
 	 * This will group just the fds for this single evsel, to group
 	 * multiple events, use evlist.open().
 	 */
-	if (perf_evsel__open(evsel, cpus, threads, group, NULL) < 0) {
+	if (perf_evsel__open(evsel, cpus, threads) < 0) {
 		PyErr_SetFromErrno(PyExc_OSError);
 		return NULL;
 	}
@@ -828,7 +828,10 @@ static PyObject *pyrf_evlist__open(struct pyrf_evlist *pevlist,
 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OOii", kwlist, &group))
 		return NULL;
 
-	if (perf_evlist__open(evlist, group) < 0) {
+	if (group)
+		perf_evlist__group(evlist);
+
+	if (perf_evlist__open(evlist) < 0) {
 		PyErr_SetFromErrno(PyExc_OSError);
 		return NULL;
 	}
Signature · 1 line
1.7.7.6
author
#1 lore raw

PATCH v3 1/3 perf, tool: Add support to parse event group syntax

In reply to Jiri Olsa

Adding scanner/parser bits to parse event groups.

The grammar for group is:

  groups:      groups ',' group | group
  group:       group_name '{' events '}' group_mod
  group_name:  name | empty
  group_mod:   ':' group_mods | empty
  group_mods:  event_mod

Currently it's possible to use standard event modifier as a modifier for group. It spans over all events in the group and overrides any event modifier settings.

It's necessary to use quoting ("'\) when specifying group on command line, since {} characters are interpretted by most of the shells.

It is now possible to specify groups in event syntax like:

'{cycles,faults}'
- anonymous group

'group1{cycles,faults}
- group with name 'group1'

'{cycles,faults}:k
- anonymous group with event modifier 'k'

'{cpu-clock,task-clock},{minor-faults,major-faults}'
- two anonymous groups

The grouping functionality itself is comming shortly.

---
 tools/perf/util/parse-events.c |   14 +++++-
 tools/perf/util/parse-events.h |    4 +-
 tools/perf/util/parse-events.l |    2 +
 tools/perf/util/parse-events.y |   93 ++++++++++++++++++++++++++++++++++------
 4 files changed, 97 insertions(+), 16 deletions(-)
tools/perf/util/parse-events.c +12 -2
index 0cc27da..f62cbee 100644
@@ -547,19 +547,29 @@ int parse_events_add_pmu(struct list_head **list, int *idx,
 			 pmu_event_name(head_config));
 }
 
+int parse_events__modifier_group(struct list_head *list __used,
+				 char *event_mod __used)
+{
+	return 0;
+}
+
+void parse_events__group(char *name __used, struct list_head *list __used)
+{
+}
+
 void parse_events_update_lists(struct list_head *list_event,
 			       struct list_head *list_all)
 {
 	/*
 	 * Called for single event definition. Update the
-	 * 'all event' list, and reinit the 'signle event'
+	 * 'all event' list, and reinit the 'single event'
 	 * list, for next event definition.
 	 */
 	list_splice_tail(list_event, list_all);
 	free(list_event);
 }
 
-int parse_events_modifier(struct list_head *list, char *str)
+int parse_events__modifier_event(struct list_head *list, char *str)
 {
 	struct perf_evsel *evsel;
 	int exclude = 0, exclude_GH = 0;
tools/perf/util/parse-events.h +3 -1
index ee9c218..c2f2ed9 100644
@@ -79,7 +79,8 @@ int parse_events__term_str(struct parse_events__term **_term,
 int parse_events__term_clone(struct parse_events__term **new,
 			     struct parse_events__term *term);
 void parse_events__free_terms(struct list_head *terms);
-int parse_events_modifier(struct list_head *list, char *str);
+int parse_events__modifier_event(struct list_head *list, char *str);
+int parse_events__modifier_group(struct list_head *list, char *event_mod);
 int parse_events_add_tracepoint(struct list_head **list, int *idx,
 				char *sys, char *event);
 int parse_events_add_numeric(struct list_head **list, int *idx,
@@ -91,6 +92,7 @@ int parse_events_add_breakpoint(struct list_head **list, int *idx,
 				void *ptr, char *type);
 int parse_events_add_pmu(struct list_head **list, int *idx,
 			 char *pmu , struct list_head *head_config);
+void parse_events__group(char *name, struct list_head *list);
 void parse_events_update_lists(struct list_head *list_event,
 			       struct list_head *list_all);
 void parse_events_error(void *data, void *scanner, char const *msg);
tools/perf/util/parse-events.l +2 -0
index 488362e..931bb6e 100644
@@ -151,6 +151,8 @@ r{num_raw_hex}		{ return raw(yyscanner); }
 -			{ return '-'; }
 ,			{ return ','; }
 :			{ return ':'; }
+"{"			{ return '{'; }
+"}"			{ return '}'; }
 =			{ return '='; }
 
 <mem>{
tools/perf/util/parse-events.y +80 -13

133 lines not on this page · raw message

Signature · 1 line
1.7.7.6
#3 lore raw

Re: [PATCH 2/3] perf, tool: Enable grouping logic for parsed events

In reply to Jiri Olsa

Em Fri, Jun 29, 2012 at 11:08:26AM +0200, Jiri Olsa escreveu:

Quoted 11 lines

This patch adds a functionality that allows to create event groups based on the way they are specified on the command line. Adding functionality to the '{}' group syntax introduced in earlier patch.

The current '--group/-g' option behaviour remains intact. If you specify it for record/stat/top command, all the specified events become members of a single group with the first event as a group leader.

With the new '{}' group syntax you can create group like:

  # perf record -e '{cycles,faults}' ls

All this cset comment makes for great tools/perf/Documentation material, right? Can you try and send a patch to add this to the 'record' man page?

On top of these, that I'm merging/testing now.

- Arnaldo

author
#4 lore raw

Re: [PATCH 2/3] perf, tool: Enable grouping logic for parsed events

Quoted 10 lines · Arnaldo Carvalho de Melo

Em Fri, Jun 29, 2012 at 11:08:26AM +0200, Jiri Olsa escreveu:

Quoted 9 lines

This patch adds a functionality that allows to create event groups based on the way they are specified on the command line. Adding functionality to the '{}' group syntax introduced in earlier patch.

The current '--group/-g' option behaviour remains intact. If you specify it for record/stat/top command, all the specified events become members of a single group with the first event as a group leader.

Quoted 6 lines
Quoted 2 lines

With the new '{}' group syntax you can create group like:

  # perf record -e '{cycles,faults}' ls

All this cset comment makes for great tools/perf/Documentation material, right? Can you try and send a patch to add this to the 'record' man page?

ok, I'll send doc patch with the next patchset

jirka

maintainer
#13 lore raw
In reply to Jiri Olsa

Hi, Jiri

Quoted 11 lines · Jiri Olsa

hi,
adding support for creating event groups based on the way they are specified on the command line.

This patchset adds the '{}' style grammar to express event group, allowing so far only the 'event modifier' as group modifier.

The sample/leader modifier changes are ready, but I'm getting some weird numbers in tests, so I'll send it later. Meanwhile, it'd be nice to have at least this patchset in.. ;)

Just a question, is there a way to know about the grouping at perf report time?

Thanks,
Namhyung

Quoted 24 lines

Attached patches:
1/3 perf, tool: Add support to parse event group syntax 2/3 perf, tool: Enable grouping logic for parsed events 3/3 perf, test: Add automated tests for event group parsing

wbr,
jirka

---
 tools/perf/builtin-record.c         |   13 +--
 tools/perf/builtin-stat.c           |   13 +--
 tools/perf/builtin-test.c           |    8 +-
 tools/perf/builtin-top.c            |   12 +--
 tools/perf/util/evlist.c            |   20 ++---
 tools/perf/util/evlist.h            |    3 +-
 tools/perf/util/evsel.c             |   51 ++++++++----
 tools/perf/util/evsel.h             |   11 +--
 tools/perf/util/parse-events-test.c |  152 +++++++++++++++++++++++++++++++++++
 tools/perf/util/parse-events.c      |   32 +++++++-
 tools/perf/util/parse-events.h      |    5 +-
 tools/perf/util/parse-events.l      |    2 +
 tools/perf/util/parse-events.y      |   93 ++++++++++++++++++---
 tools/perf/util/python.c            |    7 +-
 14 files changed, 341 insertions(+), 81 deletions(-)
maintainer
#5 lore raw

Re: [PATCH 2/3] perf, tool: Enable grouping logic for parsed events

In reply to Jiri Olsa
Quoted 41 lines · Jiri Olsa

This patch adds a functionality that allows to create event groups based on the way they are specified on the command line. Adding functionality to the '{}' group syntax introduced in earlier patch.

The current '--group/-g' option behaviour remains intact. If you specify it for record/stat/top command, all the specified events become members of a single group with the first event as a group leader.

With the new '{}' group syntax you can create group like:

  # perf record -e '{cycles,faults}' ls

resulting in single event group containing 'cycles' and 'faults' events, with cycles event as group leader.

All groups are created with regards to threads and cpus. Thus recording an event group within a 2 threads on server with 4 CPUs will create 8 separate groups.

Examples (first event in brackets is group leader):

  # 1 group (cpu-clock,task-clock)
  perf record --group -e cpu-clock,task-clock ls
  perf record -e '{cpu-clock,task-clock}' ls

# 2 groups (cpu-clock,task-clock) (minor-faults,major-faults) perf record -e '{cpu-clock,task-clock},{minor-faults,major-faults}' ls

  # 1 group (cpu-clock,task-clock,minor-faults,major-faults)
  perf record --group -e cpu-clock,task-clock -e minor-faults,major-faults ls
  perf record -e '{cpu-clock,task-clock,minor-faults,major-faults}' ls

  # 2 groups (cpu-clock,task-clock) (minor-faults,major-faults)
  perf record -e '{cpu-clock,task-clock} -e '{minor-faults,major-faults}' \
   -e instructions ls

  # 1 group (cpu-clock,task-clock,minor-faults,major-faults,instructions)
  perf record --group -e cpu-clock,task-clock \
   -e minor-faults,major-faults -e instructions ls
  perf record -e '{cpu-clock,task-clock,minor-faults,major-faults,instructions}' ls
Quoted 9 lines

It's possible to use standard event modifier for a group, which spans over all events in the group and overrides any event modifier settings, for example:

  # perf record -r '{faults:k,cache-references}:u'

resulting in ':u' modifier being used for both 'faults' and 'cache-references' events, regardless of their modifier setup (':k' for faults event).

So the faults event would get only 'u' for the modifier not 'uk', right?

Thanks,
Namhyung

#33 lore raw
In reply to Jiri Olsa

Hi Jiri:

Quoted 12 lines · Jiri Olsa

hi,
adding support for creating event groups based on the way they are specified on the command line.

This patchset adds the '{}' style grammar to express event group, allowing so far only the 'event modifier' as group modifier.

The sample/leader modifier changes are ready, but I'm getting some weird numbers in tests, so I'll send it later. Meanwhile, it'd be nice to have at least this patchset in.. ;)

Quoted 4 lines

Attached patches:
1/3 perf, tool: Add support to parse event group syntax 2/3 perf, tool: Enable grouping logic for parsed events 3/3 perf, test: Add automated tests for event group parsing

Would you mind updating perf-stat and perf-record Documentation to include the group option?

David

author
#34 lore raw
Quoted 15 lines · David Ahern

Hi Jiri:

Quoted 12 lines · Jiri Olsa

hi,
adding support for creating event groups based on the way they are specified on the command line.

This patchset adds the '{}' style grammar to express event group, allowing so far only the 'event modifier' as group modifier.

The sample/leader modifier changes are ready, but I'm getting some weird numbers in tests, so I'll send it later. Meanwhile, it'd be nice to have at least this patchset in.. ;)

Quoted 7 lines
Quoted 4 lines

Attached patches:
1/3 perf, tool: Add support to parse event group syntax 2/3 perf, tool: Enable grouping logic for parsed events 3/3 perf, test: Add automated tests for event group parsing

Would you mind updating perf-stat and perf-record Documentation to include the group option?

yes, Arnaldo already stressed that.. ;) I'll send it with my next patchset

jirka

Quoted 2 lines

David

author
#6 lore raw

Re: [PATCH 2/3] perf, tool: Enable grouping logic for parsed events

In reply to Namhyung Kim
Quoted 46 lines · Namhyung Kim
Quoted 45 lines · Jiri Olsa

This patch adds a functionality that allows to create event groups based on the way they are specified on the command line. Adding functionality to the '{}' group syntax introduced in earlier patch.

The current '--group/-g' option behaviour remains intact. If you specify it for record/stat/top command, all the specified events become members of a single group with the first event as a group leader.

With the new '{}' group syntax you can create group like:

  # perf record -e '{cycles,faults}' ls

resulting in single event group containing 'cycles' and 'faults' events, with cycles event as group leader.

All groups are created with regards to threads and cpus. Thus recording an event group within a 2 threads on server with 4 CPUs will create 8 separate groups.

Examples (first event in brackets is group leader):

  # 1 group (cpu-clock,task-clock)
  perf record --group -e cpu-clock,task-clock ls
  perf record -e '{cpu-clock,task-clock}' ls

# 2 groups (cpu-clock,task-clock) (minor-faults,major-faults) perf record -e '{cpu-clock,task-clock},{minor-faults,major-faults}' ls

  # 1 group (cpu-clock,task-clock,minor-faults,major-faults)
  perf record --group -e cpu-clock,task-clock -e minor-faults,major-faults ls
  perf record -e '{cpu-clock,task-clock,minor-faults,major-faults}' ls

  # 2 groups (cpu-clock,task-clock) (minor-faults,major-faults)
  perf record -e '{cpu-clock,task-clock} -e '{minor-faults,major-faults}' \
   -e instructions ls

  # 1 group (cpu-clock,task-clock,minor-faults,major-faults,instructions)
  perf record --group -e cpu-clock,task-clock \
   -e minor-faults,major-faults -e instructions ls
  perf record -e '{cpu-clock,task-clock,minor-faults,major-faults,instructions}' ls

It's possible to use standard event modifier for a group, which spans over all events in the group and overrides any event modifier settings, for example:

Quoted 7 lines
Quoted 5 lines
  # perf record -r '{faults:k,cache-references}:u'

resulting in ':u' modifier being used for both 'faults' and 'cache-references' events, regardless of their modifier setup (':k' for faults event).

So the faults event would get only 'u' for the modifier not 'uk', right?

right

jirka

author
#14 lore raw
In reply to Namhyung Kim
Quoted 10 lines · Namhyung Kim

Hi, Jiri

Quoted 7 lines · Jiri Olsa

hi,
adding support for creating event groups based on the way they are specified on the command line.

This patchset adds the '{}' style grammar to express event group, allowing so far only the 'event modifier' as group modifier.

Quoted 7 lines
Quoted 4 lines

The sample/leader modifier changes are ready, but I'm getting some weird numbers in tests, so I'll send it later. Meanwhile, it'd be nice to have at least this patchset in.. ;)

Just a question, is there a way to know about the grouping at perf report time?

nope, AFAIK only ID and perf_event_attr is stored for event grouping is known only for record time

jirka

#35 lore raw
In reply to Jiri Olsa
Quoted 12 lines · Jiri Olsa

hi,
adding support for creating event groups based on the way they are specified on the command line.

This patchset adds the '{}' style grammar to express event group, allowing so far only the 'event modifier' as group modifier.

The sample/leader modifier changes are ready, but I'm getting some weird numbers in tests, so I'll send it later. Meanwhile, it'd be nice to have at least this patchset in.. ;)

Quoted 4 lines

Attached patches:
1/3 perf, tool: Add support to parse event group syntax 2/3 perf, tool: Enable grouping logic for parsed events 3/3 perf, test: Add automated tests for event group parsing

Yeah, they look ok, thanks Jiri!

#15 lore raw
In reply to Jiri Olsa

2012-07-02 (월), 12:15 +0200, Jiri Olsa:

Quoted 7 lines · Namhyung Kim
Quoted 2 lines

Just a question, is there a way to know about the grouping at perf report time?

nope, AFAIK only ID and perf_event_attr is stored for event grouping is known only for record time

I heard that Arnaldo (or Stephane) wanted to make perf report group-aware or such so that it can show related events together. But to do that, it seems we need to change the data file format first, right?

Any idea?

Signature · 2 lines
Regards,
Namhyung Kim
author
#16 lore raw
Quoted 9 lines · Namhyung Kim

2012-07-02 (월), 12:15 +0200, Jiri Olsa:

Quoted 7 lines · Namhyung Kim
Quoted 2 lines

Just a question, is there a way to know about the grouping at perf report time?

nope, AFAIK only ID and perf_event_attr is stored for event grouping is known only for record time

Quoted 5 lines

I heard that Arnaldo (or Stephane) wanted to make perf report group-aware or such so that it can show related events together. But to do that, it seems we need to change the data file format first, right?

Any idea?

The next change I'm working on is to record and report PERF_FORMAT_GROUP related data. Here's commit comment from my next patchset:

---
perf, tool: Enable sampling on specified event group leader

Adding the functionality to the group modifier event syntax. Allowing user to select leader event inside the group using event index (command line event position in the group).

Following example selects e2 as leader:
-e '{e1,e2,e3,e4}:2'

The selected event becomes group leader and is the only one doing samples.

The rest of the events in the group are being read on each leader event sample by PERF_SAMPLE_READ sample type processing.

Following example:
perf record -e {cycles,faults}:1 ls

- creates a group with 'cycles' and 'faults' events
- 'cycles' event is group leader and has sampling enabled
- 'faults' event is read each time 'cycles' sample, the 'faults' count is attached to the 'cycles sample via PERF_SAMPLE_READ sample type.
---

The report does not need any new metadata about grouping, because the samples are generated/stored only from the group leader. The other events data are read from the PERF_FORMAT_GROUP leader sample data.

So no data file format change for my next changes, but I'm not sure this is the report change you mean.

jirka

#17 lore raw

2012-07-02 (월), 15:33 +0200, Jiri Olsa:

Quoted 46 lines · Namhyung Kim
Quoted 9 lines

2012-07-02 (월), 12:15 +0200, Jiri Olsa:

Quoted 7 lines · Namhyung Kim
Quoted 2 lines

Just a question, is there a way to know about the grouping at perf report time?

nope, AFAIK only ID and perf_event_attr is stored for event grouping is known only for record time

Quoted 5 lines

I heard that Arnaldo (or Stephane) wanted to make perf report group-aware or such so that it can show related events together. But to do that, it seems we need to change the data file format first, right?

Any idea?

The next change I'm working on is to record and report PERF_FORMAT_GROUP related data. Here's commit comment from my next patchset:

---
perf, tool: Enable sampling on specified event group leader

Adding the functionality to the group modifier event syntax. Allowing user to select leader event inside the group using event index (command line event position in the group).

Following example selects e2 as leader:
-e '{e1,e2,e3,e4}:2'

The selected event becomes group leader and is the only one doing samples.

The rest of the events in the group are being read on each leader event sample by PERF_SAMPLE_READ sample type processing.

Following example:
perf record -e {cycles,faults}:1 ls

- creates a group with 'cycles' and 'faults' events
- 'cycles' event is group leader and has sampling enabled
- 'faults' event is read each time 'cycles' sample, the 'faults' count is attached to the 'cycles sample via PERF_SAMPLE_READ sample type.
---

Quoted 8 lines

The report does not need any new metadata about grouping, because the samples are generated/stored only from the group leader. The other events data are read from the PERF_FORMAT_GROUP leader sample data.

So no data file format change for my next changes, but I'm not sure this is the report change you mean.

What I said is just displaying cycles and faults events in above example on the same screen/table like:

(Overhead)

cycles  faults  Command      Shared object              Symbol
......  ......  .......  .................  ..................
92.98%  60.13%  noploop  noploop            [.] main
 3.21%   5.42%  noploop  [kernel.kallsyms]  [k] __lock_acquire
 1.16%  13.13%  noploop  libc-2.11.1.so     [.] _int_malloc
 0.97%   0.33%  noploop  [kernel.kallsyms]  [k] clear_page_c

...

We could pass such information to perf report explicitly, But I guess it 'd better if perf report did it for me automagically by detecting group relations.

Signature · 2 lines
Regards,
Namhyung Kim
maintainer
#18 lore raw
Quoted 3 lines · Namhyung Kim

We could pass such information to perf report explicitly, But I guess it 'd better if perf report did it for me automagically by detecting group relations.

Oh I think we can do it by parsing the command line (again) at the perf report time. In that way, no need to change the file format. I'm gonna give it a shot later.

Thanks,
Namhyung

maintainer
#7 lore raw

Re: [PATCH 2/3] perf, tool: Enable grouping logic for parsed events

In reply to Jiri Olsa
Quoted 8 lines · Jiri Olsa
Quoted 7 lines · Namhyung Kim
Quoted 6 lines · Jiri Olsa

It's possible to use standard event modifier for a group, which spans over all events in the group and overrides any event modifier settings, for example:

  # perf record -r '{faults:k,cache-references}:u'
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

resulting in ':u' modifier being used for both 'faults' and 'cache-references' events, regardless of their modifier setup (':k' for faults event).

So the faults event would get only 'u' for the modifier not 'uk', right?

right

I was thinking about the combining the modifiers - i.e. make it 'uk' above. Not sure it's useful in general, but something like "adding 'p' to the leader (only)" looks good to have IMHO.

Thanks,
Namhyung

#19 lore raw
In reply to Namhyung Kim

Em Tue, Jul 03, 2012 at 09:50:19AM +0900, Namhyung Kim escreveu:

Quoted 8 lines · Namhyung Kim
Quoted 3 lines

We could pass such information to perf report explicitly, But I guess it 'd better if perf report did it for me automagically by detecting group relations.

Oh I think we can do it by parsing the command line (again) at the perf report time. In that way, no need to change the file format. I'm gonna give it a shot later.

Its there already...

[acme@felicio ~]$ perf record -e cycles,cache-misses sleep 1 [ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.016 MB perf.data (~713 samples) ] [acme@felicio ~]$ perf report --stdio | head -20
# ========

# captured on: Mon Jul  2 22:02:00 2012
# hostname : felicio.ghostprotocols.net
# os release : 3.4.0-rc5+
# perf version : 3.5.rc1.104.gd3076383
# arch : x86_64
# nrcpus online : 4
# nrcpus avail : 4
# cpudesc : Intel(R) Core(TM) i5-2400 CPU @ 3.10GHz
# cpuid : GenuineIntel,6,42,7
# total memory : 8089800 kB
# cmdline : /home/acme/bin/perf record -e cycles,cache-misses sleep 1 
# event : name = cycles, type = 0, config = 0x0, config1 = 0x0, config2
# = 0x0, excl_usr = 0, excl_kern = 0, id = { 10, 11, 12, 13 }
# event : name = cache-misses, type = 0, config = 0x3, config1 = 0x0,
# config2 = 0x0, excl_usr = 0, excl_kern = 0, id = { 14, 15, 16, 17 }
# HEADER_CPU_TOPOLOGY info available, use -I to display
# HEADER_NUMA_TOPOLOGY info available, use -I to display
# ========
#
# Samples: 19  of event 'cycles'
# Event count (approx.): 2442170
[acme@felicio ~]$ 

I.e. for perf report it is ok already, the user can see what was asked for, exactly as specified on the command line.

What I discussed with Jiri was that it would be good to have a programatic way of regenerating the perf_evlist instance from the perf_event_attr and other feature bits.

I.e. the counterpart to perf_evsel being created from the perf_event_attr in the perf.data file.

- Arnaldo

author
#8 lore raw

Re: [PATCH 2/3] perf, tool: Enable grouping logic for parsed events

In reply to Namhyung Kim
Quoted 13 lines · Namhyung Kim
Quoted 12 lines · Jiri Olsa
Quoted 11 lines · Namhyung Kim
Quoted 9 lines · Jiri Olsa

It's possible to use standard event modifier for a group, which spans over all events in the group and overrides any event modifier settings, for example:

  # perf record -r '{faults:k,cache-references}:u'

resulting in ':u' modifier being used for both 'faults' and 'cache-references' events, regardless of their modifier setup (':k' for faults event).

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

So the faults event would get only 'u' for the modifier not 'uk', right?

right

I was thinking about the combining the modifiers - i.e. make it 'uk' above. Not sure it's useful in general, but something like "adding 'p' to the leader (only)" looks good to have IMHO.

just hit the issue with leader 'p' during tests ;) but still not sure which way is more usefull thought.. probably better to have both ways available

how about uppercase group modifier overwrites, lowercase means combining

or any other way.. ;) thoughts?

jirka

Quoted 3 lines

Thanks,
Namhyung

maintainer
#9 lore raw

Re: [PATCH 2/3] perf, tool: Enable grouping logic for parsed events

Quoted 23 lines · Jiri Olsa
Quoted 13 lines · Namhyung Kim
Quoted 12 lines · Jiri Olsa
Quoted 11 lines · Namhyung Kim
Quoted 9 lines · Jiri Olsa

It's possible to use standard event modifier for a group, which spans over all events in the group and overrides any event modifier settings, for example:

  # perf record -r '{faults:k,cache-references}:u'

resulting in ':u' modifier being used for both 'faults' and 'cache-references' events, regardless of their modifier setup (':k' for faults event).

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

So the faults event would get only 'u' for the modifier not 'uk', right?

right

I was thinking about the combining the modifiers - i.e. make it 'uk' above. Not sure it's useful in general, but something like "adding 'p' to the leader (only)" looks good to have IMHO.

Quoted 7 lines

just hit the issue with leader 'p' during tests ;) but still not sure which way is more usefull thought.. probably better to have both ways available

how about uppercase group modifier overwrites, lowercase means combining

or any other way.. ;) thoughts?

How about using like '{...}+u' for combining?

Thanks,
Namhyung

#10 lore raw

Re: [PATCH 2/3] perf, tool: Enable grouping logic for parsed events

In reply to Jiri Olsa
Quoted 1 line · Jiri Olsa

or any other way.. ;) thoughts?

What again was the downside if always doing additive (instead of overriding) attributes?

#32 lore raw
In reply to Namhyung Kim
Quoted 5 lines · Namhyung Kim

2012-07-02 (월), 12:15 +0200, Jiri Olsa:

Quoted 4 lines · Namhyung Kim
Quoted 2 lines

Just a question, is there a way to know about the grouping at perf report time?

Quoted 8 lines
Quoted 3 lines

nope, AFAIK only ID and perf_event_attr is stored for event grouping is known only for record time

I heard that Arnaldo (or Stephane) wanted to make perf report group-aware or such so that it can show related events together. But to do that, it seems we need to change the data file format first, right?

Yes, you'd like something like that. The idea is to use an event to sample and the others to compute event deltas. For instance, how many loads/stores instructions retired for every 100k instructions retired. For that you need grouping. The kernel supports this already, the perf tool does not.

I don't think you need to change the file format. Everything is there already in the headers. OF course, you perf report needs to detect this mode and adjust the output. IF not, then it should only display samples coming from the first event. Not clear how you'd display the information in perf report or perf annotate at this point yet.

Quoted 8 lines

Any idea?

--
Regards,
Namhyung Kim

#20 lore raw
In reply to Jiri Olsa
Quoted 23 lines · Jiri Olsa
Quoted 9 lines · Namhyung Kim

2012-07-02 (월), 12:15 +0200, Jiri Olsa:

Quoted 7 lines · Namhyung Kim
Quoted 2 lines

Just a question, is there a way to know about the grouping at perf report time?

nope, AFAIK only ID and perf_event_attr is stored for event grouping is known only for record time

Quoted 5 lines

I heard that Arnaldo (or Stephane) wanted to make perf report group-aware or such so that it can show related events together. But to do that, it seems we need to change the data file format first, right?

Any idea?

The next change I'm working on is to record and report PERF_FORMAT_GROUP related data. Here's commit comment from my next patchset:

---
perf, tool: Enable sampling on specified event group leader

Quoted 7 lines

Adding the functionality to the group modifier event syntax. Allowing user to select leader event inside the group using event index (command line event position in the group).

Following example selects e2 as leader:
-e '{e1,e2,e3,e4}:2'

I don't understand why you actually need the :2 suffix. There can only be one leader. So assume it is the first one. Users have to know the first one is the leader which seems like a natural thing to do for me. It would make you syntax less ugly than it already is.

I would have thought you could enable this with a simple cmdline option which changes the way you interpret the multiple -e options:

perf record --group-reads -e e1,e2,e3 -e e4,e5,e6 .....

Would setup the group leaders (e1, e4) for 2 groups. NO curly braces, no : needed.

Quoted 25 lines

The selected event becomes group leader and is the only one doing samples.

The rest of the events in the group are being read on each leader event sample by PERF_SAMPLE_READ sample type processing.

Following example:
perf record -e {cycles,faults}:1 ls

- creates a group with 'cycles' and 'faults' events
- 'cycles' event is group leader and has sampling enabled
- 'faults' event is read each time 'cycles' sample, the 'faults' count is attached to the 'cycles sample via PERF_SAMPLE_READ sample type.
---

The report does not need any new metadata about grouping, because the samples are generated/stored only from the group leader. The other events data are read from the PERF_FORMAT_GROUP leader sample data.

So no data file format change for my next changes, but I'm not sure this is the report change you mean.

jirka

#11 lore raw

Re: [PATCH 2/3] perf, tool: Enable grouping logic for parsed events

In reply to Peter Zijlstra

Em Thu, Jul 05, 2012 at 06:05:51PM +0200, Peter Zijlstra escreveu:

Quoted 5 lines · Jiri Olsa
Quoted 1 line

or any other way.. ;) thoughts?

What again was the downside if always doing additive (instead of overriding) attributes?

Yeah, I think this is the sanest way: additive. Overriding is confusing.

- Arnaldo

#21 lore raw
In reply to Stephane Eranian

Em Thu, Jul 05, 2012 at 06:15:20PM +0200, Stephane Eranian escreveu:

Quoted 7 lines · Jiri Olsa
Quoted 6 lines

perf, tool: Enable sampling on specified event group leader

Adding the functionality to the group modifier event syntax. Allowing user to select leader event inside the group using event index (command line event position in the group).

Quoted 8 lines
Quoted 3 lines

Following example selects e2 as leader:
-e '{e1,e2,e3,e4}:2'

I don't understand why you actually need the :2 suffix. There can only be one leader. So assume it is the first one. Users have to know the first one is the leader which seems like a natural thing to do for me. It would make you syntax less ugly than it already is.

Agreed, looks like creeping featurism.

Quoted 8 lines

I would have thought you could enable this with a simple cmdline option which changes the way you interpret the multiple -e options:

perf record --group-reads -e e1,e2,e3 -e e4,e5,e6 .....

Would setup the group leaders (e1, e4) for 2 groups. NO curly braces, no : needed.

Yeah, curly braces needed just when one wants to add group wide modifiers.

- Arnaldo

#22 lore raw
Quoted 23 lines · Arnaldo Carvalho de Melo

Em Thu, Jul 05, 2012 at 06:15:20PM +0200, Stephane Eranian escreveu:

Quoted 7 lines · Jiri Olsa
Quoted 6 lines

perf, tool: Enable sampling on specified event group leader

Adding the functionality to the group modifier event syntax. Allowing user to select leader event inside the group using event index (command line event position in the group).

Quoted 8 lines
Quoted 3 lines

Following example selects e2 as leader:
-e '{e1,e2,e3,e4}:2'

I don't understand why you actually need the :2 suffix. There can only be one leader. So assume it is the first one. Users have to know the first one is the leader which seems like a natural thing to do for me. It would make you syntax less ugly than it already is.

Agreed, looks like creeping featurism.

Quoted 4 lines

I would have thought you could enable this with a simple cmdline option which changes the way you interpret the multiple -e options:

Quoted 7 lines
Quoted 4 lines

perf record --group-reads -e e1,e2,e3 -e e4,e5,e6 .....

Would setup the group leaders (e1, e4) for 2 groups. NO curly braces, no : needed.

Yeah, curly braces needed just when one wants to add group wide modifiers.

And even, in that case that seems overkill too.
You can simply repeat the modifier on each event. A group cannot big that big. It is limited in size by the number of physical counters plus the events constraints.

#23 lore raw
In reply to Stephane Eranian
Quoted 5 lines · Stephane Eranian

I don't understand why you actually need the :2 suffix. There can only be one leader. So assume it is the first one. Users have to know the first one is the leader which seems like a natural thing to do for me. It would make you syntax less ugly than it already is.

In a blue sky world I would have done this. In fact, this is what I tried before reading the sources to find out there is no group support so far. But given that multiple -e options already have a meaning I would be hesitant to change this.

#24 lore raw
Quoted 11 lines · Ulrich Drepper
Quoted 5 lines · Stephane Eranian

I don't understand why you actually need the :2 suffix. There can only be one leader. So assume it is the first one. Users have to know the first one is the leader which seems like a natural thing to do for me. It would make you syntax less ugly than it already is.

In a blue sky world I would have done this. In fact, this is what I tried before reading the sources to find out there is no group support so far. But given that multiple -e options already have a meaning I would be hesitant to change this.

That's why I said you activate grouping via -e only when you have the --group-events or --group-reads option in front. That would not change the meaning of the multiple -e when none of those group options are specified.

author
#25 lore raw
Quoted 13 lines · Stephane Eranian
Quoted 11 lines · Ulrich Drepper
Quoted 5 lines · Stephane Eranian

I don't understand why you actually need the :2 suffix. There can only be one leader. So assume it is the first one. Users have to know the first one is the leader which seems like a natural thing to do for me. It would make you syntax less ugly than it already is.

In a blue sky world I would have done this. In fact, this is what I tried before reading the sources to find out there is no group support so far. But given that multiple -e options already have a meaning I would be hesitant to change this.

Quoted 4 lines

That's why I said you activate grouping via -e only when you have the --group-events or --group-reads option in front. That would not change the meaning of the multiple -e when none of those group options are specified.

I discussed this with peter..

<peterz> the {} thing allows: 1) multiple groups in a single -e, 2) group attributes

as for the leader sampling, we can have the first event to become the leader by default (omit the leader index modifier) and enable the leader sampling by another modifier:

<peterz> right, just make it a single 'l' (el not one) to indicate 'leader' sampling

jirka

#26 lore raw
Quoted 1 line · Jiri Olsa

<peterz> the {} thing allows: 1) multiple groups in a single -e

The advantage would be when you're passing such things on via environment variables or somesuch.

#27 lore raw
In reply to Jiri Olsa
Quoted 15 lines · Jiri Olsa
Quoted 13 lines · Stephane Eranian
Quoted 11 lines · Ulrich Drepper
Quoted 5 lines · Stephane Eranian

I don't understand why you actually need the :2 suffix. There can only be one leader. So assume it is the first one. Users have to know the first one is the leader which seems like a natural thing to do for me. It would make you syntax less ugly than it already is.

In a blue sky world I would have done this. In fact, this is what I tried before reading the sources to find out there is no group support so far. But given that multiple -e options already have a meaning I would be hesitant to change this.

Quoted 9 lines
Quoted 4 lines

That's why I said you activate grouping via -e only when you have the --group-events or --group-reads option in front. That would not change the meaning of the multiple -e when none of those group options are specified.

I discussed this with peter..

<peterz> the {} thing allows: 1) multiple groups in a single -e, 2) group attributes

And what's the value of 1) exactly? What's wrong with passing multiple -e ? The only group attribute I can think of would be :u, :k. Not so much typing.

Quoted 4 lines

as for the leader sampling, we can have the first event to become the leader by default (omit the leader index modifier) and enable the leader sampling by another modifier:

I don't understand this sentence.

Quoted 2 lines

<peterz> right, just make it a single 'l' (el not one) to indicate 'leader' sampling

To me ,this looks a bit of an over-engineered design and it is not based on any actual user requests. Don't get me wrong, grouping is useful and required but nobody has ever asked for that level of flexibility. The syntax you have now is already very rich for my taste.

Quoted 2 lines

jirka

#28 lore raw
Quoted 4 lines

To me ,this looks a bit of an over-engineered design and it is not based on any actual user requests. Don't get me wrong, grouping is useful and required but nobody has ever asked for that level of flexibility. The syntax you have now is already very rich for my taste.

The user input I hear is just get the basic support working ASAP.

-Andi

author
#29 lore raw
In reply to Stephane Eranian
Quoted 32 lines · Stephane Eranian
Quoted 15 lines · Jiri Olsa
Quoted 13 lines · Stephane Eranian
Quoted 11 lines · Ulrich Drepper
Quoted 5 lines · Stephane Eranian

I don't understand why you actually need the :2 suffix. There can only be one leader. So assume it is the first one. Users have to know the first one is the leader which seems like a natural thing to do for me. It would make you syntax less ugly than it already is.

In a blue sky world I would have done this. In fact, this is what I tried before reading the sources to find out there is no group support so far. But given that multiple -e options already have a meaning I would be hesitant to change this.

Quoted 9 lines
Quoted 4 lines

That's why I said you activate grouping via -e only when you have the --group-events or --group-reads option in front. That would not change the meaning of the multiple -e when none of those group options are specified.

I discussed this with peter..

<peterz> the {} thing allows: 1) multiple groups in a single -e, 2) group attributes

And what's the value of 1) exactly? What's wrong with passing multiple -e ? The only group attribute I can think of would be :u, :k. Not so much typing.

Quoted 4 lines

as for the leader sampling, we can have the first event to become the leader by default (omit the leader index modifier) and enable the leader sampling by another modifier:

Quoted 8 lines

I don't understand this sentence.

Quoted 2 lines

<peterz> right, just make it a single 'l' (el not one) to indicate 'leader' sampling

To me ,this looks a bit of an over-engineered design and it is not based on any actual user requests. Don't get me wrong, grouping is useful and required but nobody has ever asked for that level of flexibility. The syntax you have now is already very rich for my taste.

Well, I personally like the '{}' syntax more than '--group-events or --group-reads option in front', it feels more user friendly.. anyway, we can easily have both ways.

As for the group attributes and group leader sampling, I don't mind omitting them at this point and get back to that if we find it useful in future.

jirka

#30 lore raw
Quoted 2 lines · Jiri Olsa

Well, I personally like the '{}' syntax more than '--group-events or --group-reads option in front', it feels more user friendly.. anyway, we can easily have both ways.

I like the actual visual grouping better, too.

Also, it doesn't require us to define what

   -e E1,E2 --group-events -e E3,E4

means. Does --group-events also apply to the first parameter?

Quoted 2 lines

As for the group attributes and group leader sampling, I don't mind omitting them at this point and get back to that if we find it useful in future.

Just define the first event the leader. What reason is there which prevents this?

I can only second what Andi wrote: just get it done quickly. This is functionality that is desperately needed.

author
#31 lore raw
Quoted 10 lines · Ulrich Drepper
Quoted 2 lines · Jiri Olsa

Well, I personally like the '{}' syntax more than '--group-events or --group-reads option in front', it feels more user friendly.. anyway, we can easily have both ways.

I like the actual visual grouping better, too.

Also, it doesn't require us to define what

   -e E1,E2 --group-events -e E3,E4
Quoted 8 lines

means. Does --group-events also apply to the first parameter?

Quoted 2 lines

As for the group attributes and group leader sampling, I don't mind omitting them at this point and get back to that if we find it useful in future.

Just define the first event the leader. What reason is there which prevents this?

yep, no problem.. first one is the leader

The group sampling is just another feature where you enable sampling only for the leader and the rest of the events in the group are only being read on leader's sample - they don't sample by themselves.

But this feature needs more testing, and event modifier syntax rethinking ;) I'll send it later..

Quoted 2 lines

I can only second what Andi wrote: just get it done quickly. This is functionality that is desperately needed.

I have new patchset ready with group modifiers adding modifiers to events in the group, like:

{cycles:u,instructions:u}:p

adds 'p' to both events in the group
(in current patchset group modifier overwrites events modifiers)

if there's strong opinion/reasons against it, I can simply remove it, but it looks helpful

jirka