Skip to contentSkip to conversation

perf ui/browser: Add browser for perf script

PATCH In review Feng Tang 3 participants 17 messages Sep 7, 2012 – Sep 19, 2012 perf events

lore
Share & tools
lore

Feng Tang

author
#0 lore raw

v2 cover perf ui/browser: Add browser for perf script

Hi Arnaldo and all,

This is a patch set mainly to add a browser for perf script, which will be integrated into the main hists and annotation browser.

Patch 1-4 are some preparation for adding the script
patch 5 introduce the script browser
patch 6-7 integrate the browser to hists browser and annotation browser

The patches are on top of current perf/core branch of your git tree. Please help to review.

Namhyung,

Many thanks for providing many good comments for the v1 patch sets. In this v2, I addressed most of those comments, for the suggestion to use browser for "perf script -l", I'll handle it later, and would post the v2 first for review.

Changelog:
Since v1:
* Add filter for scripts can't be run in script browser
* Fix some bugs about buffer handling and error check

Feng
-----------------------
Feng Tang (7):
perf symbols: Filter samples with unresolved symbol when "--symbols"
option is used
perf scripts: Add --symbols option to handle specific symbols perf scripts: Add event_analyzing_sample-record/report perf scripts: Export a find_scripts() function
perf ui/browser: Add a browser for perf script
perf ui/browser: Integrate script browser into annotation browser perf ui/browser: Integrate script browser into main hists browser

 tools/perf/Makefile                                |    4 +
 tools/perf/builtin-script.c                        |   58 ++++++
 tools/perf/builtin.h                               |    1 +
 .../python/bin/event_analyzing_sample-record       |    8 +
 .../python/bin/event_analyzing_sample-report       |    3 +
 tools/perf/ui/browsers/annotate.c                  |    6 +
 tools/perf/ui/browsers/hists.c                     |   37 ++++
 tools/perf/ui/browsers/scripts.c                   |  182 ++++++++++++++++++++
 tools/perf/util/event.c                            |    5 +-
 tools/perf/util/hist.h                             |    7 +
 10 files changed, 309 insertions(+), 2 deletions(-)
 create mode 100644 tools/perf/scripts/python/bin/event_analyzing_sample-record
 create mode 100644 tools/perf/scripts/python/bin/event_analyzing_sample-report
 create mode 100644 tools/perf/ui/browsers/scripts.c
author
#1 lore raw

PATCH v2 1/7 perf symbols: Filter samples with unresolved symbol when "--symbols" option is used

Report/top commands support to only handle specific symbols with "--symbols" option, but current code will keep those samples whose symbol can't be resolved, which should actually be filtered.

If we run following commands:
$perf record -a tree
$perf report --symbols intel_idle -n
the output will be:

Without the patch:
==================

    46.27%        156     sshd  [unknown]
    26.05%         48  swapper  [kernel.kallsyms]
    17.26%         38     tree  libc-2.12.1.so
     7.69%         17     tree  tree
     2.73%          6     tree  ld-2.12.1.so

With the patch:
===============
100.00% 48 swapper [kernel.kallsyms]

---
 tools/perf/util/event.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
tools/perf/util/event.c +3 -2
index 3a0f1a5..08910f0 100644
@@ -886,8 +886,9 @@ int perf_event__preprocess_sample(const union perf_event *event,
 		al->sym = map__find_symbol(al->map, al->addr, filter);
 	}
 
-	if (symbol_conf.sym_list && al->sym &&
-	    !strlist__has_entry(symbol_conf.sym_list, al->sym->name))
+	if (symbol_conf.sym_list &&
+		(!al->sym || !strlist__has_entry(symbol_conf.sym_list,
+						al->sym->name)))
 		goto out_filtered;
 
 	return 0;
Signature · 1 line
1.7.1
#2 lore raw

[tip:perf/core] perf symbols: Filter samples with unresolved symbol when "--symbols" option is used

Commit-ID:  1500b93b61fc70a1176871b64f1c8ae3bd4da9dd
Gitweb:     http://git.kernel.org/tip/1500b93b61fc70a1176871b64f1c8ae3bd4da9dd
Author:     Feng Tang <[email protected]>
AuthorDate: Fri, 7 Sep 2012 16:42:23 +0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 17 Sep 2012 13:10:57 -0300

perf symbols: Filter samples with unresolved symbol when "--symbols" option is used

Report/top commands support to only handle specific symbols with "--symbols" option, but current code will keep those samples whose symbol can't be resolved, which should actually be filtered.

If we run following commands:
$perf record -a tree
$perf report --symbols intel_idle -n
the output will be:

Without the patch:
==================

    46.27%        156     sshd  [unknown]
    26.05%         48  swapper  [kernel.kallsyms]
    17.26%         38     tree  libc-2.12.1.so
     7.69%         17     tree  tree
     2.73%          6     tree  ld-2.12.1.so

With the patch:
===============
100.00% 48 swapper [kernel.kallsyms]

---
 tools/perf/util/event.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
tools/perf/util/event.c +3 -2
index 8202f5c..6715b19 100644
@@ -904,8 +904,9 @@ int perf_event__preprocess_sample(const union perf_event *event,
 		al->sym = map__find_symbol(al->map, al->addr, filter);
 	}
 
-	if (symbol_conf.sym_list && al->sym &&
-	    !strlist__has_entry(symbol_conf.sym_list, al->sym->name))
+	if (symbol_conf.sym_list &&
+		(!al->sym || !strlist__has_entry(symbol_conf.sym_list,
+						al->sym->name)))
 		goto out_filtered;
 
 	return 0;
author
#3 lore raw

PATCH v2 2/7 perf scripts: Add --symbols option to handle specific symbols

In reply to Feng Tang

Since perf script no longer only handle the trace points, we can add the symbol filter option so that scripts can handle specified samples.

---
 tools/perf/builtin-script.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
tools/perf/builtin-script.c +3 -0
index 2d6e3b2..7ab86bb 100644
@@ -14,6 +14,7 @@
 #include "util/util.h"
 #include "util/evlist.h"
 #include "util/evsel.h"
+#include "util/sort.h"
 #include <linux/bitmap.h>
 
 static char const		*script_name;
@@ -1142,6 +1143,8 @@ static const struct option options[] = {
 		     parse_output_fields),
 	OPT_BOOLEAN('a', "all-cpus", &system_wide,
 		     "system-wide collection from all CPUs"),
+	OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
+		   "only consider these symbols"),
 	OPT_STRING('C', "cpu", &cpu_list, "cpu", "list of cpus to profile"),
 	OPT_STRING('c', "comms", &symbol_conf.comm_list_str, "comm[,comm...]",
 		   "only display events for these comms"),
Signature · 1 line
1.7.1
#4 lore raw

[tip:perf/core] perf scripts: Add --symbols option to handle specific symbols

Commit-ID:  36385be55da10b3271407c45c3a62d9af3db666e
Gitweb:     http://git.kernel.org/tip/36385be55da10b3271407c45c3a62d9af3db666e
Author:     Feng Tang <[email protected]>
AuthorDate: Fri, 7 Sep 2012 16:42:24 +0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 17 Sep 2012 13:11:06 -0300

perf scripts: Add --symbols option to handle specific symbols

Since perf script no longer only handle the trace points, we can add the symbol filter option so that scripts can handle specified samples.

---
 tools/perf/builtin-script.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
tools/perf/builtin-script.c +3 -0
index 6d98a83..76577e6 100644
@@ -14,6 +14,7 @@
 #include "util/util.h"
 #include "util/evlist.h"
 #include "util/evsel.h"
+#include "util/sort.h"
 #include <linux/bitmap.h>
 
 static char const		*script_name;
@@ -1143,6 +1144,8 @@ static const struct option options[] = {
 		     parse_output_fields),
 	OPT_BOOLEAN('a', "all-cpus", &system_wide,
 		     "system-wide collection from all CPUs"),
+	OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
+		   "only consider these symbols"),
 	OPT_STRING('C', "cpu", &cpu_list, "cpu", "list of cpus to profile"),
 	OPT_STRING('c', "comms", &symbol_conf.comm_list_str, "comm[,comm...]",
 		   "only display events for these comms"),
author
#5 lore raw

PATCH v2 3/7 perf scripts: Add event_analyzing_sample-record/report

In reply to Feng Tang

So that event_analyzing_sample.py can be shown by "perf script -l"

---
 .../python/bin/event_analyzing_sample-record       |    8 ++++++++
 .../python/bin/event_analyzing_sample-report       |    3 +++
 2 files changed, 11 insertions(+), 0 deletions(-)
 create mode 100644 tools/perf/scripts/python/bin/event_analyzing_sample-record
 create mode 100644 tools/perf/scripts/python/bin/event_analyzing_sample-report
tools/perf/scripts/python/bin/event_analyzing_sample-record new file +8 -0
new file mode 100644
index 0000000..5ce652d
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+#
+# event_analyzing_sample.py can cover all type of perf samples including
+# the tracepoints, so no special record requirements, just record what
+# you want to analyze.
+#
+perf record $@
tools/perf/scripts/python/bin/event_analyzing_sample-report new file +3 -0
new file mode 100644
index 0000000..0941fc9
@@ -0,0 +1,3 @@
+#!/bin/bash
+# description: analyze all perf samples
+perf script $@ -s "$PERF_EXEC_PATH"/scripts/python/event_analyzing_sample.py
Signature · 1 line
1.7.1
#6 lore raw

[tip:perf/core] perf scripts: Add event_analyzing_sample-record/ report

Commit-ID:  59cbea229473350168930941986ebe5bf685cc23
Gitweb:     http://git.kernel.org/tip/59cbea229473350168930941986ebe5bf685cc23
Author:     Feng Tang <[email protected]>
AuthorDate: Fri, 7 Sep 2012 16:42:25 +0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 17 Sep 2012 13:11:15 -0300

perf scripts: Add event_analyzing_sample-record/report

So that event_analyzing_sample.py can be shown by "perf script -l"

---
 .../python/bin/event_analyzing_sample-record       |    8 ++++++++
 .../python/bin/event_analyzing_sample-report       |    3 +++
 2 files changed, 11 insertions(+), 0 deletions(-)
tools/perf/scripts/python/bin/event_analyzing_sample-record new file +8 -0
new file mode 100644
index 0000000..5ce652d
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+#
+# event_analyzing_sample.py can cover all type of perf samples including
+# the tracepoints, so no special record requirements, just record what
+# you want to analyze.
+#
+perf record $@
tools/perf/scripts/python/bin/event_analyzing_sample-report new file +3 -0
new file mode 100644
index 0000000..0941fc9
@@ -0,0 +1,3 @@
+#!/bin/bash
+# description: analyze all perf samples
+perf script $@ -s "$PERF_EXEC_PATH"/scripts/python/event_analyzing_sample.py
author
#7 lore raw

PATCH v2 4/7 perf scripts: Export a find_scripts() function

In reply to Feng Tang

So that other perf commands/browser has a way to dig out the available scripts info in system, this is a preparation for the script browser.

---
 tools/perf/builtin-script.c |   55 +++++++++++++++++++++++++++++++++++++++++++
 tools/perf/builtin.h        |    1 +
 2 files changed, 56 insertions(+), 0 deletions(-)
tools/perf/builtin-script.c +55 -0
index 7ab86bb..79f21d5 100644
@@ -1031,6 +1031,61 @@ static int list_available_scripts(const struct option *opt __used,
 	exit(0);
 }
 
+/*
+ * Return -1 if none is found, otherwise the actual scripts number.
+ *
+ * Currently the only user of this function is the script browser, which
+ * will list all statically runnable scripts, select one, execute it and
+ * show the output in a perf browser.
+ */
+int find_scripts(char **scripts_array, char **scripts_path_array)
+{
+	struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
+	char scripts_path[MAXPATHLEN];
+	DIR *scripts_dir, *lang_dir;
+	char lang_path[MAXPATHLEN];
+	char *temp;
+	int i = 0;
+
+	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
+
+	scripts_dir = opendir(scripts_path);
+	if (!scripts_dir)
+		return -1;
+
+	for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) {
+		snprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path,
+			 lang_dirent.d_name);
+#ifdef NO_LIBPERL
+		if (strstr(lang_path, "perl"))
+			continue;
+#endif
+#ifdef NO_LIBPYTHON
+		if (strstr(lang_path, "python"))
+			continue;
+#endif
+
+		lang_dir = opendir(lang_path);
+		if (!lang_dir)
+			continue;
+
+		for_each_script(lang_path, lang_dir, script_dirent, script_next) {
+			/* Skip those real time scripts: xxxtop.p[yl] */
+			if (strstr(script_dirent.d_name, "top."))
+				continue;
+			sprintf(scripts_path_array[i], "%s/%s", lang_path,
+				script_dirent.d_name);
+			temp = strchr(script_dirent.d_name, '.');
+			snprintf(scripts_array[i],
+				(temp - script_dirent.d_name) + 1,
+				"%s", script_dirent.d_name);
+			i++;
+		}
+	}
+
+	return i;
+}
+
 static char *get_script_path(const char *script_root, const char *suffix)
 {
 	struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
tools/perf/builtin.h +1 -0
index b382bd5..3ea74ed 100644
@@ -36,4 +36,5 @@ extern int cmd_kvm(int argc, const char **argv, const char *prefix);
 extern int cmd_test(int argc, const char **argv, const char *prefix);
 extern int cmd_inject(int argc, const char **argv, const char *prefix);
 
+extern int find_scripts(char **scripts_array, char **scripts_path_array);
 #endif
Signature · 1 line
1.7.1
#8 lore raw

[tip:perf/core] perf scripts: Export a find_scripts() function

Commit-ID:  e5f3705e62b03251797a5173024184bfc223599d
Gitweb:     http://git.kernel.org/tip/e5f3705e62b03251797a5173024184bfc223599d
Author:     Feng Tang <[email protected]>
AuthorDate: Fri, 7 Sep 2012 16:42:26 +0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 17 Sep 2012 13:11:26 -0300

perf scripts: Export a find_scripts() function

So that other perf commands/browser has a way to dig out the available scripts info in system, this is a preparation for the script browser.

---
 tools/perf/builtin-script.c |   55 +++++++++++++++++++++++++++++++++++++++++++
 tools/perf/builtin.h        |    1 +
 2 files changed, 56 insertions(+), 0 deletions(-)
tools/perf/builtin-script.c +55 -0
index 76577e6..1be843a 100644
@@ -1032,6 +1032,61 @@ static int list_available_scripts(const struct option *opt __maybe_unused,
 	exit(0);
 }
 
+/*
+ * Return -1 if none is found, otherwise the actual scripts number.
+ *
+ * Currently the only user of this function is the script browser, which
+ * will list all statically runnable scripts, select one, execute it and
+ * show the output in a perf browser.
+ */
+int find_scripts(char **scripts_array, char **scripts_path_array)
+{
+	struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
+	char scripts_path[MAXPATHLEN];
+	DIR *scripts_dir, *lang_dir;
+	char lang_path[MAXPATHLEN];
+	char *temp;
+	int i = 0;
+
+	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
+
+	scripts_dir = opendir(scripts_path);
+	if (!scripts_dir)
+		return -1;
+
+	for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) {
+		snprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path,
+			 lang_dirent.d_name);
+#ifdef NO_LIBPERL
+		if (strstr(lang_path, "perl"))
+			continue;
+#endif
+#ifdef NO_LIBPYTHON
+		if (strstr(lang_path, "python"))
+			continue;
+#endif
+
+		lang_dir = opendir(lang_path);
+		if (!lang_dir)
+			continue;
+
+		for_each_script(lang_path, lang_dir, script_dirent, script_next) {
+			/* Skip those real time scripts: xxxtop.p[yl] */
+			if (strstr(script_dirent.d_name, "top."))
+				continue;
+			sprintf(scripts_path_array[i], "%s/%s", lang_path,
+				script_dirent.d_name);
+			temp = strchr(script_dirent.d_name, '.');
+			snprintf(scripts_array[i],
+				(temp - script_dirent.d_name) + 1,
+				"%s", script_dirent.d_name);
+			i++;
+		}
+	}
+
+	return i;
+}
+
 static char *get_script_path(const char *script_root, const char *suffix)
 {
 	struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
tools/perf/builtin.h +1 -0
index b382bd5..3ea74ed 100644
@@ -36,4 +36,5 @@ extern int cmd_kvm(int argc, const char **argv, const char *prefix);
 extern int cmd_test(int argc, const char **argv, const char *prefix);
 extern int cmd_inject(int argc, const char **argv, const char *prefix);
 
+extern int find_scripts(char **scripts_array, char **scripts_path_array);
 #endif
author
#9 lore raw

PATCH v2 5/7 perf ui/browser: Add a browser for perf script

In reply to Feng Tang

Create a script browser, so that user can check all the available scripts and run them inside the main perf report or annotation browsers, for all the perf samples or samples belong to one thread/symbol.

The work flow is, users can use function key to list all the available scripts in system and chose one, which will be executed with popen("perf script -s xxx.xx",) and all the output lines are put into one ui browser, pressing 'q' or left arrow key will make it return to previous browser.

---
 tools/perf/Makefile              |    4 +
 tools/perf/ui/browsers/scripts.c |  182 ++++++++++++++++++++++++++++++++++++++
 tools/perf/util/hist.h           |    7 ++
 3 files changed, 193 insertions(+), 0 deletions(-)
 create mode 100644 tools/perf/ui/browsers/scripts.c
tools/perf/Makefile +4 -0
index cd196bc..941e700 100644
@@ -579,6 +579,7 @@ else
 		LIB_OBJS += $(OUTPUT)ui/browsers/annotate.o
 		LIB_OBJS += $(OUTPUT)ui/browsers/hists.o
 		LIB_OBJS += $(OUTPUT)ui/browsers/map.o
+		LIB_OBJS += $(OUTPUT)ui/browsers/scripts.o
 		LIB_OBJS += $(OUTPUT)ui/progress.o
 		LIB_OBJS += $(OUTPUT)ui/util.o
 		LIB_OBJS += $(OUTPUT)ui/tui/setup.o
@@ -890,6 +891,9 @@ $(OUTPUT)ui/browsers/hists.o: ui/browsers/hists.c $(OUTPUT)PERF-CFLAGS
 $(OUTPUT)ui/browsers/map.o: ui/browsers/map.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $<
 
+$(OUTPUT)ui/browsers/scripts.o: ui/browsers/scripts.c $(OUTPUT)PERF-CFLAGS
+	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $<
+
 $(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
 
tools/perf/ui/browsers/scripts.c new file +182 -0

182 lines not on this page · raw message

tools/perf/util/hist.h +7 -0
index 2e650ff..418a040 100644
@@ -136,6 +136,12 @@ static inline int hist_entry__tui_annotate(struct hist_entry *self __used,
 {
 	return 0;
 }
+
+static inline int script_browse(const char *script_opt)
+{
+	return 0;
+}
+
 #define K_LEFT -1
 #define K_RIGHT -2
 #else
@@ -146,6 +152,7 @@ int hist_entry__tui_annotate(struct hist_entry *he, int evidx,
 int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help,
 				  void(*timer)(void *arg), void *arg,
 				  int refresh);
+int script_browse(const char *script_opt);
 #endif
 
 #ifdef NO_GTK2_SUPPORT
Signature · 1 line
1.7.1
author
#10 lore raw

PATCH v2 6/7 perf ui/browser: Integrate script browser into annotation browser

In reply to Feng Tang

Integrate the script browser into annotation, users can press function key 'r' to list all perf scripts and select one of them to run that script, the output will be shown in a separate browser.

---
 tools/perf/ui/browsers/annotate.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
tools/perf/ui/browsers/annotate.c +6 -0
index 67a2703..13ac54c 100644
@@ -675,8 +675,14 @@ static int annotate_browser__run(struct annotate_browser *browser, int evidx,
 		"o             Toggle disassembler output/simplified view\n"
 		"s             Toggle source code view\n"
 		"/             Search string\n"
+		"r             Run available scripts\n"
 		"?             Search previous string\n");
 			continue;
+		case 'r':
+			{
+				script_browse(NULL);
+				continue;
+			}
 		case 'H':
 			nd = browser->curr_hot;
 			break;
Signature · 1 line
1.7.1
#11 lore raw

Re: [PATCH v2 6/7] perf ui/browser: Integrate script browser into annotation browser

Em Fri, Sep 07, 2012 at 04:42:28PM +0800, Feng Tang escreveu:

Quoted 3 lines

Integrate the script browser into annotation, users can press function key 'r' to list all perf scripts and select one of them to run that script, the output will be shown in a separate browser.

I think this needs a bit more work... i.e. I tried it with your script, event_analyzing_sample and I kinda get meaningful output when pressing 'r' + that script from the top and hists browser.

But with other scripts, and you filtered the -top suffixed ones, that require special handling, I get things like "Press Control+C to get a summary", and when I press that, the browser exits, going back to annotate or report/top browser.

I.e. this only works if we are processing a perf.data file made specially for that specific script, right? I.e. the record phase is not integrated at all, just running specific scripts in specific perf.data files.

How to allow the user to chose appropriate scripts to run each perf.data file is an aspect of usability that is missing...

Can you ellaborate on the assumptions you made while working on this, do they match what I described above as how to use this scripts browser?

So I merged part of this patchset, but will wait till more discussion happens on the browsing part,

Thanks,

- Arnaldo

Quoted 26 lines
---
 tools/perf/ui/browsers/annotate.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
tools/perf/ui/browsers/annotate.c +6 -0
index 67a2703..13ac54c 100644
@@ -675,8 +675,14 @@ static int annotate_browser__run(struct annotate_browser *browser, int evidx,
 		"o             Toggle disassembler output/simplified view\n"
 		"s             Toggle source code view\n"
 		"/             Search string\n"
+		"r             Run available scripts\n"
 		"?             Search previous string\n");
 			continue;
+		case 'r':
+			{
+				script_browse(NULL);
+				continue;
+			}
 		case 'H':
 			nd = browser->curr_hot;
 			break;
Signature · 1 line
1.7.1
author
#12 lore raw

Re: [PATCH v2 6/7] perf ui/browser: Integrate script browser into annotation browser

Hi Arnaldo,

Thanks for the reviews!

Quoted 8 lines · On Mon, 17 Sep 2012 12:23:01 -0300 Arnaldo Carvalho de Melo <[email protected]>…

Em Fri, Sep 07, 2012 at 04:42:28PM +0800, Feng Tang escreveu:

Quoted 3 lines

Integrate the script browser into annotation, users can press function key 'r' to list all perf scripts and select one of them to run that script, the output will be shown in a separate browser.

I think this needs a bit more work... i.e. I tried it with your script, event_analyzing_sample and I kinda get meaningful output when pressing 'r' + that script from the top and hists browser.

I would answer you question about "elllaborate on the assumptions" first here, that the main purpose of this script browser is not to replace the normal "perf script" command, but to:
1. Provide a convenient way for user to directly run scripts while they are browsing through the hists or annotation browser, and provide some option for run script with samples from specific thread or symbol
2. Prepare for some advance feature, like inside the annotation browser, analyze some specific hot line of code with samples containing precise information, like the register values, store/load latency stuff. But I have no idea how to implement it now, I guess after Stefan work out the general perf latency tool, we may be able to revisit it.

And when I started to code, I assumed user will mainly use this feature for running scripts for general samples other than the existing scripts for tracepoints. And yes, some user cases you mentioned are not covered.

Quoted 5 lines

But with other scripts, and you filtered the -top suffixed ones, that require special handling, I get things like "Press Control+C to get a summary", and when I press that, the browser exits, going back to annotate or report/top browser.

That's right, 4 current perf python scripts will print that line in its "trace_begin" function, as some of the scripts may run for quiet some time if the perf.data is huge. And what you see in the script browser is just some static text of the script output.

Quoted 5 lines

I.e. this only works if we are processing a perf.data file made specially for that specific script, right? I.e. the record phase is not integrated at all, just running specific scripts in specific perf.data files.

No, the record phase is not added, it just handle the recorded data. And there is something missed in current implementation, that the script in browser mode is only run for the "perf.data" even if the perf report/annotate is run for data with another name.

Quoted 3 lines

How to allow the user to chose appropriate scripts to run each perf.data file is an aspect of usability that is missing...

Do we need to run script for another perf.data when we run report/annotation for one perf.data? or should we add a option for script browser to make it work in browser mode, this is something Numhyung has mentioned in his review

Thanks,
Feng

Quoted 10 lines

Can you ellaborate on the assumptions you made while working on this, do they match what I described above as how to use this scripts browser?

So I merged part of this patchset, but will wait till more discussion happens on the browsing part,

Thanks,

- Arnaldo

#13 lore raw

Re: [PATCH v2 6/7] perf ui/browser: Integrate script browser into annotation browser

Em Tue, Sep 18, 2012 at 03:40:10PM +0800, Feng Tang escreveu:

Quoted 6 lines
Quoted 5 lines · Arnaldo Carvalho de Melo

Em Fri, Sep 07, 2012 at 04:42:28PM +0800, Feng Tang escreveu:

Quoted 3 lines

Integrate the script browser into annotation, users can press function key 'r' to list all perf scripts and select one of them to run that script, the output will be shown in a separate browser.

Quoted 8 lines
Quoted 3 lines

I think this needs a bit more work... i.e. I tried it with your script, event_analyzing_sample and I kinda get meaningful output when pressing 'r' + that script from the top and hists browser.

I would answer you question about "elllaborate on the assumptions" first here, that the main purpose of this script browser is not to replace the normal "perf script" command, but to:
1. Provide a convenient way for user to directly run scripts while they

I think this is what confused me, you say "directly run scripts", but that only means "directly run the report phase of scripts, not the record phase". Ok, that is clear now.

Quoted 8 lines

are browsing through the hists or annotation browser, and provide some option for run script with samples from specific thread or symbol

2. Prepare for some advance feature, like inside the annotation browser, analyze some specific hot line of code with samples containing precise information, like the register values, store/load latency stuff. But I have no idea how to implement it now, I guess after Stefan work out the general perf latency tool, we may be able to revisit it.

I'm ok with adding infrastructure for later improvements, but I think we should try to do it in a way that doesn't confuses users too much, otherwise they may get annoyed and not try the feature when it becomes useful, worse, tell others that it is cumbersome, don't bother trying it.

So we should try to do it in a way that is useful for the constraints you explained here, more on that later in this message.

Quoted 3 lines

And when I started to code, I assumed user will mainly use this feature for running scripts for general samples other than the existing scripts for tracepoints. And yes, some user cases you mentioned are not covered.

Ok, so we need to filter out some more, like you did for the top script.

Quoted 9 lines
Quoted 4 lines

But with other scripts, and you filtered the -top suffixed ones, that require special handling, I get things like "Press Control+C to get a summary", and when I press that, the browser exits, going back to annotate or report/top browser.

That's right, 4 current perf python scripts will print that line in its "trace_begin" function, as some of the scripts may run for quiet some time if the perf.data is huge. And what you see in the script browser is just some static text of the script output.

Ok, so one thing I think we can do is to look at the record script:

[acme@sandy linux]$ cat tools/perf/scripts/python/bin/syscall-counts-by-pid-record #!/bin/bash
perf record -e raw_syscalls:sys_enter $@

and also at the perf.data file:

[root@sandy linux]# perf evlist
cycles

See? we can't offer the syscall-counts-by-pid script to analyse this perf.data file, one is made for the raw_syscalls:sys_enter tracepoint while the other has only cpu cycles.

While the script you provided:

[acme@sandy linux]$ cat tools/perf/scripts/python/bin/event_analyzing_sample-record #!/bin/bash

#

# event_analyzing_sample.py can cover all type of perf samples including
# the tracepoints, so no special record requirements, just record what
# you want to analyze.
#
perf record $@
[acme@sandy linux]$ 

-----------------------

You made it general purpose, so yeah, we can offer that script to the user analysing that perf.data file.

So this is one possible way of matching scripts to perf.data files, another would be for us to somehow annotate the scripts, in the first few lines, with markers that would help do this matching, but I'd start with what we have: parse the line that has the 'perf record' command in the tools/perf/scripts/python/bin/*-record file, look at the event it handles and match to what 'perf evlist' reports.

Not necessarily running 'perf evlist', just doing what it does to figure out the needed information.

Quoted 9 lines
Quoted 4 lines

I.e. this only works if we are processing a perf.data file made specially for that specific script, right? I.e. the record phase is not integrated at all, just running specific scripts in specific perf.data files.

No, the record phase is not added, it just handle the recorded data. And there is something missed in current implementation, that the script in browser mode is only run for the "perf.data" even if the perf report/annotate is run for data with another name.

Ok, so that needs to be handled, using the filtering I suggested above.

Quoted 6 lines
Quoted 2 lines

How to allow the user to chose appropriate scripts to run each perf.data file is an aspect of usability that is missing...

Do we need to run script for another perf.data when we run report/annotation for one perf.data? or should we add a option for script browser to make it work in browser mode, this is something Numhyung has mentioned in his review

Well, it would be great to be able to press some key in the main hists browser and then switch to a different perf.data file, the tool could just look at the current directory, looking at the magic number in the first few bytes of all files, looking for perf.data files to offer.

That, done in the 'top' tool would make it stop doing continuous profiling, stopping the thread it uses to read the counters and instead switch to static profiling, i.e. just reading a perf.data file.

This is something that is a nice new feature and one that would pave the way for a better top/report/script/annotate integration.

- Arnaldo

Quoted 9 lines
Quoted 9 lines

Can you ellaborate on the assumptions you made while working on this, do they match what I described above as how to use this scripts browser?

So I merged part of this patchset, but will wait till more discussion happens on the browsing part,

Thanks,

- Arnaldo

author
#14 lore raw

Re: [PATCH v2 6/7] perf ui/browser: Integrate script browser into annotation browser

Hi Arnaldo,

Quoted 29 lines · On Tue, 18 Sep 2012 08:30:28 -0300 Arnaldo Carvalho de Melo <[email protected]>…

Em Tue, Sep 18, 2012 at 03:40:10PM +0800, Feng Tang escreveu:

Quoted 6 lines
Quoted 5 lines · Arnaldo Carvalho de Melo

Em Fri, Sep 07, 2012 at 04:42:28PM +0800, Feng Tang escreveu:

Quoted 3 lines

Integrate the script browser into annotation, users can press function key 'r' to list all perf scripts and select one of them to run that script, the output will be shown in a separate browser.

Quoted 8 lines
Quoted 3 lines

I think this needs a bit more work... i.e. I tried it with your script, event_analyzing_sample and I kinda get meaningful output when pressing 'r' + that script from the top and hists browser.

I would answer you question about "elllaborate on the assumptions" first here, that the main purpose of this script browser is not to replace the normal "perf script" command, but to:
1. Provide a convenient way for user to directly run scripts while they

I think this is what confused me, you say "directly run scripts", but that only means "directly run the report phase of scripts, not the record phase". Ok, that is clear now.

Quoted 8 lines

are browsing through the hists or annotation browser, and provide some option for run script with samples from specific thread or symbol

2. Prepare for some advance feature, like inside the annotation browser, analyze some specific hot line of code with samples containing precise information, like the register values, store/load latency stuff. But I have no idea how to implement it now, I guess after Stefan work out the general perf latency tool, we may be able to revisit it.

Quoted 5 lines

I'm ok with adding infrastructure for later improvements, but I think we should try to do it in a way that doesn't confuses users too much, otherwise they may get annoyed and not try the feature when it becomes useful, worse, tell others that it is cumbersome, don't bother trying it.

OK, will try to make it clear in the commit log and comments inside the code.

Quoted 27 lines

So we should try to do it in a way that is useful for the constraints you explained here, more on that later in this message.

Quoted 3 lines

And when I started to code, I assumed user will mainly use this feature for running scripts for general samples other than the existing scripts for tracepoints. And yes, some user cases you mentioned are not covered.

Ok, so we need to filter out some more, like you did for the top script.

Quoted 9 lines
Quoted 4 lines

But with other scripts, and you filtered the -top suffixed ones, that require special handling, I get things like "Press Control+C to get a summary", and when I press that, the browser exits, going back to annotate or report/top browser.

That's right, 4 current perf python scripts will print that line in its "trace_begin" function, as some of the scripts may run for quiet some time if the perf.data is huge. And what you see in the script browser is just some static text of the script output.

Ok, so one thing I think we can do is to look at the record script:

[acme@sandy linux]$ cat tools/perf/scripts/python/bin/syscall-counts-by-pid-record #!/bin/bash
perf record -e raw_syscalls:sys_enter $@

Quoted 8 lines

and also at the perf.data file:

[root@sandy linux]# perf evlist
cycles

See? we can't offer the syscall-counts-by-pid script to analyse this perf.data file, one is made for the raw_syscalls:sys_enter tracepoint while the other has only cpu cycles.

Yeah, good idea.

Quoted 27 lines

While the script you provided:

[acme@sandy linux]$ cat tools/perf/scripts/python/bin/event_analyzing_sample-record #!/bin/bash

#

# event_analyzing_sample.py can cover all type of perf samples including
# the tracepoints, so no special record requirements, just record what
# you want to analyze.
#
perf record $@
[acme@sandy linux]$ 

-----------------------

You made it general purpose, so yeah, we can offer that script to the user analysing that perf.data file.

So this is one possible way of matching scripts to perf.data files, another would be for us to somehow annotate the scripts, in the first few lines, with markers that would help do this matching, but I'd start with what we have: parse the line that has the 'perf record' command in the tools/perf/scripts/python/bin/*-record file, look at the event it handles and match to what 'perf evlist' reports.

Quoted 2 lines

Not necessarily running 'perf evlist', just doing what it does to figure out the needed information.

OK, will try this dynamic way for scripts filtering (comparing to the static way of filtering xxxtop scripts)

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

I.e. this only works if we are processing a perf.data file made specially for that specific script, right? I.e. the record phase is not integrated at all, just running specific scripts in specific perf.data files.

Quoted 6 lines
Quoted 4 lines

No, the record phase is not added, it just handle the recorded data. And there is something missed in current implementation, that the script in browser mode is only run for the "perf.data" even if the perf report/annotate is run for data with another name.

Ok, so that needs to be handled, using the filtering I suggested above.

And I need to pass the filename of the perf.data to the script browser in case the perf report/annotate use the "-i" option.

Quoted 13 lines
Quoted 7 lines
Quoted 3 lines

How to allow the user to chose appropriate scripts to run each perf.data file is an aspect of usability that is missing...

Do we need to run script for another perf.data when we run report/annotation for one perf.data? or should we add a option for script browser to make it work in browser mode, this is something Numhyung has mentioned in his review

Well, it would be great to be able to press some key in the main hists browser and then switch to a different perf.data file, the tool could just look at the current directory, looking at the magic number in the first few bytes of all files, looking for perf.data files to offer.

Quoted 6 lines

That, done in the 'top' tool would make it stop doing continuous profiling, stopping the thread it uses to read the counters and instead switch to static profiling, i.e. just reading a perf.data file.

This is something that is a nice new feature and one that would pave the way for a better top/report/script/annotate integration.

I will try to see what I can do with this.

One thing I need confirm is, the filtering method you mentioned above is only against the perf.data that is currently processed by the report/annotate browser, and not related with the perf.data switching?

Thanks,
Feng

author
#15 lore raw

PATCH v2 7/7 perf ui/browser: Integrate script browser into main hists browser

In reply to Feng Tang

Integrate the script browser into "perf report" framework, users can use function key 'r' or the drop down menu to list all perf scripts and select one of them, just like they did for the annotation.

---
 tools/perf/ui/browsers/hists.c |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
tools/perf/ui/browsers/hists.c +37 -0
index 81bd8c2..73cff34 100644
@@ -1089,6 +1089,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
 	int nr_options = 0;
 	int key = -1;
 	char buf[64];
+	char script_opt[64];
 
 	if (browser == NULL)
 		return -1;
@@ -1099,6 +1100,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
 
 	ui_helpline__push(helpline);
 
+	memset(script_opt, 0, 64);
 	memset(options, 0, sizeof(options));
 
 	while (1) {
@@ -1107,6 +1109,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
 		int choice = 0,
 		    annotate = -2, zoom_dso = -2, zoom_thread = -2,
 		    annotate_f = -2, annotate_t = -2, browse_map = -2;
+		int scripts_comm = -2, scripts_symbol = -2, scripts_all = -2;
 
 		nr_options = 0;
 
@@ -1159,6 +1162,8 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
 				hist_browser__reset(browser);
 			}
 			continue;
+		case 'r':
+			goto do_scripts;
 		case K_F1:
 		case 'h':
 		case '?':
@@ -1177,6 +1182,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
 					"E             Expand all callchains\n"
 					"d             Zoom into current DSO\n"
 					"t             Zoom into current Thread\n"
+					"r             Run available scripts\n"
 					"P             Print histograms to perf.hist.N\n"
 					"V             Verbose (DSO names in callchains, etc)\n"
 					"/             Filter symbol by name");
@@ -1265,6 +1271,25 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
 		    browser->selection->map != NULL &&
 		    asprintf(&options[nr_options], "Browse map details") > 0)
 			browse_map = nr_options++;
+
+		/* perf script support */
+		if (browser->he_selection) {
+			struct symbol *sym;
+
+			if (asprintf(&options[nr_options], "Run scripts for samples of thread [%s]",
+				browser->he_selection->thread->comm) > 0)
+				scripts_comm = nr_options++;
+
+			sym = browser->he_selection->ms.sym;
+			if (sym && sym->namelen &&
+				asprintf(&options[nr_options], "Run scripts for samples of symbol [%s]",
+						sym->name) > 0)
+				scripts_symbol = nr_options++;
+		}
+
+		if (asprintf(&options[nr_options], "Run scripts for all samples") > 0)
+			scripts_all = nr_options++;
+
 add_exit_option:
 		options[nr_options++] = (char *)"Exit";
 retry_popup_menu:
@@ -1359,6 +1384,18 @@ zoom_out_thread:
 			hists__filter_by_thread(hists);
 			hist_browser__reset(browser);
 		}
+		/* perf scripts support */
+		else if (choice == scripts_all || choice == scripts_comm ||
+				choice == scripts_symbol) {
+do_scripts:
+			if (choice == scripts_comm)
+				sprintf(script_opt, " -c %s ", browser->he_selection->thread->comm);
+
+			if (choice == scripts_symbol)
+				sprintf(script_opt, " -S %s ", browser->he_selection->ms.sym->name);
+
+			script_browse(script_opt);
+		}
 	}
 out_free_stack:
 	pstack__delete(fstack);
Signature · 1 line
1.7.1
maintainer Reviewed-by on the v2 series
#16 lore raw
In reply to Feng Tang

Hi Feng,

Quoted 19 lines · Feng Tang

Hi Arnaldo and all,

This is a patch set mainly to add a browser for perf script, which will be integrated into the main hists and annotation browser.

Patch 1-4 are some preparation for adding the script
patch 5 introduce the script browser
patch 6-7 integrate the browser to hists browser and annotation browser

The patches are on top of current perf/core branch of your git tree. Please help to review.

Namhyung,

Many thanks for providing many good comments for the v1 patch sets. In this v2, I addressed most of those comments, for the suggestion to use browser for "perf script -l", I'll handle it later, and would post the v2 first for review.

Quoted 4 lines

Changelog:
Since v1:
* Add filter for scripts can't be run in script browser
* Fix some bugs about buffer handling and error check

For whole series,

Thanks for your work!
Namhyung