Skip to contentSkip to conversation

perf script: Remove default_scripting_ops

PATCH Applied Jiri Olsa 5 participants 12 messages Nov 26, 2015 – Dec 27, 2015 perf events

lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

PATCH 1/3 perf script: Remove default_scripting_ops

The default script handler (the one that displays samples on screen) is implemented scripting_ops instance with process_event callback.

This way we can't pass any script config into display function, because we don't want perl or python handlers to be depended on perf script internals.

Removing the default_scripting_ops and calling process event function directly. This way it's possible to pass perf_script struct and process configuration data in following commit.

---
 tools/perf/builtin-script.c | 43 +++++++------------------------------------
 1 file changed, 7 insertions(+), 36 deletions(-)
tools/perf/builtin-script.c +7 -36
index 72b5deb4bd79..8e3f8048d2d0 100644
@@ -643,57 +643,24 @@ static void process_event(union perf_event *event, struct perf_sample *sample,
 	printf("\n");
 }
 
-static int default_start_script(const char *script __maybe_unused,
-				int argc __maybe_unused,
-				const char **argv __maybe_unused)
-{
-	return 0;
-}
-
-static int default_flush_script(void)
-{
-	return 0;
-}
-
-static int default_stop_script(void)
-{
-	return 0;
-}
-
-static int default_generate_script(struct pevent *pevent __maybe_unused,
-				   const char *outfile __maybe_unused)
-{
-	return 0;
-}
-
-static struct scripting_ops default_scripting_ops = {
-	.start_script		= default_start_script,
-	.flush_script		= default_flush_script,
-	.stop_script		= default_stop_script,
-	.process_event		= process_event,
-	.generate_script	= default_generate_script,
-};
-
 static struct scripting_ops	*scripting_ops;
 
 static void setup_scripting(void)
 {
 	setup_perl_scripting();
 	setup_python_scripting();
-
-	scripting_ops = &default_scripting_ops;
 }
 
 static int flush_scripting(void)
 {
-	return scripting_ops->flush_script();
+	return scripting_ops ? scripting_ops->flush_script() : 0;
 }
 
 static int cleanup_scripting(void)
 {
 	pr_debug("\nperf script stopped\n");
 
-	return scripting_ops->stop_script();
+	return scripting_ops ? scripting_ops->stop_script() : 0;
 }
 
 static int process_sample_event(struct perf_tool *tool __maybe_unused,
@@ -727,7 +694,11 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
 	if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
 		goto out_put;
 
-	scripting_ops->process_event(event, sample, evsel, &al);
+	if (scripting_ops)
+		scripting_ops->process_event(event, sample, evsel, &al);
+	else
+		process_event(event, sample, evsel, &al);
+
 out_put:
 	addr_location__put(&al);
 	return 0;
Signature · 1 line
2.4.3
author reviewer
#1 lore raw

PATCH 2/3 perf script: Pass perf_script into process_event

Passing perf_script struct into process_event function.

---
 tools/perf/builtin-script.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)
tools/perf/builtin-script.c +14 -12
index 8e3f8048d2d0..3c3f8d0e3064 100644
@@ -588,8 +588,17 @@ static void print_sample_flags(u32 flags)
 	printf("  %-4s ", str);
 }
 
-static void process_event(union perf_event *event, struct perf_sample *sample,
-			  struct perf_evsel *evsel, struct addr_location *al)
+struct perf_script {
+	struct perf_tool	tool;
+	struct perf_session	*session;
+	bool			show_task_events;
+	bool			show_mmap_events;
+	bool			show_switch_events;
+};
+
+static void process_event(struct perf_script *script __maybe_unused, union perf_event *event,
+			  struct perf_sample *sample, struct perf_evsel *evsel,
+			  struct addr_location *al)
 {
 	struct thread *thread = al->thread;
 	struct perf_event_attr *attr = &evsel->attr;
@@ -663,12 +672,13 @@ static int cleanup_scripting(void)
 	return scripting_ops ? scripting_ops->stop_script() : 0;
 }
 
-static int process_sample_event(struct perf_tool *tool __maybe_unused,
+static int process_sample_event(struct perf_tool *tool,
 				union perf_event *event,
 				struct perf_sample *sample,
 				struct perf_evsel *evsel,
 				struct machine *machine)
 {
+	struct perf_script *scr = container_of(tool, struct perf_script, tool);
 	struct addr_location al;
 
 	if (debug_mode) {
@@ -697,21 +707,13 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
 	if (scripting_ops)
 		scripting_ops->process_event(event, sample, evsel, &al);
 	else
-		process_event(event, sample, evsel, &al);
+		process_event(scr, event, sample, evsel, &al);
 
 out_put:
 	addr_location__put(&al);
 	return 0;
 }
 
-struct perf_script {
-	struct perf_tool	tool;
-	struct perf_session	*session;
-	bool			show_task_events;
-	bool			show_mmap_events;
-	bool			show_switch_events;
-};
-
 static int process_attr(struct perf_tool *tool, union perf_event *event,
 			struct perf_evlist **pevlist)
 {
Signature · 1 line
2.4.3
#2 lore raw

Re: [PATCH 2/3] perf script: Pass perf_script into process_event

Em Thu, Nov 26, 2015 at 02:55:24PM +0100, Jiri Olsa escreveu:

Quoted 1 line

Passing perf_script struct into process_event function.

For? Please write the motivation for a patch.

- Arnaldo

Quoted 70 lines
---
 tools/perf/builtin-script.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)
tools/perf/builtin-script.c +14 -12
index 8e3f8048d2d0..3c3f8d0e3064 100644
@@ -588,8 +588,17 @@ static void print_sample_flags(u32 flags)
 	printf("  %-4s ", str);
 }
 
-static void process_event(union perf_event *event, struct perf_sample *sample,
-			  struct perf_evsel *evsel, struct addr_location *al)
+struct perf_script {
+	struct perf_tool	tool;
+	struct perf_session	*session;
+	bool			show_task_events;
+	bool			show_mmap_events;
+	bool			show_switch_events;
+};
+
+static void process_event(struct perf_script *script __maybe_unused, union perf_event *event,
+			  struct perf_sample *sample, struct perf_evsel *evsel,
+			  struct addr_location *al)
 {
 	struct thread *thread = al->thread;
 	struct perf_event_attr *attr = &evsel->attr;
@@ -663,12 +672,13 @@ static int cleanup_scripting(void)
 	return scripting_ops ? scripting_ops->stop_script() : 0;
 }
 
-static int process_sample_event(struct perf_tool *tool __maybe_unused,
+static int process_sample_event(struct perf_tool *tool,
 				union perf_event *event,
 				struct perf_sample *sample,
 				struct perf_evsel *evsel,
 				struct machine *machine)
 {
+	struct perf_script *scr = container_of(tool, struct perf_script, tool);
 	struct addr_location al;
 
 	if (debug_mode) {
@@ -697,21 +707,13 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
 	if (scripting_ops)
 		scripting_ops->process_event(event, sample, evsel, &al);
 	else
-		process_event(event, sample, evsel, &al);
+		process_event(scr, event, sample, evsel, &al);
 
 out_put:
 	addr_location__put(&al);
 	return 0;
 }
 
-struct perf_script {
-	struct perf_tool	tool;
-	struct perf_session	*session;
-	bool			show_task_events;
-	bool			show_mmap_events;
-	bool			show_switch_events;
-};
-
 static int process_attr(struct perf_tool *tool, union perf_event *event,
 			struct perf_evlist **pevlist)
 {
Signature · 1 line
2.4.3
#3 lore raw

PATCH v2 2/3 perf script: Pass perf_script into process_event

Quoted 4 lines · Arnaldo Carvalho de Melo

Em Thu, Nov 26, 2015 at 02:55:24PM +0100, Jiri Olsa escreveu:

Quoted 1 line

Passing perf_script struct into process_event function.

For? Please write the motivation for a patch.

for patch 3 ;-) attached with new changelog

perf/fixes branch is updated

thanks,
jirka

---
Passing perf_script struct into process_event function, so we could process configuration data for event printing.

It will be used in following patch to get event name string width.

---
 tools/perf/builtin-script.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)
tools/perf/builtin-script.c +14 -12
index 8e3f8048d2d0..3c3f8d0e3064 100644
@@ -588,8 +588,17 @@ static void print_sample_flags(u32 flags)
 	printf("  %-4s ", str);
 }
 
-static void process_event(union perf_event *event, struct perf_sample *sample,
-			  struct perf_evsel *evsel, struct addr_location *al)
+struct perf_script {
+	struct perf_tool	tool;
+	struct perf_session	*session;
+	bool			show_task_events;
+	bool			show_mmap_events;
+	bool			show_switch_events;
+};
+
+static void process_event(struct perf_script *script __maybe_unused, union perf_event *event,
+			  struct perf_sample *sample, struct perf_evsel *evsel,
+			  struct addr_location *al)
 {
 	struct thread *thread = al->thread;
 	struct perf_event_attr *attr = &evsel->attr;
@@ -663,12 +672,13 @@ static int cleanup_scripting(void)
 	return scripting_ops ? scripting_ops->stop_script() : 0;
 }
 
-static int process_sample_event(struct perf_tool *tool __maybe_unused,
+static int process_sample_event(struct perf_tool *tool,
 				union perf_event *event,
 				struct perf_sample *sample,
 				struct perf_evsel *evsel,
 				struct machine *machine)
 {
+	struct perf_script *scr = container_of(tool, struct perf_script, tool);
 	struct addr_location al;
 
 	if (debug_mode) {
@@ -697,21 +707,13 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
 	if (scripting_ops)
 		scripting_ops->process_event(event, sample, evsel, &al);
 	else
-		process_event(event, sample, evsel, &al);
+		process_event(scr, event, sample, evsel, &al);
 
 out_put:
 	addr_location__put(&al);
 	return 0;
 }
 
-struct perf_script {
-	struct perf_tool	tool;
-	struct perf_session	*session;
-	bool			show_task_events;
-	bool			show_mmap_events;
-	bool			show_switch_events;
-};
-
 static int process_attr(struct perf_tool *tool, union perf_event *event,
 			struct perf_evlist **pevlist)
 {
Signature · 1 line
2.4.3
#4 lore raw

[tip:perf/core] perf script: Pass perf_script into process_event

perf script: Pass perf_script into process_event
Commit-ID:  809e9423d7bc72e50d94d8267bab010a007a6137
Gitweb:     http://git.kernel.org/tip/809e9423d7bc72e50d94d8267bab010a007a6137
Author:     Jiri Olsa <[email protected]>
AuthorDate: Thu, 26 Nov 2015 18:55:21 +0100
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 26 Nov 2015 16:06:16 -0300

perf script: Pass perf_script into process_event

Passing perf_script struct into process_event function, so we could process configuration data for event printing.

It will be used in following patch to get event name string width.

---
 tools/perf/builtin-script.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)
tools/perf/builtin-script.c +14 -12
index 8e3f804..3c3f8d0 100644
@@ -588,8 +588,17 @@ static void print_sample_flags(u32 flags)
 	printf("  %-4s ", str);
 }
 
-static void process_event(union perf_event *event, struct perf_sample *sample,
-			  struct perf_evsel *evsel, struct addr_location *al)
+struct perf_script {
+	struct perf_tool	tool;
+	struct perf_session	*session;
+	bool			show_task_events;
+	bool			show_mmap_events;
+	bool			show_switch_events;
+};
+
+static void process_event(struct perf_script *script __maybe_unused, union perf_event *event,
+			  struct perf_sample *sample, struct perf_evsel *evsel,
+			  struct addr_location *al)
 {
 	struct thread *thread = al->thread;
 	struct perf_event_attr *attr = &evsel->attr;
@@ -663,12 +672,13 @@ static int cleanup_scripting(void)
 	return scripting_ops ? scripting_ops->stop_script() : 0;
 }
 
-static int process_sample_event(struct perf_tool *tool __maybe_unused,
+static int process_sample_event(struct perf_tool *tool,
 				union perf_event *event,
 				struct perf_sample *sample,
 				struct perf_evsel *evsel,
 				struct machine *machine)
 {
+	struct perf_script *scr = container_of(tool, struct perf_script, tool);
 	struct addr_location al;
 
 	if (debug_mode) {
@@ -697,21 +707,13 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
 	if (scripting_ops)
 		scripting_ops->process_event(event, sample, evsel, &al);
 	else
-		process_event(event, sample, evsel, &al);
+		process_event(scr, event, sample, evsel, &al);
 
 out_put:
 	addr_location__put(&al);
 	return 0;
 }
 
-struct perf_script {
-	struct perf_tool	tool;
-	struct perf_session	*session;
-	bool			show_task_events;
-	bool			show_mmap_events;
-	bool			show_switch_events;
-};
-
 static int process_attr(struct perf_tool *tool, union perf_event *event,
 			struct perf_evlist **pevlist)
 {
author reviewer
#5 lore raw

PATCH 3/3 perf script: Align event name properly

In reply to Jiri Olsa

Adding code to align event names, so we get aligned output in case of multiple events with different names.

Before:

  $ perf script
  :13757 13757 163918.230829: cpu/mem-snp-none/P: ffff88085f20d010
  :13757 13757 163918.230832: cpu/mem-loads,ldlat=30/P:     7f5a5f719f00
  :13757 13757 163918.230835: cpu/mem-loads,ldlat=30/P:     7f5a5f719f00
  :13758 13758 163918.230838: cpu/mem-snp-none/P: ffff88085f4ad810
  :13758 13758 163918.154093: cpu/mem-stores/P: ffff88085bb53f28
  :13757 13757 163918.155264: cpu/mem-snp-hitm/P:           601080
  ...

After:

  $ perf script
  :13757 13757 163918.228831:       cpu/mem-snp-none/P: ffffffff81a841c0
  :13757 13757 163918.228834: cpu/mem-loads,ldlat=30/P:     7f5a5f719f08
  :13757 13757 163918.228837: cpu/mem-loads,ldlat=30/P:     7f5a5f719f08
  :13758 13758 163918.228837:       cpu/mem-snp-none/P: ffff88085f4ad800
  :13758 13758 163918.154093:         cpu/mem-stores/P: ffff88085bb53f28
  :13757 13757 163918.155264:       cpu/mem-snp-hitm/P:           601080
  ...
---
 tools/perf/builtin-script.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
tools/perf/builtin-script.c +22 -2
index 3c3f8d0e3064..10a96da0ea56 100644
@@ -594,9 +594,24 @@ struct perf_script {
 	bool			show_task_events;
 	bool			show_mmap_events;
 	bool			show_switch_events;
+	int			name_width;
 };
 
-static void process_event(struct perf_script *script __maybe_unused, union perf_event *event,
+static int perf_evlist__max_name_len(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel;
+	int max = 0;
+
+	evlist__for_each(evlist, evsel) {
+		int len = strlen(perf_evsel__name(evsel));
+
+		max = MAX(len, max);
+	}
+
+	return max;
+}
+
+static void process_event(struct perf_script *script, union perf_event *event,
 			  struct perf_sample *sample, struct perf_evsel *evsel,
 			  struct addr_location *al)
 {
@@ -613,7 +628,12 @@ static void process_event(struct perf_script *script __maybe_unused, union perf_
 
 	if (PRINT_FIELD(EVNAME)) {
 		const char *evname = perf_evsel__name(evsel);
-		printf("%s: ", evname ? evname : "[unknown]");
+
+		if (!script->name_width)
+			script->name_width = perf_evlist__max_name_len(script->session->evlist);
+
+		printf("%*s: ", script->name_width,
+		       evname ? evname : "[unknown]");
 	}
 
 	if (print_flags)
Signature · 1 line
2.4.3
Acked-by on v1 3/3
#6 lore raw

Re: [PATCH 3/3] perf script: Align event name properly

Quoted 4 lines · Jiri Olsa

Adding code to align event names, so we get aligned output in case of multiple events with different names.

Before:

Quoted 9 lines
   $ perf script
   :13757 13757 163918.230829: cpu/mem-snp-none/P: ffff88085f20d010
   :13757 13757 163918.230832: cpu/mem-loads,ldlat=30/P:     7f5a5f719f00
   :13757 13757 163918.230835: cpu/mem-loads,ldlat=30/P:     7f5a5f719f00
   :13758 13758 163918.230838: cpu/mem-snp-none/P: ffff88085f4ad810
   :13758 13758 163918.154093: cpu/mem-stores/P: ffff88085bb53f28
   :13757 13757 163918.155264: cpu/mem-snp-hitm/P:           601080
   ...

What's up with the ":13757" for the process name?

Patches LGTM

#7 lore raw

Re: [PATCH 3/3] perf script: Align event name properly

Quoted 15 lines · David Ahern
Quoted 4 lines · Jiri Olsa

Adding code to align event names, so we get aligned output in case of multiple events with different names.

Before:

Quoted 9 lines
  $ perf script
  :13757 13757 163918.230829: cpu/mem-snp-none/P: ffff88085f20d010
  :13757 13757 163918.230832: cpu/mem-loads,ldlat=30/P:     7f5a5f719f00
  :13757 13757 163918.230835: cpu/mem-loads,ldlat=30/P:     7f5a5f719f00
  :13758 13758 163918.230838: cpu/mem-snp-none/P: ffff88085f4ad810
  :13758 13758 163918.154093: cpu/mem-stores/P: ffff88085bb53f28
  :13757 13757 163918.155264: cpu/mem-snp-hitm/P:           601080
  ...
Quoted 1 line

What's up with the ":13757" for the process name?

hum, fallback if the name's not resolved? I'll check..

thanks,
jirka

Quoted 5 lines

Patches LGTM

#8 lore raw

Re: [PATCH 3/3] perf script: Align event name properly

Quoted 16 lines · Jiri Olsa
Quoted 15 lines · David Ahern
Quoted 13 lines · Jiri Olsa

Adding code to align event names, so we get aligned output in case of multiple events with different names.

Before:

   $ perf script
   :13757 13757 163918.230829: cpu/mem-snp-none/P: ffff88085f20d010
   :13757 13757 163918.230832: cpu/mem-loads,ldlat=30/P:     7f5a5f719f00
   :13757 13757 163918.230835: cpu/mem-loads,ldlat=30/P:     7f5a5f719f00
   :13758 13758 163918.230838: cpu/mem-snp-none/P: ffff88085f4ad810
   :13758 13758 163918.154093: cpu/mem-stores/P: ffff88085bb53f28
   :13757 13757 163918.155264: cpu/mem-snp-hitm/P:           601080
   ...
Quoted 3 lines
Quoted 1 line

What's up with the ":13757" for the process name?

hum, fallback if the name's not resolved? I'll check..

right, but I thought those were fixed. How is there a SAMPLE for a task without a COMM.

#9 lore raw

Re: [PATCH 3/3] perf script: Align event name properly

In reply to David Ahern
Quoted 15 lines · David Ahern
Quoted 4 lines · Jiri Olsa

Adding code to align event names, so we get aligned output in case of multiple events with different names.

Before:

Quoted 9 lines
  $ perf script
  :13757 13757 163918.230829: cpu/mem-snp-none/P: ffff88085f20d010
  :13757 13757 163918.230832: cpu/mem-loads,ldlat=30/P:     7f5a5f719f00
  :13757 13757 163918.230835: cpu/mem-loads,ldlat=30/P:     7f5a5f719f00
  :13758 13758 163918.230838: cpu/mem-snp-none/P: ffff88085f4ad810
  :13758 13758 163918.154093: cpu/mem-stores/P: ffff88085bb53f28
  :13757 13757 163918.155264: cpu/mem-snp-hitm/P:           601080
  ...
Quoted 5 lines

What's up with the ":13757" for the process name?

Patches LGTM

this one was missed, I pushed it on the top of my perf/fixes branch with David's ack

thanks,
jirka

maintainer Applied
#10 lore raw
In reply to Jiri Olsa

Em Thu, Nov 26, 2015 at 02:55:23PM +0100, Jiri Olsa escreveu:

Quoted 7 lines

The default script handler (the one that displays samples on screen) is implemented scripting_ops instance with process_event callback.

This way we can't pass any script config into display function, because we don't want perl or python handlers to be depended on perf script internals.

Quoted 6 lines

Removing the default_scripting_ops and calling process event function directly. This way it's possible to pass perf_script struct and process configuration data in following commit.

Applied, with David's ack.

- Arnaldo

#11 lore raw
In reply to Jiri Olsa
perf script: Remove default_scripting_ops
Commit-ID:  2aaecfc51bc65532152e141df3268fda06cae029
Gitweb:     http://git.kernel.org/tip/2aaecfc51bc65532152e141df3268fda06cae029
Author:     Jiri Olsa <[email protected]>
AuthorDate: Thu, 26 Nov 2015 14:55:23 +0100
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 26 Nov 2015 13:33:00 -0300

perf script: Remove default_scripting_ops

The default script handler (the one that displays samples on screen) is implemented scripting_ops instance with process_event callback.

This way we can't pass any script config into display function, because we don't want perl or python handlers to be depended on perf script internals.

Removing the default_scripting_ops and calling process event function directly. This way it's possible to pass perf_script struct and process configuration data in following commit.

---
 tools/perf/builtin-script.c | 43 +++++++------------------------------------
 1 file changed, 7 insertions(+), 36 deletions(-)
tools/perf/builtin-script.c +7 -36
index 72b5deb..8e3f804 100644
@@ -643,57 +643,24 @@ static void process_event(union perf_event *event, struct perf_sample *sample,
 	printf("\n");
 }
 
-static int default_start_script(const char *script __maybe_unused,
-				int argc __maybe_unused,
-				const char **argv __maybe_unused)
-{
-	return 0;
-}
-
-static int default_flush_script(void)
-{
-	return 0;
-}
-
-static int default_stop_script(void)
-{
-	return 0;
-}
-
-static int default_generate_script(struct pevent *pevent __maybe_unused,
-				   const char *outfile __maybe_unused)
-{
-	return 0;
-}
-
-static struct scripting_ops default_scripting_ops = {
-	.start_script		= default_start_script,
-	.flush_script		= default_flush_script,
-	.stop_script		= default_stop_script,
-	.process_event		= process_event,
-	.generate_script	= default_generate_script,
-};
-
 static struct scripting_ops	*scripting_ops;
 
 static void setup_scripting(void)
 {
 	setup_perl_scripting();
 	setup_python_scripting();
-
-	scripting_ops = &default_scripting_ops;
 }
 
 static int flush_scripting(void)
 {
-	return scripting_ops->flush_script();
+	return scripting_ops ? scripting_ops->flush_script() : 0;
 }
 
 static int cleanup_scripting(void)
 {
 	pr_debug("\nperf script stopped\n");
 
-	return scripting_ops->stop_script();
+	return scripting_ops ? scripting_ops->stop_script() : 0;
 }
 
 static int process_sample_event(struct perf_tool *tool __maybe_unused,
@@ -727,7 +694,11 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
 	if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
 		goto out_put;
 
-	scripting_ops->process_event(event, sample, evsel, &al);
+	if (scripting_ops)
+		scripting_ops->process_event(event, sample, evsel, &al);
+	else
+		process_event(event, sample, evsel, &al);
+
 out_put:
 	addr_location__put(&al);
 	return 0;