Skip to contentSkip to conversation

perf, tools: Implement branch_type event parameter

PATCH In review Andi Kleen 3 participants 5 messages Oct 12, 2016 – Oct 24, 2016 perf events

lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH 1/2 perf, tools: Implement branch_type event parameter

From: Andi Kleen <[email protected]>

It can be useful to specify branch type state per event, for example if we want to collect both software trace points and last branch PMU events in a single collection. Currently this doesn't work because the software trace point errors out with -b.

There was already a branch-type parameter to configure branch sample types per event in the parser, but it was stubbed out. This patch implements the necessary plumbing to actually enable it.

Now

perf record -e sched:sched_switch,cpu/cpu-cycles,branch_type=any/ ...

works

---
 tools/perf/util/evsel.c                |  9 ++++
 tools/perf/util/evsel.h                |  2 +
 tools/perf/util/parse-branch-options.c | 85 +++++++++++++++++++---------------
 tools/perf/util/parse-branch-options.h |  3 +-
 tools/perf/util/parse-events.c         | 15 ++++--
 5 files changed, 71 insertions(+), 43 deletions(-)
tools/perf/util/evsel.c +9 -0
index 8bc271141d9d..e58a2fbf3b16 100644
@@ -28,6 +28,7 @@
 #include "debug.h"
 #include "trace-event.h"
 #include "stat.h"
+#include "util/parse-branch-options.h"
 
 static struct {
 	bool sample_id_all;
@@ -708,6 +709,14 @@ static void apply_config_terms(struct perf_evsel *evsel,
 		case PERF_EVSEL__CONFIG_TERM_CALLGRAPH:
 			callgraph_buf = term->val.callgraph;
 			break;
+		case PERF_EVSEL__CONFIG_TERM_BRANCH:
+			if (term->val.branch && strcmp(term->val.branch, "no")) {
+				perf_evsel__set_sample_bit(evsel, BRANCH_STACK);
+				parse_branch_str(term->val.branch,
+						 &attr->branch_sample_type);
+			} else
+				perf_evsel__reset_sample_bit(evsel, BRANCH_STACK);
+			break;
 		case PERF_EVSEL__CONFIG_TERM_STACK_USER:
 			dump_size = term->val.stack_user;
 			break;
tools/perf/util/evsel.h +2 -0
index b1503b0ecdff..8cd7cd227483 100644
@@ -47,6 +47,7 @@ enum {
 	PERF_EVSEL__CONFIG_TERM_MAX_STACK,
 	PERF_EVSEL__CONFIG_TERM_OVERWRITE,
 	PERF_EVSEL__CONFIG_TERM_DRV_CFG,
+	PERF_EVSEL__CONFIG_TERM_BRANCH,
 	PERF_EVSEL__CONFIG_TERM_MAX,
 };
 
@@ -63,6 +64,7 @@ struct perf_evsel_config_term {
 		int	max_stack;
 		bool	inherit;
 		bool	overwrite;
+		char	*branch;
 	} val;
 };
 
tools/perf/util/parse-branch-options.c +47 -38

109 lines not on this page · raw message

tools/perf/util/parse-branch-options.h +2 -1
index b9d9470c2e82..6086fd90eb23 100644
@@ -1,5 +1,6 @@
 #ifndef _PERF_PARSE_BRANCH_OPTIONS_H
 #define _PERF_PARSE_BRANCH_OPTIONS_H 1
-struct option;
+#include <stdint.h>
 int parse_branch_stack(const struct option *opt, const char *str, int unset);
+int parse_branch_str(const char *str, __u64 *mode);
 #endif /* _PERF_PARSE_BRANCH_OPTIONS_H */
tools/perf/util/parse-events.c +11 -4
index 4e778eae1510..3c876b8ba4de 100644
@@ -22,6 +22,7 @@
 #include "cpumap.h"
 #include "probe-file.h"
 #include "asm/bug.h"
+#include "util/parse-branch-options.h"
 
 #define MAX_NAME_LEN 100
 
@@ -973,10 +974,13 @@ do {									   \
 		CHECK_TYPE_VAL(NUM);
 		break;
 	case PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE:
-		/*
-		 * TODO uncomment when the field is available
-		 * attr->branch_sample_type = term->val.num;
-		 */
+		CHECK_TYPE_VAL(STR);
+		if (strcmp(term->val.str, "no") &&
+		    parse_branch_str(term->val.str, &attr->branch_sample_type)) {
+			err->str = strdup("invalid branch sample type");
+			err->idx = term->err_val;
+			return -EINVAL;
+		}
 		break;
 	case PARSE_EVENTS__TERM_TYPE_TIME:
 		CHECK_TYPE_VAL(NUM);
@@ -1119,6 +1123,9 @@ do {								\
 		case PARSE_EVENTS__TERM_TYPE_CALLGRAPH:
 			ADD_CONFIG_TERM(CALLGRAPH, callgraph, term->val.str);
 			break;
+		case PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE:
+			ADD_CONFIG_TERM(BRANCH, branch, term->val.str);
+			break;
 		case PARSE_EVENTS__TERM_TYPE_STACKSIZE:
 			ADD_CONFIG_TERM(STACK_USER, stack_user, term->val.num);
 			break;
Signature · 1 line
2.5.5
author
#1 lore raw

PATCH 2/2 perf, tools: Add documentation for perf user event parameters

From: Andi Kleen <[email protected]>

There was no proper documention for the user parameters for events that the perf parser implements. Document them all in the perf list manpage.

---
 tools/perf/Documentation/perf-list.txt | 42 ++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
tools/perf/Documentation/perf-list.txt +42 -0
index 41857cce5e86..511adc684148 100644
@@ -119,6 +119,48 @@ be specified as
 
   perf stat -e cpu/event=0xa8,umask=0x1,name=LSD.UOPS_CYCLES,cmask=1/ ...
 
+EVENT PARAMETERS
+----------------
+
+The pmu// syntax in perf uses parameters to configure the event for the
+PMU.
+
+For a list of available parameters for each PMU please use
+
+  ls /sys/devices/*/format
+
+Common parameters are
+
+. event=NUM: Event code
+. umask=NUM: Event umask
+
+In addition perf supports some extra parameters to further configure then
+event
+
+. name=name: Use name to display the event in perf
+. period=NUM: Use sampling period NUM for the event. Similar to the -c parameter,
+but only applies to this event.  Only valid for perf record and top.
+. freq=NUM:  Use sampling frequency NUM for the event. Similar to the -c parameter,
+but only applies to this event.  Only valid for perf record and top.
+. branch_type=TYPE: Enable last branch sampling for event. TYPE is the same
+as the argument to perf record's -j option. Use any to be equivalent to -b.
+when no is specified branch sampling is disabled for this event. Only valid
+for perf record and top.
+. time=NUM:  When NUM is non zero collect a time stamp for the event.
+. call-graph=type: Enable call graph mode for the event. When no is specified call
+graph is disabled. The parameters are the as to the --call-graph option of
+perf record. Only valid for perf record and top.
+. stack-size=BYTES: For dwarf unwinding call graph mode limit the number of stack
+bytes collected to BYTES.
+. max-stack=NUM:  For call graph mode limit the number of entries to NUM.
+. inherit:  Inherit the event to child processes.
+. no-inherit: Do not inherit the event to child processes.
+. overwrite: Enable overwrite mode in the perf buffer.
+. no-overwrite: Do not enable overwrite mode in the perf buffer.
+. config=NUM: Configure config parameter in perf event attribute.
+. config1=NUM:  Configure config1 parameter in perf event attribute.
+. config2=NUM:  Configure config2 parameter in perf event attribute.
+
 PER SOCKET PMUS
 ---------------
 
Signature · 1 line
2.5.5
#2 lore raw

Re: [PATCH 2/2] perf, tools: Add documentation for perf user event parameters

Quoted 50 lines · Andi Kleen

From: Andi Kleen <[email protected]>

There was no proper documention for the user parameters for events that the perf parser implements. Document them all in the perf list manpage.

---
 tools/perf/Documentation/perf-list.txt | 42 ++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
tools/perf/Documentation/perf-list.txt +31 -0
index 41857cce5e86..511adc684148 100644
@@ -119,6 +119,48 @@ be specified as
 
   perf stat -e cpu/event=0xa8,umask=0x1,name=LSD.UOPS_CYCLES,cmask=1/ ...
 
+EVENT PARAMETERS
+----------------
+
+The pmu// syntax in perf uses parameters to configure the event for the
+PMU.
+
+For a list of available parameters for each PMU please use
+
+  ls /sys/devices/*/format
+
+Common parameters are
+
+. event=NUM: Event code
+. umask=NUM: Event umask
+
+In addition perf supports some extra parameters to further configure then
+event
+
+. name=name: Use name to display the event in perf
+. period=NUM: Use sampling period NUM for the event. Similar to the -c parameter,
+but only applies to this event.  Only valid for perf record and top.
+. freq=NUM:  Use sampling frequency NUM for the event. Similar to the -c parameter,
+but only applies to this event.  Only valid for perf record and top.
+. branch_type=TYPE: Enable last branch sampling for event. TYPE is the same
+as the argument to perf record's -j option. Use any to be equivalent to -b.
+when no is specified branch sampling is disabled for this event. Only valid
+for perf record and top.
+. time=NUM:  When NUM is non zero collect a time stamp for the event.
+. call-graph=type: Enable call graph mode for the event. When no is specified call
+graph is disabled. The parameters are the as to the --call-graph option of
+perf record. Only valid for perf record and top.

tools/perf/Documentation/perf-list.txt be specified as · line 162

Quoted 10 lines
tools/perf/Documentation/perf-list.txt +10 -0
+. stack-size=BYTES: For dwarf unwinding call graph mode limit the number of stack
+bytes collected to BYTES.
+. max-stack=NUM:  For call graph mode limit the number of entries to NUM.
+. inherit:  Inherit the event to child processes.
+. no-inherit: Do not inherit the event to child processes.
+. overwrite: Enable overwrite mode in the perf buffer.
+. no-overwrite: Do not enable overwrite mode in the perf buffer.
+. config=NUM: Configure config parameter in perf event attribute.
+. config1=NUM:  Configure config1 parameter in perf event attribute.
+. config2=NUM:  Configure config2 parameter in perf event attribute.

we already have some description of these in perf-record.. we might want to keep just one and have the other one point to it

thanks,
jirka

Acked-by on v1 1/2
#3 lore raw
In reply to Andi Kleen
Quoted 11 lines · Andi Kleen

From: Andi Kleen <[email protected]>

It can be useful to specify branch type state per event, for example if we want to collect both software trace points and last branch PMU events in a single collection. Currently this doesn't work because the software trace point errors out with -b.

There was already a branch-type parameter to configure branch sample types per event in the parser, but it was stubbed out. This patch implements the necessary plumbing to actually enable it.

Quoted 7 lines

Now

perf record -e sched:sched_switch,cpu/cpu-cycles,branch_type=any/ ...

works

thanks,
jirka

#4 lore raw

[tip:perf/core] perf tools: Implement branch_type event parameter

In reply to Andi Kleen
perf tools: Implement branch_type event parameter
Commit-ID:  ac12f6764c5097e791cd44f10b8943b40f44bfe7
Gitweb:     http://git.kernel.org/tip/ac12f6764c5097e791cd44f10b8943b40f44bfe7
Author:     Andi Kleen <[email protected]>
AuthorDate: Wed, 12 Oct 2016 14:02:06 -0700
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 24 Oct 2016 11:07:35 -0300

perf tools: Implement branch_type event parameter

It can be useful to specify branch type state per event, for example if we want to collect both software trace points and last branch PMU events in a single collection. Currently this doesn't work because the software trace point errors out with -b.

There was already a branch-type parameter to configure branch sample types per event in the parser, but it was stubbed out. This patch implements the necessary plumbing to actually enable it.

Now:

  $ perf record -e sched:sched_switch,cpu/cpu-cycles,branch_type=any/ ...

works.

---
 tools/perf/util/evsel.c                |  9 ++++
 tools/perf/util/evsel.h                |  2 +
 tools/perf/util/parse-branch-options.c | 85 +++++++++++++++++++---------------
 tools/perf/util/parse-branch-options.h |  3 +-
 tools/perf/util/parse-events.c         | 15 ++++--
 5 files changed, 71 insertions(+), 43 deletions(-)
tools/perf/util/evsel.c +9 -0
index 8bc2711..e58a2fb 100644
@@ -28,6 +28,7 @@
 #include "debug.h"
 #include "trace-event.h"
 #include "stat.h"
+#include "util/parse-branch-options.h"
 
 static struct {
 	bool sample_id_all;
@@ -708,6 +709,14 @@ static void apply_config_terms(struct perf_evsel *evsel,
 		case PERF_EVSEL__CONFIG_TERM_CALLGRAPH:
 			callgraph_buf = term->val.callgraph;
 			break;
+		case PERF_EVSEL__CONFIG_TERM_BRANCH:
+			if (term->val.branch && strcmp(term->val.branch, "no")) {
+				perf_evsel__set_sample_bit(evsel, BRANCH_STACK);
+				parse_branch_str(term->val.branch,
+						 &attr->branch_sample_type);
+			} else
+				perf_evsel__reset_sample_bit(evsel, BRANCH_STACK);
+			break;
 		case PERF_EVSEL__CONFIG_TERM_STACK_USER:
 			dump_size = term->val.stack_user;
 			break;
tools/perf/util/evsel.h +2 -0
index b1503b0..8cd7cd2 100644
@@ -47,6 +47,7 @@ enum {
 	PERF_EVSEL__CONFIG_TERM_MAX_STACK,
 	PERF_EVSEL__CONFIG_TERM_OVERWRITE,
 	PERF_EVSEL__CONFIG_TERM_DRV_CFG,
+	PERF_EVSEL__CONFIG_TERM_BRANCH,
 	PERF_EVSEL__CONFIG_TERM_MAX,
 };
 
@@ -63,6 +64,7 @@ struct perf_evsel_config_term {
 		int	max_stack;
 		bool	inherit;
 		bool	overwrite;
+		char	*branch;
 	} val;
 };
 
tools/perf/util/parse-branch-options.c +47 -38

109 lines not on this page · raw message

tools/perf/util/parse-branch-options.h +2 -1
index b9d9470..6086fd9 100644
@@ -1,5 +1,6 @@
 #ifndef _PERF_PARSE_BRANCH_OPTIONS_H
 #define _PERF_PARSE_BRANCH_OPTIONS_H 1
-struct option;
+#include <stdint.h>
 int parse_branch_stack(const struct option *opt, const char *str, int unset);
+int parse_branch_str(const char *str, __u64 *mode);
 #endif /* _PERF_PARSE_BRANCH_OPTIONS_H */
tools/perf/util/parse-events.c +11 -4
index 4e778ea..3c876b8 100644
@@ -22,6 +22,7 @@
 #include "cpumap.h"
 #include "probe-file.h"
 #include "asm/bug.h"
+#include "util/parse-branch-options.h"
 
 #define MAX_NAME_LEN 100
 
@@ -973,10 +974,13 @@ do {									   \
 		CHECK_TYPE_VAL(NUM);
 		break;
 	case PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE:
-		/*
-		 * TODO uncomment when the field is available
-		 * attr->branch_sample_type = term->val.num;
-		 */
+		CHECK_TYPE_VAL(STR);
+		if (strcmp(term->val.str, "no") &&
+		    parse_branch_str(term->val.str, &attr->branch_sample_type)) {
+			err->str = strdup("invalid branch sample type");
+			err->idx = term->err_val;
+			return -EINVAL;
+		}
 		break;
 	case PARSE_EVENTS__TERM_TYPE_TIME:
 		CHECK_TYPE_VAL(NUM);
@@ -1119,6 +1123,9 @@ do {								\
 		case PARSE_EVENTS__TERM_TYPE_CALLGRAPH:
 			ADD_CONFIG_TERM(CALLGRAPH, callgraph, term->val.str);
 			break;
+		case PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE:
+			ADD_CONFIG_TERM(BRANCH, branch, term->val.str);
+			break;
 		case PARSE_EVENTS__TERM_TYPE_STACKSIZE:
 			ADD_CONFIG_TERM(STACK_USER, stack_user, term->val.num);
 			break;