Skip to contentSkip to conversation

perf trace: Python scripting support

PATCH In review Tom Zanussi 2 participants 38 messages Jan 27, 2010 – Mar 28, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover perf trace: Python scripting support

This patchset adds a Python scripting engine to perf trace. In the process, it also creates a scripting-engines directory under perf/util and moves the existing Perl support there, to avoid cluttering the main perf/util directory with scripting support files.

It also includes some minor bugfixes and adds Documentation for the Python support, which includes a step-by-step example detailing how to write a new trace stream processing script using Python.

Finally, it adds several new scripts, all dealing with aggregation of system call trace data. To make those scripts more user-friendly, it adds a couple patches that export some of the syscall metadata, enough to allow syscall names rather than raw numbers to be printed in the output.

NOTE: in order to run the 'record' side of these scripts, you need to first revert commit f5a2c3dce03621b55f84496f58adc2d1a87ca16f "perf
record: Intercept all events" - recording the syscall events seems to always trigger the infinite loop in there.

Here's the new current listing of available scripts:

# perf trace -l
List of available trace scripts:
  workqueue-stats                      workqueue stats (ins/exe/create/destroy)
  wakeup-latency                       system-wide min/max/avg wakeup latency
  rw-by-file <comm>                    r/w activity for a program, by file
  failed-syscalls [comm]               system-wide failed syscalls
  rw-by-pid                            system-wide r/w activity
  syscall-counts-by-pid [comm]         system-wide syscall counts, by pid
  failed-syscalls-by-pid [comm]        system-wide failed syscalls, by pid
  syscall-counts [comm]                system-wide syscall counts

And some sample output from the four new ones:

The 'syscall-counts' script just gives a high-level overview of all syscalls on the system, listed by syscall:

root@tropicana:~# perf trace record syscall-counts
^C[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 32.165 MB perf.data (~1405309 samples) ]
root@tropicana:~# perf trace report syscall-counts

syscall events:

event count
---------------------------------------- -----------
sys_write 269407

sys_getdents                                    2782
sys_close                                       2004
sys_swapoff                                     1095
sys_read                                         920
sys_sched_setparam                               511
sys_open                                         331
sys_newfstat                                     326
sys_mmap                                         217
sys_munmap                                       216
sys_select                                       173
sys_getgid                                       128
sys_futex                                         89
sys_poll                                          76
174                                               64
sys_setuid                                        64
sys_setitimer                                     50
15                                                25
sys_rt_sigprocmask                                24
sys_lseek                                          7
sys_inotify_add_watch                              6
sys_writev                                         5
sys_ioctl                                          5
sys_wait4                                          2
sys_perf_event_open                                1
sys_fcntl                                          1

The 'syscall-counts-by-pid' script dives down into more detail, listing the system calls by comm/pid:

root@tropicana:~# perf trace report syscall-counts

syscall events by comm/pid:

comm [pid]/syscalls count
---------------------------------------- ----------

gnome-screensav [6351]
sys_read 8
sys_poll 2

firefox [6505]
sys_futex 72
sys_write 19

firefox [6502]

  sys_read                                        61
  sys_select                                      41
  sys_poll                                        41
  sys_futex                                       17

sys_inotify_add_watch 2
sys_write 1

perf [13629]
sys_write 269386

  sys_read                                       790
  sys_newfstat                                   326
  sys_open                                       326
  sys_close                                      324
  sys_getdents                                   222
  sys_mmap                                       217
  sys_munmap                                     216
  sys_lseek                                        7
  sys_ioctl                                        4
  sys_perf_event_open                              1
  sys_fcntl                                        1
  15                                               1
  sys_poll                                         1

pulseaudio [6275]
sys_poll 1

gnome-panel [6329]

  sys_inotify_add_watch                            4
  sys_poll                                         1
  sys_read                                         1

apache2 [6004]
sys_wait4 2
sys_select 2

wterm [6659]

  sys_read                                         7
  sys_select                                       3
  sys_write                                        1

mysqld [5120]
sys_select 2

mysqld [5119]
sys_select 2

npviewer.bin [13313]

  sys_getdents                                  2560
  sys_close                                     1679
  sys_swapoff                                   1095

sys_sched_setparam 511
sys_getgid 128
174 64
sys_setuid 64

Xorg [5853]
sys_select 123

  sys_setitimer                                   50
  sys_read                                        50
  15                                              24
  sys_rt_sigprocmask                              24
  sys_poll                                        24

sys_writev 5

The 'failed-syscalls' script likewise gives a high-level overview of all failed syscalls on the system, listed both by comm and by syscall:

root@tropicana:~# perf trace record failed-syscalls
^C[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 32.653 MB perf.data (~1426644 samples) ]
root@tropicana:~# perf trace report failed-syscalls

failed syscalls, by comm:

comm # errors
-------------------- ----------
npviewer.bin 2468
firefox 91
Xorg 31

gnome-screensav                6
wterm                          5
gnome-panel                    5
trashapplet                    4
hald-addon-stor                4
gvfsd-trash                    2
gnome-settings-                2
sh                             1
update-notifier                1

failed syscalls, by syscall:

syscall # errors
------------------------------ ----------
sys_close 2468

sys_read                                81
sys_futex                               29
sys_select                              15
undefined                               15
sys_inotify_add_watch                    6
sys_open                                 4
sys_access                               1
sys_wait4                                1

And again, diving into more detail, the 'failed-syscalls-by-pid' script lists the failed system calls by comm/pid and error:

root@tropicana:~# perf trace report failed-syscalls-by-pid
perf trace started with Python script /root/libexec/perf-core/scripts/python/failed-syscalls-by-pid.py

syscall errors:

comm [pid] count
------------------------------ ----------

gnome-screensav [6351]
syscall: sys_read
err = -11 6

firefox [6505]
syscall: sys_futex
err = -110 28

firefox [6502]
syscall: sys_read
err = -11 60
syscall: sys_access
err = -2 1
syscall: sys_inotify_add_watch
err = -2 2

gnome-panel [6329]
syscall: sys_read
err = -11 1
syscall: sys_inotify_add_watch
err = -2 4

wterm [6659]
syscall: sys_read
err = -11 5

trashapplet [6364]
syscall: sys_read
err = -11 4

sh [13717]
syscall: sys_wait4
err = -512 1

npviewer.bin [13313]
syscall: sys_close
err = -11 2468

Xorg [5853]
syscall: sys_read
err = -11 1
syscall: undefined
err = -4 15
syscall: sys_select
err = -514 15

gnome-settings- [6297]
syscall: sys_read
err = -11 2

hald-addon-stor [5721]
syscall: sys_open
err = -123 1

hald-addon-stor [5715]
syscall: sys_open
err = -123 1

hald-addon-stor [5724]
syscall: sys_open
err = -123 1

hald-addon-stor [5718]
syscall: sys_open
err = -123 1

gvfsd-trash [6370]
syscall: sys_read
err = -11 1

gvfsd-trash [13719]
syscall: sys_futex
err = -110 1

update-notifier [6395]
syscall: sys_read
err = -11 1

These scripts can be used to get a general idea of syscall activity on the system, which can be used to direct further investigation in the form of either more refined scripts and/or looking at the source of apps that seem to be acting strangely.

For instance, the output of failed-syscalls-by-pid shows npviewer.bin, a flash plugin wrapper, seems to be making a lot of failed close system calls, while the output of syscalls-by-pid doesn't show a lot of open calls. So it's apparently wasting a lot of time closing nonexistent files (this script was run for only a very short time). It might be useful at this point to record syscalls::sys_enter/exit_close syscalls and write a script that would hash the fds by error code to find out which files it's trying unsuccessfully to close. That might be enough information to go examine and fix the offending code in the wrapper, or put the blame on the wrappee if that's where the problem is...

Tom Zanussi (12): perf trace/scripting: Fix supported language listing
option perf trace/scripting: fix bug in Util.pm perf trace/scripting: move common code out of Perl-specific files perf trace/scripting: move Perl scripting files to scripting-engines dir perf trace/scripting: remove check-perf-trace from listed scripts perf trace/scripting: add Python scripting engine perf trace/scripting: add syscall tracing scripts perf: export some syscall metadata perf tools: save syscall map perf trace/scripting:
make the syscall map available as a Python dict perf trace/scripting: make the syscall map available as a Perl hash perf trace/scripting: add perf-trace-python Documentation

 kernel/trace/trace_syscalls.c                      |   87 +++
 tools/perf/Documentation/perf-trace-perl.txt       |    3 +-
 tools/perf/Documentation/perf-trace-python.txt     |  624 ++++++++++++++++++
 tools/perf/Documentation/perf-trace.txt            |   15 +-
 tools/perf/Makefile                                |   33 +-
 tools/perf/builtin-trace.c                         |    5 +-
 tools/perf/scripts/perl/Perf-Trace-Util/Context.c  |   49 ++-
 tools/perf/scripts/perl/Perf-Trace-Util/Context.xs |   27 +-
 .../perl/Perf-Trace-Util/lib/Perf/Trace/Context.pm |    2 +-
 .../perl/Perf-Trace-Util/lib/Perf/Trace/Util.pm    |   24 +-
 .../perf/scripts/perl/bin/check-perf-trace-record  |    7 +-
 .../perf/scripts/perl/bin/check-perf-trace-report  |    6 -
 tools/perf/scripts/perl/bin/failed-syscalls-record |    2 +
 tools/perf/scripts/perl/bin/failed-syscalls-report |    4 +
 tools/perf/scripts/perl/failed-syscalls.pl         |   51 ++
 .../perf/scripts/python/Perf-Trace-Util/Context.c  |  110 ++++
 .../python/Perf-Trace-Util/lib/Perf/Trace/Core.py  |   91 +++
 .../python/Perf-Trace-Util/lib/Perf/Trace/Util.py  |   37 ++
 .../python/bin/failed-syscalls-by-pid-record       |    2 +
 .../python/bin/failed-syscalls-by-pid-report       |    4 +
 .../python/bin/syscall-counts-by-pid-record        |    2 +
 .../python/bin/syscall-counts-by-pid-report        |    4 +
 .../perf/scripts/python/bin/syscall-counts-record  |    2 +
 .../perf/scripts/python/bin/syscall-counts-report  |    4 +
 tools/perf/scripts/python/check-perf-trace.py      |   83 +++
 .../perf/scripts/python/failed-syscalls-by-pid.py  |   69 ++
 tools/perf/scripts/python/syscall-counts-by-pid.py |   65 ++
 tools/perf/scripts/python/syscall-counts.py        |   59 ++
 .../perf/util/scripting-engines/trace-event-perl.c |  568 +++++++++++++++++
 .../util/scripting-engines/trace-event-python.c    |  576 +++++++++++++++++
 tools/perf/util/trace-event-info.c                 |   25 +
 tools/perf/util/trace-event-parse.c                |   78 +++
 tools/perf/util/trace-event-perl.c                 |  661 --------------------
 tools/perf/util/trace-event-perl.h                 |   55 --
 tools/perf/util/trace-event-read.c                 |   18 +
 tools/perf/util/trace-event-scripting.c            |  167 +++++
 tools/perf/util/trace-event.h                      |   20 +-
 37 files changed, 2895 insertions(+), 744 deletions(-)
 create mode 100644 tools/perf/Documentation/perf-trace-python.txt
 delete mode 100644 tools/perf/scripts/perl/bin/check-perf-trace-report
 create mode 100644 tools/perf/scripts/perl/bin/failed-syscalls-record
 create mode 100644 tools/perf/scripts/perl/bin/failed-syscalls-report
 create mode 100644 tools/perf/scripts/perl/failed-syscalls.pl
 create mode 100644 tools/perf/scripts/python/Perf-Trace-Util/Context.c
 create mode 100644 tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Core.py
 create mode 100644 tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py
 create mode 100644 tools/perf/scripts/python/bin/failed-syscalls-by-pid-record
 create mode 100644 tools/perf/scripts/python/bin/failed-syscalls-by-pid-report
 create mode 100644 tools/perf/scripts/python/bin/syscall-counts-by-pid-record
 create mode 100644 tools/perf/scripts/python/bin/syscall-counts-by-pid-report
 create mode 100644 tools/perf/scripts/python/bin/syscall-counts-record
 create mode 100644 tools/perf/scripts/python/bin/syscall-counts-report
 create mode 100644 tools/perf/scripts/python/check-perf-trace.py
 create mode 100644 tools/perf/scripts/python/failed-syscalls-by-pid.py
 create mode 100644 tools/perf/scripts/python/syscall-counts-by-pid.py
 create mode 100644 tools/perf/scripts/python/syscall-counts.py
 create mode 100644 tools/perf/util/scripting-engines/trace-event-perl.c
 create mode 100644 tools/perf/util/scripting-engines/trace-event-python.c
 delete mode 100644 tools/perf/util/trace-event-perl.c
 delete mode 100644 tools/perf/util/trace-event-perl.h
 create mode 100644 tools/perf/util/trace-event-scripting.c
#1 lore raw

PATCH 1/12 perf trace/scripting: Fix supported language listing option

'perf trace -s list' prints a list of the supported scripting languages. One problem with it is that it falls through and prints the trace as well. The use of 'list' for this also makes it easy to confuse with 'perf trace -l', used for listing available scripts. So change 'perf trace -s list' to 'perf trace -s lang' and fixes the fall-through problem.

---
 tools/perf/Documentation/perf-trace.txt |    4 +++-
 tools/perf/builtin-trace.c              |    4 ++--
 2 files changed, 5 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-trace.txt +3 -1
index 60e5900..c00a76f 100644
@@ -45,9 +45,11 @@ OPTIONS
 --list=::
         Display a list of available trace scripts.
 
--s::
+-s ['lang']::
 --script=::
         Process trace data with the given script ([lang]:script[.ext]).
+	If the string 'lang' is specified in place of a script name, a
+        list of supported languages will be displayed instead.
 
 -g::
 --gen-script=::
tools/perf/builtin-trace.c +2 -2
index 8e9cbfe..850d0aa 100644
@@ -219,9 +219,9 @@ static int parse_scriptname(const struct option *opt __used,
 	const char *script, *ext;
 	int len;
 
-	if (strcmp(str, "list") == 0) {
+	if (strcmp(str, "lang") == 0) {
 		list_available_languages();
-		return 0;
+		exit(0);
 	}
 
 	script = strchr(str, ':');
Signature · 1 line
1.6.4.GIT
#2 lore raw

[tip:perf/core] perf/scripts: Fix supported language listing option

Commit-ID:  f526d68b6ce9ba7a2bd94e663e240a022524c58a
Gitweb:     http://git.kernel.org/tip/f526d68b6ce9ba7a2bd94e663e240a022524c58a
Author:     Tom Zanussi <[email protected]>
AuthorDate: Wed, 27 Jan 2010 02:27:52 -0600
Committer:  Frederic Weisbecker <[email protected]>
CommitDate: Tue, 23 Feb 2010 20:34:42 +0100

perf/scripts: Fix supported language listing option

'perf trace -s list' prints a list of the supported scripting languages. One problem with it is that it falls through and prints the trace as well. The use of 'list' for this also makes it easy to confuse with 'perf trace -l', used for listing available scripts. So change 'perf trace -s list' to 'perf trace -s lang' and fixes the fall-through problem.

Cc Ingo Molnar <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Keiichi KII <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>

LKML-Reference: <[email protected]>

---
 tools/perf/Documentation/perf-trace.txt |    4 +++-
 tools/perf/builtin-trace.c              |    4 ++--
 2 files changed, 5 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-trace.txt +3 -1
index 60e5900..c00a76f 100644
@@ -45,9 +45,11 @@ OPTIONS
 --list=::
         Display a list of available trace scripts.
 
--s::
+-s ['lang']::
 --script=::
         Process trace data with the given script ([lang]:script[.ext]).
+	If the string 'lang' is specified in place of a script name, a
+        list of supported languages will be displayed instead.
 
 -g::
 --gen-script=::
tools/perf/builtin-trace.c +2 -2
index 0b65779..d5d20c3 100644
@@ -219,9 +219,9 @@ static int parse_scriptname(const struct option *opt __used,
 	const char *script, *ext;
 	int len;
 
-	if (strcmp(str, "list") == 0) {
+	if (strcmp(str, "lang") == 0) {
 		list_available_languages();
-		return 0;
+		exit(0);
 	}
 
 	script = strchr(str, ':');
#3 lore raw

PATCH 2/12 perf trace/scripting: fix bug in Util.pm

In reply to Tom Zanussi

Fix bogus calculation.

---
 .../perl/Perf-Trace-Util/lib/Perf/Trace/Util.pm    |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Util.pm +1 -1
index 052f132..f869c48 100644
@@ -44,7 +44,7 @@ sub nsecs_secs {
 sub nsecs_nsecs {
     my ($nsecs) = @_;
 
-    return $nsecs - nsecs_secs($nsecs);
+    return $nsecs % $NSECS_PER_SEC;
 }
 
 sub nsecs_str {
Signature · 1 line
1.6.4.GIT
#4 lore raw

[tip:perf/core] perf/scripts: Fix bug in Util.pm

Commit-ID:  e26207a3819684e9b4450a2d30bdd065fa92d9c7
Gitweb:     http://git.kernel.org/tip/e26207a3819684e9b4450a2d30bdd065fa92d9c7
Author:     Tom Zanussi <[email protected]>
AuthorDate: Wed, 27 Jan 2010 02:27:53 -0600
Committer:  Frederic Weisbecker <[email protected]>
CommitDate: Tue, 23 Feb 2010 20:34:45 +0100

perf/scripts: Fix bug in Util.pm

Fix bogus calculation.

Cc Ingo Molnar <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Keiichi KII <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>

LKML-Reference: <[email protected]>

---
 .../perl/Perf-Trace-Util/lib/Perf/Trace/Util.pm    |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Util.pm +1 -1
index 052f132..f869c48 100644
@@ -44,7 +44,7 @@ sub nsecs_secs {
 sub nsecs_nsecs {
     my ($nsecs) = @_;
 
-    return $nsecs - nsecs_secs($nsecs);
+    return $nsecs % $NSECS_PER_SEC;
 }
 
 sub nsecs_str {
#5 lore raw

PATCH 3/12 perf trace/scripting: move common code out of Perl-specific files

In reply to Tom Zanussi

This stuff is needed by all scripting engines; move it from the Perl engine source to a more common place.

---
 tools/perf/scripts/perl/Perf-Trace-Util/Context.c  |    5 ++-
 tools/perf/scripts/perl/Perf-Trace-Util/Context.xs |    3 +-
 tools/perf/util/trace-event-parse.c                |   15 +++++++++++
 tools/perf/util/trace-event-perl.c                 |   27 --------------------
 tools/perf/util/trace-event-perl.h                 |    8 ------
 tools/perf/util/trace-event.h                      |    9 ++++++-
 6 files changed, 28 insertions(+), 39 deletions(-)
tools/perf/scripts/perl/Perf-Trace-Util/Context.c +3 -2
index af78d9a..01a64ad 100644
@@ -31,13 +31,14 @@
 #include "EXTERN.h"
 #include "perl.h"
 #include "XSUB.h"
-#include "../../../util/trace-event-perl.h"
+#include "../../../perf.h"
+#include "../../../util/trace-event.h"
 
 #ifndef PERL_UNUSED_VAR
 #  define PERL_UNUSED_VAR(var) if (0) var = var
 #endif
 
-#line 41 "Context.c"
+#line 42 "Context.c"
 
 XS(XS_Perf__Trace__Context_common_pc); /* prototype to pass -Wmissing-prototypes */
 XS(XS_Perf__Trace__Context_common_pc)
tools/perf/scripts/perl/Perf-Trace-Util/Context.xs +2 -1
index fb78006..549cf04 100644
@@ -22,7 +22,8 @@
 #include "EXTERN.h"
 #include "perl.h"
 #include "XSUB.h"
-#include "../../../util/trace-event-perl.h"
+#include "../../../perf.h"
+#include "../../../util/trace-event.h"
 
 MODULE = Perf::Trace::Context		PACKAGE = Perf::Trace::Context
 PROTOTYPES: ENABLE
tools/perf/util/trace-event-parse.c +15 -0
index c5c32be..c1299ff 100644
@@ -3277,3 +3277,18 @@ void parse_set_info(int nr_cpus, int long_sz)
 	cpus = nr_cpus;
 	long_size = long_sz;
 }
+
+int common_pc(struct scripting_context *context)
+{
+	return parse_common_pc(context->event_data);
+}
+
+int common_flags(struct scripting_context *context)
+{
+	return parse_common_flags(context->event_data);
+}
+
+int common_lock_depth(struct scripting_context *context)
+{
+	return parse_common_lock_depth(context->event_data);
+}
tools/perf/util/trace-event-perl.c +0 -27
index 6d6d76b..5b49df0 100644
@@ -239,33 +239,6 @@ static inline struct event *find_cache_event(int type)
 	return event;
 }
 
-int common_pc(struct scripting_context *context)
-{
-	int pc;
-
-	pc = parse_common_pc(context->event_data);
-
-	return pc;
-}
-
-int common_flags(struct scripting_context *context)
-{
-	int flags;
-
-	flags = parse_common_flags(context->event_data);
-
-	return flags;
-}
-
-int common_lock_depth(struct scripting_context *context)
-{
-	int lock_depth;
-
-	lock_depth = parse_common_lock_depth(context->event_data);
-
-	return lock_depth;
-}
-
 static void perl_process_event(int cpu, void *data,
 			       int size __unused,
 			       unsigned long long nsecs, char *comm)
tools/perf/util/trace-event-perl.h +0 -8
index e88fb26..01efcc9 100644
@@ -44,12 +44,4 @@ void boot_DynaLoader(pTHX_ CV *cv);
 typedef PerlInterpreter * INTERP;
 #endif
 
-struct scripting_context {
-	void *event_data;
-};
-
-int common_pc(struct scripting_context *context);
-int common_flags(struct scripting_context *context);
-int common_lock_depth(struct scripting_context *context);
-
 #endif /* __PERF_TRACE_EVENT_PERL_H */
tools/perf/util/trace-event.h +8 -1
index 6ad4056..aaf2da2 100644
@@ -279,7 +279,14 @@ struct scripting_ops {
 
 int script_spec_register(const char *spec, struct scripting_ops *ops);
 
-extern struct scripting_ops perl_scripting_ops;
 void setup_perl_scripting(void);
 
+struct scripting_context {
+	void *event_data;
+};
+
+int common_pc(struct scripting_context *context);
+int common_flags(struct scripting_context *context);
+int common_lock_depth(struct scripting_context *context);
+
 #endif /* __PERF_TRACE_EVENTS_H */
Signature · 1 line
1.6.4.GIT
#6 lore raw

[tip:perf/core] perf/scripts: Move common code out of Perl-specific files

Commit-ID:  7397d80ddde8eef3b1dce6c29e0c53bd322ef824
Gitweb:     http://git.kernel.org/tip/7397d80ddde8eef3b1dce6c29e0c53bd322ef824
Author:     Tom Zanussi <[email protected]>
AuthorDate: Wed, 27 Jan 2010 02:27:54 -0600
Committer:  Frederic Weisbecker <[email protected]>
CommitDate: Tue, 23 Feb 2010 20:37:29 +0100

perf/scripts: Move common code out of Perl-specific files

This stuff is needed by all scripting engines; move it from the Perl engine source to a more common place.

Cc Ingo Molnar <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Keiichi KII <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>

LKML-Reference: <[email protected]>

---
 tools/perf/scripts/perl/Perf-Trace-Util/Context.c  |    5 ++-
 tools/perf/scripts/perl/Perf-Trace-Util/Context.xs |    3 +-
 tools/perf/util/trace-event-parse.c                |   15 +++++++++++
 tools/perf/util/trace-event-perl.c                 |   27 --------------------
 tools/perf/util/trace-event-perl.h                 |    8 ------
 tools/perf/util/trace-event.h                      |    9 ++++++-
 6 files changed, 28 insertions(+), 39 deletions(-)
tools/perf/scripts/perl/Perf-Trace-Util/Context.c +3 -2
index af78d9a..01a64ad 100644
@@ -31,13 +31,14 @@
 #include "EXTERN.h"
 #include "perl.h"
 #include "XSUB.h"
-#include "../../../util/trace-event-perl.h"
+#include "../../../perf.h"
+#include "../../../util/trace-event.h"
 
 #ifndef PERL_UNUSED_VAR
 #  define PERL_UNUSED_VAR(var) if (0) var = var
 #endif
 
-#line 41 "Context.c"
+#line 42 "Context.c"
 
 XS(XS_Perf__Trace__Context_common_pc); /* prototype to pass -Wmissing-prototypes */
 XS(XS_Perf__Trace__Context_common_pc)
tools/perf/scripts/perl/Perf-Trace-Util/Context.xs +2 -1
index fb78006..549cf04 100644
@@ -22,7 +22,8 @@
 #include "EXTERN.h"
 #include "perl.h"
 #include "XSUB.h"
-#include "../../../util/trace-event-perl.h"
+#include "../../../perf.h"
+#include "../../../util/trace-event.h"
 
 MODULE = Perf::Trace::Context		PACKAGE = Perf::Trace::Context
 PROTOTYPES: ENABLE
tools/perf/util/trace-event-parse.c +15 -0
index c4b3cb8..9b3c20f 100644
@@ -3286,3 +3286,18 @@ void parse_set_info(int nr_cpus, int long_sz)
 	cpus = nr_cpus;
 	long_size = long_sz;
 }
+
+int common_pc(struct scripting_context *context)
+{
+	return parse_common_pc(context->event_data);
+}
+
+int common_flags(struct scripting_context *context)
+{
+	return parse_common_flags(context->event_data);
+}
+
+int common_lock_depth(struct scripting_context *context)
+{
+	return parse_common_lock_depth(context->event_data);
+}
tools/perf/util/trace-event-perl.c +0 -27
index 6d6d76b..5b49df0 100644
@@ -239,33 +239,6 @@ static inline struct event *find_cache_event(int type)
 	return event;
 }
 
-int common_pc(struct scripting_context *context)
-{
-	int pc;
-
-	pc = parse_common_pc(context->event_data);
-
-	return pc;
-}
-
-int common_flags(struct scripting_context *context)
-{
-	int flags;
-
-	flags = parse_common_flags(context->event_data);
-
-	return flags;
-}
-
-int common_lock_depth(struct scripting_context *context)
-{
-	int lock_depth;
-
-	lock_depth = parse_common_lock_depth(context->event_data);
-
-	return lock_depth;
-}
-
 static void perl_process_event(int cpu, void *data,
 			       int size __unused,
 			       unsigned long long nsecs, char *comm)
tools/perf/util/trace-event-perl.h +0 -8
index e88fb26..01efcc9 100644
@@ -44,12 +44,4 @@ void boot_DynaLoader(pTHX_ CV *cv);
 typedef PerlInterpreter * INTERP;
 #endif
 
-struct scripting_context {
-	void *event_data;
-};
-
-int common_pc(struct scripting_context *context);
-int common_flags(struct scripting_context *context);
-int common_lock_depth(struct scripting_context *context);
-
 #endif /* __PERF_TRACE_EVENT_PERL_H */
tools/perf/util/trace-event.h +8 -1
index 6ad4056..aaf2da2 100644
@@ -279,7 +279,14 @@ struct scripting_ops {
 
 int script_spec_register(const char *spec, struct scripting_ops *ops);
 
-extern struct scripting_ops perl_scripting_ops;
 void setup_perl_scripting(void);
 
+struct scripting_context {
+	void *event_data;
+};
+
+int common_pc(struct scripting_context *context);
+int common_flags(struct scripting_context *context);
+int common_lock_depth(struct scripting_context *context);
+
 #endif /* __PERF_TRACE_EVENTS_H */
#7 lore raw

PATCH 4/12 perf trace/scripting: move Perl scripting files to scripting-engines dir

In reply to Tom Zanussi

Create a scripting-engines directory to contain scripting engine implementation code, in anticipation of the addition of new scripting support. Also removes trace-event-perl.h.

---
 tools/perf/Makefile                                |    9 +-
 .../perf/util/scripting-engines/trace-event-perl.c |  568 ++++++++++++++++++
 tools/perf/util/trace-event-perl.c                 |  634 --------------------
 tools/perf/util/trace-event-perl.h                 |   47 --
 tools/perf/util/trace-event-scripting.c            |  106 ++++
 5 files changed, 679 insertions(+), 685 deletions(-)
 create mode 100644 tools/perf/util/scripting-engines/trace-event-perl.c
 delete mode 100644 tools/perf/util/trace-event-perl.c
 delete mode 100644 tools/perf/util/trace-event-perl.h
 create mode 100644 tools/perf/util/trace-event-scripting.c
tools/perf/Makefile +5 -4
index 9b173e6..b09588f 100644
@@ -383,7 +383,6 @@ LIB_H += util/sort.h
 LIB_H += util/hist.h
 LIB_H += util/thread.h
 LIB_H += util/trace-event.h
-LIB_H += util/trace-event-perl.h
 LIB_H += util/probe-finder.h
 LIB_H += util/probe-event.h
 
@@ -425,7 +424,7 @@ LIB_OBJS += util/thread.o
 LIB_OBJS += util/trace-event-parse.o
 LIB_OBJS += util/trace-event-read.o
 LIB_OBJS += util/trace-event-info.o
-LIB_OBJS += util/trace-event-perl.o
+LIB_OBJS += util/trace-event-scripting.o
 LIB_OBJS += util/svghelper.o
 LIB_OBJS += util/sort.o
 LIB_OBJS += util/hist.o
@@ -515,6 +514,7 @@ ifneq ($(shell sh -c "(echo '\#include <EXTERN.h>'; echo '\#include <perl.h>'; e
 	BASIC_CFLAGS += -DNO_LIBPERL
 else
 	ALL_LDFLAGS += $(PERL_EMBED_LDOPTS)
+	LIB_OBJS += util/scripting-engines/trace-event-perl.o
 	LIB_OBJS += scripts/perl/Perf-Trace-Util/Context.o
 endif
 
@@ -889,8 +889,8 @@ util/hweight.o: ../../lib/hweight.c PERF-CFLAGS
 util/find_next_bit.o: ../../lib/find_next_bit.c PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o util/find_next_bit.o -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
 
-util/trace-event-perl.o: util/trace-event-perl.c PERF-CFLAGS
-	$(QUIET_CC)$(CC) -o util/trace-event-perl.o -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $<
+util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c PERF-CFLAGS
+	$(QUIET_CC)$(CC) -o util/scripting-engines/trace-event-perl.o -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $<
 
 scripts/perl/Perf-Trace-Util/Context.o: scripts/perl/Perf-Trace-Util/Context.c PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o scripts/perl/Perf-Trace-Util/Context.o -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $<
@@ -1008,6 +1008,7 @@ install: all
 	$(INSTALL) scripts/perl/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/Perf-Trace-Util/lib/Perf/Trace'
 	$(INSTALL) scripts/perl/*.pl -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl'
 	$(INSTALL) scripts/perl/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/bin'
+
 ifdef BUILT_INS
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
 	$(INSTALL) $(BUILT_INS) '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
tools/perf/util/scripting-engines/trace-event-perl.c new file +568 -0

568 lines not on this page · raw message

tools/perf/util/trace-event-perl.c deleted +0 -634

634 lines not on this page · raw message

tools/perf/util/trace-event-perl.h deleted +0 -47

47 lines not on this page · raw message

tools/perf/util/trace-event-scripting.c new file +106 -0

106 lines not on this page · raw message

Signature · 1 line
1.6.4.GIT
#8 lore raw

[tip:perf/core] perf/scripts: Move Perl scripting files to scripting-engines dir

Commit-ID:  82d156cd5e817055c63ec50247a425c195f4cb14
Gitweb:     http://git.kernel.org/tip/82d156cd5e817055c63ec50247a425c195f4cb14
Author:     Tom Zanussi <[email protected]>
AuthorDate: Wed, 27 Jan 2010 02:27:55 -0600
Committer:  Frederic Weisbecker <[email protected]>
CommitDate: Tue, 23 Feb 2010 20:49:55 +0100

perf/scripts: Move Perl scripting files to scripting-engines dir

Create a scripting-engines directory to contain scripting engine implementation code, in anticipation of the addition of new scripting support. Also removes trace-event-perl.h.

Cc Ingo Molnar <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Keiichi KII <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>

LKML-Reference: <[email protected]>

---
 tools/perf/Makefile                                |    9 +-
 .../perf/util/scripting-engines/trace-event-perl.c |  568 ++++++++++++++++++
 tools/perf/util/trace-event-perl.c                 |  634 --------------------
 tools/perf/util/trace-event-perl.h                 |   47 --
 tools/perf/util/trace-event-scripting.c            |  106 ++++
 5 files changed, 679 insertions(+), 685 deletions(-)
tools/perf/Makefile +5 -4
index 3a5fb36..0a3c0c8 100644
@@ -385,7 +385,6 @@ LIB_H += util/sort.h
 LIB_H += util/hist.h
 LIB_H += util/thread.h
 LIB_H += util/trace-event.h
-LIB_H += util/trace-event-perl.h
 LIB_H += util/probe-finder.h
 LIB_H += util/probe-event.h
 
@@ -428,7 +427,7 @@ LIB_OBJS += util/thread.o
 LIB_OBJS += util/trace-event-parse.o
 LIB_OBJS += util/trace-event-read.o
 LIB_OBJS += util/trace-event-info.o
-LIB_OBJS += util/trace-event-perl.o
+LIB_OBJS += util/trace-event-scripting.o
 LIB_OBJS += util/svghelper.o
 LIB_OBJS += util/sort.o
 LIB_OBJS += util/hist.o
@@ -519,6 +518,7 @@ ifneq ($(shell sh -c "(echo '\#include <EXTERN.h>'; echo '\#include <perl.h>'; e
 	BASIC_CFLAGS += -DNO_LIBPERL
 else
 	ALL_LDFLAGS += $(PERL_EMBED_LDOPTS)
+	LIB_OBJS += util/scripting-engines/trace-event-perl.o
 	LIB_OBJS += scripts/perl/Perf-Trace-Util/Context.o
 endif
 
@@ -893,8 +893,8 @@ util/hweight.o: ../../lib/hweight.c PERF-CFLAGS
 util/find_next_bit.o: ../../lib/find_next_bit.c PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o util/find_next_bit.o -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
 
-util/trace-event-perl.o: util/trace-event-perl.c PERF-CFLAGS
-	$(QUIET_CC)$(CC) -o util/trace-event-perl.o -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $<
+util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c PERF-CFLAGS
+	$(QUIET_CC)$(CC) -o util/scripting-engines/trace-event-perl.o -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $<
 
 scripts/perl/Perf-Trace-Util/Context.o: scripts/perl/Perf-Trace-Util/Context.c PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o scripts/perl/Perf-Trace-Util/Context.o -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $<
@@ -1012,6 +1012,7 @@ install: all
 	$(INSTALL) scripts/perl/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/Perf-Trace-Util/lib/Perf/Trace'
 	$(INSTALL) scripts/perl/*.pl -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl'
 	$(INSTALL) scripts/perl/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/bin'
+
 ifdef BUILT_INS
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
 	$(INSTALL) $(BUILT_INS) '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
tools/perf/util/scripting-engines/trace-event-perl.c new file +568 -0

568 lines not on this page · raw message

tools/perf/util/trace-event-perl.c deleted +0 -634

634 lines not on this page · raw message

tools/perf/util/trace-event-perl.h deleted +0 -47

47 lines not on this page · raw message

tools/perf/util/trace-event-scripting.c new file +106 -0

106 lines not on this page · raw message

#9 lore raw

PATCH 5/12 perf trace/scripting: remove check-perf-trace from listed scripts

In reply to Tom Zanussi

The check-perf-trace script only checks Perl functionality, and doesn't really need to be listed as as user script anyway.

This only removes the '-report' shell script, so although it doesn't appear in the listing, the '-record' shell script and the check perf trace perl script itself is still available and can still be run manually as such:

$ libexec/perf-core/scripts/perl/bin/check-perf-trace-record
$ perf trace -s libexec/perf-core/scripts/perl/check-perf-trace.pl
---
 .../perf/scripts/perl/bin/check-perf-trace-record  |    7 +------
 .../perf/scripts/perl/bin/check-perf-trace-report  |    6 ------
 2 files changed, 1 insertions(+), 12 deletions(-)
 delete mode 100644 tools/perf/scripts/perl/bin/check-perf-trace-report
tools/perf/scripts/perl/bin/check-perf-trace-record +1 -6
index c7ec5de..f439cc3 100644
@@ -1,7 +1,2 @@
 #!/bin/bash
-perf record -c 1 -f -a -M -R -e kmem:kmalloc -e irq:softirq_entry
-
-
-
-
-
+perf record -c 1 -f -a -M -R -e kmem:kmalloc -e irq:softirq_entry -e kmem:kmalloc
tools/perf/scripts/perl/bin/check-perf-trace-report deleted +0 -6
deleted file mode 100644
index 7fc4a03..0000000
@@ -1,6 +0,0 @@
-#!/bin/bash
-# description: useless but exhaustive test script
-perf trace -s ~/libexec/perf-core/scripts/perl/check-perf-trace.pl
-
-
-
Signature · 1 line
1.6.4.GIT
#10 lore raw

Re: [PATCH 05/12] perf trace/scripting: remove check-perf-trace from listed scripts

Quoted 23 lines · Tom Zanussi

The check-perf-trace script only checks Perl functionality, and doesn't really need to be listed as as user script anyway.

This only removes the '-report' shell script, so although it doesn't appear in the listing, the '-record' shell script and the check perf trace perl script itself is still available and can still be run manually as such:

$ libexec/perf-core/scripts/perl/bin/check-perf-trace-record
$ perf trace -s libexec/perf-core/scripts/perl/check-perf-trace.pl
---
 .../perf/scripts/perl/bin/check-perf-trace-record  |    7 +------
 .../perf/scripts/perl/bin/check-perf-trace-report  |    6 ------
 2 files changed, 1 insertions(+), 12 deletions(-)
 delete mode 100644 tools/perf/scripts/perl/bin/check-perf-trace-report
tools/perf/scripts/perl/bin/check-perf-trace-record +0 -0
index c7ec5de..f439cc3 100644

tools/perf/scripts/perl/bin/check-perf-trace-record line 2

Quoted 8 lines
tools/perf/scripts/perl/bin/check-perf-trace-record +1 -6
@@ -1,7 +1,2 @@
 #!/bin/bash
-perf record -c 1 -f -a -M -R -e kmem:kmalloc -e irq:softirq_entry
-
-
-
-
-
+perf record -c 1 -f -a -M -R -e kmem:kmalloc -e irq:softirq_entry -e kmem:kmalloc

Looks like kmem:kmalloc has been appended twice incidentally there. No problem, I'll remove it.

Thanks.

#11 lore raw

[tip:perf/core] perf/scripts: Remove check-perf-trace from listed scripts

In reply to Tom Zanussi
Commit-ID:  266fe2f217d1dc9f8041e395c0ab4569a5bad91a
Gitweb:     http://git.kernel.org/tip/266fe2f217d1dc9f8041e395c0ab4569a5bad91a
Author:     Tom Zanussi <[email protected]>
AuthorDate: Wed, 27 Jan 2010 02:27:56 -0600
Committer:  Frederic Weisbecker <[email protected]>
CommitDate: Tue, 23 Feb 2010 20:58:59 +0100

perf/scripts: Remove check-perf-trace from listed scripts

The check-perf-trace script only checks Perl functionality, and doesn't really need to be listed as as user script anyway.

This only removes the '-report' shell script, so although it doesn't appear in the listing, the '-record' shell script and the check perf trace perl script itself is still available and can still be run manually as such:

$ libexec/perf-core/scripts/perl/bin/check-perf-trace-record
$ perf trace -s libexec/perf-core/scripts/perl/check-perf-trace.pl
Cc Ingo Molnar <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Keiichi KII <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>

LKML-Reference: <[email protected]>

---
 .../perf/scripts/perl/bin/check-perf-trace-record  |    5 -----
 .../perf/scripts/perl/bin/check-perf-trace-report  |    6 ------
 2 files changed, 0 insertions(+), 11 deletions(-)
tools/perf/scripts/perl/bin/check-perf-trace-record +0 -5
index c7ec5de..3c15744 100644
@@ -1,7 +1,2 @@
 #!/bin/bash
 perf record -c 1 -f -a -M -R -e kmem:kmalloc -e irq:softirq_entry
-
-
-
-
-
tools/perf/scripts/perl/bin/check-perf-trace-report deleted +0 -6
deleted file mode 100644
index 7fc4a03..0000000
@@ -1,6 +0,0 @@
-#!/bin/bash
-# description: useless but exhaustive test script
-perf trace -s ~/libexec/perf-core/scripts/perl/check-perf-trace.pl
-
-
-
#12 lore raw

[tip:perf/core] perf/scripts: Add Python scripting engine

In reply to Tom Zanussi
Commit-ID:  7e4b21b84c43bb8a80b916e40718ca4ed1fc52e6
Gitweb:     http://git.kernel.org/tip/7e4b21b84c43bb8a80b916e40718ca4ed1fc52e6
Author:     Tom Zanussi <[email protected]>
AuthorDate: Wed, 27 Jan 2010 02:27:57 -0600
Committer:  Frederic Weisbecker <[email protected]>
CommitDate: Thu, 25 Feb 2010 04:07:29 +0100

perf/scripts: Add Python scripting engine

Add base support for Python scripting to perf trace.

Cc Ingo Molnar <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Keiichi KII <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>

LKML-Reference: <[email protected]>

---
 tools/perf/Makefile                                |   21 +
 tools/perf/builtin-trace.c                         |    1 +
 .../perf/scripts/python/Perf-Trace-Util/Context.c  |   88 +++
 .../python/Perf-Trace-Util/lib/Perf/Trace/Core.py  |   91 +++
 .../python/Perf-Trace-Util/lib/Perf/Trace/Util.py  |   25 +
 .../util/scripting-engines/trace-event-python.c    |  576 ++++++++++++++++++++
 tools/perf/util/trace-event-scripting.c            |   61 ++
 tools/perf/util/trace-event.h                      |    1 +
 8 files changed, 864 insertions(+), 0 deletions(-)
tools/perf/Makefile +21 -0
index 0a3c0c8..1427316 100644
@@ -522,6 +522,19 @@ else
 	LIB_OBJS += scripts/perl/Perf-Trace-Util/Context.o
 endif
 
+ifndef NO_LIBPYTHON
+PYTHON_EMBED_LDOPTS = `python-config --ldflags 2>/dev/null`
+PYTHON_EMBED_CCOPTS = `python-config --cflags 2>/dev/null`
+endif
+
+ifneq ($(shell sh -c "(echo '\#include <Python.h>'; echo 'int main(void) { Py_Initialize(); return 0; }') | $(CC) -x c - $(PYTHON_EMBED_CCOPTS) -o /dev/null $(PYTHON_EMBED_LDOPTS) > /dev/null 2>&1 && echo y"), y)
+	BASIC_CFLAGS += -DNO_LIBPYTHON
+else
+	ALL_LDFLAGS += $(PYTHON_EMBED_LDOPTS)
+	LIB_OBJS += util/scripting-engines/trace-event-python.o
+	LIB_OBJS += scripts/python/Perf-Trace-Util/Context.o
+endif
+
 ifdef NO_DEMANGLE
 	BASIC_CFLAGS += -DNO_DEMANGLE
 else
@@ -899,6 +912,12 @@ util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-pe
 scripts/perl/Perf-Trace-Util/Context.o: scripts/perl/Perf-Trace-Util/Context.c PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o scripts/perl/Perf-Trace-Util/Context.o -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $<
 
+util/scripting-engines/trace-event-python.o: util/scripting-engines/trace-event-python.c PERF-CFLAGS
+	$(QUIET_CC)$(CC) -o util/scripting-engines/trace-event-python.o -c $(ALL_CFLAGS) $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $<
+
+scripts/python/Perf-Trace-Util/Context.o: scripts/python/Perf-Trace-Util/Context.c PERF-CFLAGS
+	$(QUIET_CC)$(CC) -o scripts/python/Perf-Trace-Util/Context.o -c $(ALL_CFLAGS) $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $<
+
 perf-%$X: %.o $(PERFLIBS)
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
 
@@ -1012,6 +1031,8 @@ install: all
 	$(INSTALL) scripts/perl/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/Perf-Trace-Util/lib/Perf/Trace'
 	$(INSTALL) scripts/perl/*.pl -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl'
 	$(INSTALL) scripts/perl/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/bin'
+	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace'
+	$(INSTALL) scripts/python/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace'
 
 ifdef BUILT_INS
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
tools/perf/builtin-trace.c +1 -0
index d5d20c3..5db687f 100644
@@ -44,6 +44,7 @@ static void setup_scripting(void)
 	perf_set_argv_exec_path(perf_exec_path());
 
 	setup_perl_scripting();
+	setup_python_scripting();
 
 	scripting_ops = &default_scripting_ops;
 }
tools/perf/scripts/python/Perf-Trace-Util/Context.c new file +88 -0

88 lines not on this page · raw message

tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Core.py new file +91 -0

91 lines not on this page · raw message

tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py new file +25 -0
new file mode 100644
index 0000000..83e9143
@@ -0,0 +1,25 @@
+# Util.py - Python extension for perf trace, miscellaneous utility code
+#
+# Copyright (C) 2010 by Tom Zanussi <[email protected]>
+#
+# This software may be distributed under the terms of the GNU General
+# Public License ("GPL") version 2 as published by the Free Software
+# Foundation.
+
+NSECS_PER_SEC    = 1000000000
+
+def avg(total, n):
+    return total / n
+
+def nsecs(secs, nsecs):
+    return secs * NSECS_PER_SEC + nsecs
+
+def nsecs_secs(nsecs):
+    return nsecs / NSECS_PER_SEC
+
+def nsecs_nsecs(nsecs):
+    return nsecs % NSECS_PER_SEC
+
+def nsecs_str(nsecs):
+    str = "%5u.%09u" % (nsecs_secs(nsecs), nsecs_nsecs(nsecs)),
+    return str
tools/perf/util/scripting-engines/trace-event-python.c new file +576 -0

576 lines not on this page · raw message

tools/perf/util/trace-event-scripting.c +61 -0

67 lines not on this page · raw message

tools/perf/util/trace-event.h +1 -0
index aaf2da2..c3269b9 100644
@@ -280,6 +280,7 @@ struct scripting_ops {
 int script_spec_register(const char *spec, struct scripting_ops *ops);
 
 void setup_perl_scripting(void);
+void setup_python_scripting(void);
 
 struct scripting_context {
 	void *event_data;
#13 lore raw

PATCH 6/12 perf trace/scripting: add Python scripting engine

In reply to Tom Zanussi

Add base support for Python scripting to perf trace.

---
 tools/perf/Makefile                                |   21 +
 tools/perf/builtin-trace.c                         |    1 +
 .../perf/scripts/python/Perf-Trace-Util/Context.c  |   88 +++
 .../python/Perf-Trace-Util/lib/Perf/Trace/Core.py  |   91 +++
 .../python/Perf-Trace-Util/lib/Perf/Trace/Util.py  |   25 +
 .../util/scripting-engines/trace-event-python.c    |  576 ++++++++++++++++++++
 tools/perf/util/trace-event-scripting.c            |   61 ++
 tools/perf/util/trace-event.h                      |    1 +
 8 files changed, 864 insertions(+), 0 deletions(-)
 create mode 100644 tools/perf/scripts/python/Perf-Trace-Util/Context.c
 create mode 100644 tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Core.py
 create mode 100644 tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py
 create mode 100644 tools/perf/util/scripting-engines/trace-event-python.c
tools/perf/Makefile +21 -0
index b09588f..19d535f 100644
@@ -518,6 +518,19 @@ else
 	LIB_OBJS += scripts/perl/Perf-Trace-Util/Context.o
 endif
 
+ifndef NO_LIBPYTHON
+PYTHON_EMBED_LDOPTS = `python-config --ldflags 2>/dev/null`
+PYTHON_EMBED_CCOPTS = `python-config --cflags 2>/dev/null`
+endif
+
+ifneq ($(shell sh -c "(echo '\#include <Python.h>'; echo 'int main(void) { Py_Initialize(); return 0; }') | $(CC) -x c - $(PYTHON_EMBED_CCOPTS) -o /dev/null $(PYTHON_EMBED_LDOPTS) > /dev/null 2>&1 && echo y"), y)
+	BASIC_CFLAGS += -DNO_LIBPYTHON
+else
+	ALL_LDFLAGS += $(PYTHON_EMBED_LDOPTS)
+	LIB_OBJS += util/scripting-engines/trace-event-python.o
+	LIB_OBJS += scripts/python/Perf-Trace-Util/Context.o
+endif
+
 ifdef NO_DEMANGLE
 	BASIC_CFLAGS += -DNO_DEMANGLE
 else
@@ -895,6 +908,12 @@ util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-pe
 scripts/perl/Perf-Trace-Util/Context.o: scripts/perl/Perf-Trace-Util/Context.c PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o scripts/perl/Perf-Trace-Util/Context.o -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $<
 
+util/scripting-engines/trace-event-python.o: util/scripting-engines/trace-event-python.c PERF-CFLAGS
+	$(QUIET_CC)$(CC) -o util/scripting-engines/trace-event-python.o -c $(ALL_CFLAGS) $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $<
+
+scripts/python/Perf-Trace-Util/Context.o: scripts/python/Perf-Trace-Util/Context.c PERF-CFLAGS
+	$(QUIET_CC)$(CC) -o scripts/python/Perf-Trace-Util/Context.o -c $(ALL_CFLAGS) $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $<
+
 perf-%$X: %.o $(PERFLIBS)
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
 
@@ -1008,6 +1027,8 @@ install: all
 	$(INSTALL) scripts/perl/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/Perf-Trace-Util/lib/Perf/Trace'
 	$(INSTALL) scripts/perl/*.pl -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl'
 	$(INSTALL) scripts/perl/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/bin'
+	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace'
+	$(INSTALL) scripts/python/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace'
 
 ifdef BUILT_INS
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
tools/perf/builtin-trace.c +1 -0
index 850d0aa..eee0805 100644
@@ -44,6 +44,7 @@ static void setup_scripting(void)
 	perf_set_argv_exec_path(perf_exec_path());
 
 	setup_perl_scripting();
+	setup_python_scripting();
 
 	scripting_ops = &default_scripting_ops;
 }
tools/perf/scripts/python/Perf-Trace-Util/Context.c new file +88 -0

88 lines not on this page · raw message

tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Core.py new file +91 -0

91 lines not on this page · raw message

tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py new file +25 -0
new file mode 100644
index 0000000..83e9143
@@ -0,0 +1,25 @@
+# Util.py - Python extension for perf trace, miscellaneous utility code
+#
+# Copyright (C) 2010 by Tom Zanussi <[email protected]>
+#
+# This software may be distributed under the terms of the GNU General
+# Public License ("GPL") version 2 as published by the Free Software
+# Foundation.
+
+NSECS_PER_SEC    = 1000000000
+
+def avg(total, n):
+    return total / n
+
+def nsecs(secs, nsecs):
+    return secs * NSECS_PER_SEC + nsecs
+
+def nsecs_secs(nsecs):
+    return nsecs / NSECS_PER_SEC
+
+def nsecs_nsecs(nsecs):
+    return nsecs % NSECS_PER_SEC
+
+def nsecs_str(nsecs):
+    str = "%5u.%09u" % (nsecs_secs(nsecs), nsecs_nsecs(nsecs)),
+    return str
tools/perf/util/scripting-engines/trace-event-python.c new file +576 -0

576 lines not on this page · raw message

tools/perf/util/trace-event-scripting.c +61 -0

67 lines not on this page · raw message

tools/perf/util/trace-event.h +1 -0
index aaf2da2..c3269b9 100644
@@ -280,6 +280,7 @@ struct scripting_ops {
 int script_spec_register(const char *spec, struct scripting_ops *ops);
 
 void setup_perl_scripting(void);
+void setup_python_scripting(void);
 
 struct scripting_context {
 	void *event_data;
Signature · 1 line
1.6.4.GIT
#14 lore raw

Re: [PATCH 06/12] perf trace/scripting: add Python scripting engine

Quoted 17 lines · Tom Zanussi
tools/perf/util/scripting-engines/trace-event-python.c new file +17 -0
+static void define_value(enum print_arg_type field_type,
+			 const char *ev_name,
+			 const char *field_name,
+			 const char *field_value,
+			 const char *field_str)
+{
+	const char *handler_name = "define_flag_value";
+	PyObject *handler, *t, *retval;
+	unsigned long long value;
+	unsigned n = 0;
+
+	if (field_type == PRINT_SYMBOL)
+		handler_name = "define_symbolic_value";
+
+	t = PyTuple_New(MAX_FIELDS);
+	if (!t)
+		Py_FatalError("couldn't create Python tuple");

tools/perf/util/scripting-engines/trace-event-python.c line 83

Quoted 10 lines
tools/perf/util/scripting-engines/trace-event-python.c new file +10 -0
+
+	value = eval_flag(field_value);
+
+	PyTuple_SetItem(t, n++, PyString_FromString(ev_name));
+	PyTuple_SetItem(t, n++, PyString_FromString(field_name));
+	PyTuple_SetItem(t, n++, PyInt_FromLong(value));
+	PyTuple_SetItem(t, n++, PyString_FromString(field_str));
+
+	if (_PyTuple_Resize(&t, n) == -1)
+		Py_FatalError("error resizing Python tuple");

Why are creating a tuple of 64 fields while you are always using 4?

Quoted 12 lines
tools/perf/util/scripting-engines/trace-event-python.c new file +12 -0
+
+	handler = PyDict_GetItemString(main_dict, handler_name);
+	if (handler && PyCallable_Check(handler)) {
+		retval = PyObject_CallObject(handler, t);
+		if (retval == NULL)
+			handler_call_die(handler_name);
+	}
+
+	Py_DECREF(t);
+}
+
+

[...]

Quoted 13 lines
tools/perf/util/scripting-engines/trace-event-python.c new file +13 -0
+static void define_field(enum print_arg_type field_type,
+			 const char *ev_name,
+			 const char *field_name,
+			 const char *delim)
+{
+	const char *handler_name = "define_flag_field";
+	PyObject *handler, *t, *retval;
+	unsigned n = 0;
+
+	if (field_type == PRINT_SYMBOL)
+		handler_name = "define_symbolic_field";
+
+	t = PyTuple_New(MAX_FIELDS);

tools/perf/util/scripting-engines/trace-event-python.c line 129

Quoted 10 lines
tools/perf/util/scripting-engines/trace-event-python.c new file +10 -0
+	if (!t)
+		Py_FatalError("couldn't create Python tuple");
+
+	PyTuple_SetItem(t, n++, PyString_FromString(ev_name));
+	PyTuple_SetItem(t, n++, PyString_FromString(field_name));
+	if (field_type == PRINT_FLAGS)
+		PyTuple_SetItem(t, n++, PyString_FromString(delim));
+
+	if (_PyTuple_Resize(&t, n) == -1)
+		Py_FatalError("error resizing Python tuple");

Same here (except you may or may not have a PRINT_FLAGS type).

This is about neats though. The patch looks pretty nice.

#15 lore raw

Re: [PATCH 06/12] perf trace/scripting: add Python scripting engine

Quoted 70 lines · Frederic Weisbecker
Quoted 17 lines · Tom Zanussi
(quoted diff) +17 -0
+static void define_value(enum print_arg_type field_type,
+			 const char *ev_name,
+			 const char *field_name,
+			 const char *field_value,
+			 const char *field_str)
+{
+	const char *handler_name = "define_flag_value";
+	PyObject *handler, *t, *retval;
+	unsigned long long value;
+	unsigned n = 0;
+
+	if (field_type == PRINT_SYMBOL)
+		handler_name = "define_symbolic_value";
+
+	t = PyTuple_New(MAX_FIELDS);
+	if (!t)
+		Py_FatalError("couldn't create Python tuple");

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+	value = eval_flag(field_value);
+
+	PyTuple_SetItem(t, n++, PyString_FromString(ev_name));
+	PyTuple_SetItem(t, n++, PyString_FromString(field_name));
+	PyTuple_SetItem(t, n++, PyInt_FromLong(value));
+	PyTuple_SetItem(t, n++, PyString_FromString(field_str));
+
+	if (_PyTuple_Resize(&t, n) == -1)
+		Py_FatalError("error resizing Python tuple");

Why are creating a tuple of 64 fields while you are always using 4?

Quoted 12 lines
(quoted diff) +12 -0
+
+	handler = PyDict_GetItemString(main_dict, handler_name);
+	if (handler && PyCallable_Check(handler)) {
+		retval = PyObject_CallObject(handler, t);
+		if (retval == NULL)
+			handler_call_die(handler_name);
+	}
+
+	Py_DECREF(t);
+}
+
+

[...]

Quoted 19 lines
(quoted diff) +19 -0
+static void define_field(enum print_arg_type field_type,
+			 const char *ev_name,
+			 const char *field_name,
+			 const char *delim)
+{
+	const char *handler_name = "define_flag_field";
+	PyObject *handler, *t, *retval;
+	unsigned n = 0;
+
+	if (field_type == PRINT_SYMBOL)
+		handler_name = "define_symbolic_field";
+
+	t = PyTuple_New(MAX_FIELDS);
+	if (!t)
+		Py_FatalError("couldn't create Python tuple");
+
+	PyTuple_SetItem(t, n++, PyString_FromString(ev_name));
+	PyTuple_SetItem(t, n++, PyString_FromString(field_name));
+	if (field_type == PRINT_FLAGS)
Quoted 9 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+		PyTuple_SetItem(t, n++, PyString_FromString(delim));
+
+	if (_PyTuple_Resize(&t, n) == -1)
+		Py_FatalError("error resizing Python tuple");

Same here (except you may or may not have a PRINT_FLAGS type).

Good point - no reason to resize if we don't have to. Here's a patch to change that.

Thanks,

Tom

[PATCH] perf trace/scripting: remove unnecessary PyTuple resizes

If we know the size of a tuple in advance, there's no need to resize it - start out with the known size in the first place.

---
 .../util/scripting-engines/trace-event-python.c    |   13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)
tools/perf/util/scripting-engines/trace-event-python.c +5 -8
index d402f64..33a414b 100644
@@ -68,7 +68,7 @@ static void define_value(enum print_arg_type field_type,
 	if (field_type == PRINT_SYMBOL)
 		handler_name = "define_symbolic_value";
 
-	t = PyTuple_New(MAX_FIELDS);
+	t = PyTuple_New(4);
 	if (!t)
 		Py_FatalError("couldn't create Python tuple");
 
@@ -79,9 +79,6 @@ static void define_value(enum print_arg_type field_type,
 	PyTuple_SetItem(t, n++, PyInt_FromLong(value));
 	PyTuple_SetItem(t, n++, PyString_FromString(field_str));
 
-	if (_PyTuple_Resize(&t, n) == -1)
-		Py_FatalError("error resizing Python tuple");
-
 	handler = PyDict_GetItemString(main_dict, handler_name);
 	if (handler && PyCallable_Check(handler)) {
 		retval = PyObject_CallObject(handler, t);
@@ -116,7 +113,10 @@ static void define_field(enum print_arg_type field_type,
 	if (field_type == PRINT_SYMBOL)
 		handler_name = "define_symbolic_field";
 
-	t = PyTuple_New(MAX_FIELDS);
+	if (field_type == PRINT_FLAGS)
+		t = PyTuple_New(3);
+	else
+		t = PyTuple_New(2);
 	if (!t)
 		Py_FatalError("couldn't create Python tuple");
 
@@ -125,9 +125,6 @@ static void define_field(enum print_arg_type field_type,
 	if (field_type == PRINT_FLAGS)
 		PyTuple_SetItem(t, n++, PyString_FromString(delim));
 
-	if (_PyTuple_Resize(&t, n) == -1)
-		Py_FatalError("error resizing Python tuple");
-
 	handler = PyDict_GetItemString(main_dict, handler_name);
 	if (handler && PyCallable_Check(handler)) {
 		retval = PyObject_CallObject(handler, t);
Signature · 1 line
1.6.4.GIT
#16 lore raw

[tip:perf/core] perf/scripts: Remove unnecessary PyTuple resizes

Commit-ID:  44ad9cd8f0893b9ae0ac729a7dc2a1ebcd170ac6
Gitweb:     http://git.kernel.org/tip/44ad9cd8f0893b9ae0ac729a7dc2a1ebcd170ac6
Author:     Tom Zanussi <[email protected]>
AuthorDate: Mon, 22 Feb 2010 01:12:59 -0600
Committer:  Frederic Weisbecker <[email protected]>
CommitDate: Thu, 25 Feb 2010 04:07:49 +0100

perf/scripts: Remove unnecessary PyTuple resizes

If we know the size of a tuple in advance, there's no need to resize it - start out with the known size in the first place.

Cc Ingo Molnar <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Keiichi KII <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>

LKML-Reference: <1266822779.6426.4.camel@tropicana>

---
 .../util/scripting-engines/trace-event-python.c    |   13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)
tools/perf/util/scripting-engines/trace-event-python.c +5 -8
index d402f64..33a414b 100644
@@ -68,7 +68,7 @@ static void define_value(enum print_arg_type field_type,
 	if (field_type == PRINT_SYMBOL)
 		handler_name = "define_symbolic_value";
 
-	t = PyTuple_New(MAX_FIELDS);
+	t = PyTuple_New(4);
 	if (!t)
 		Py_FatalError("couldn't create Python tuple");
 
@@ -79,9 +79,6 @@ static void define_value(enum print_arg_type field_type,
 	PyTuple_SetItem(t, n++, PyInt_FromLong(value));
 	PyTuple_SetItem(t, n++, PyString_FromString(field_str));
 
-	if (_PyTuple_Resize(&t, n) == -1)
-		Py_FatalError("error resizing Python tuple");
-
 	handler = PyDict_GetItemString(main_dict, handler_name);
 	if (handler && PyCallable_Check(handler)) {
 		retval = PyObject_CallObject(handler, t);
@@ -116,7 +113,10 @@ static void define_field(enum print_arg_type field_type,
 	if (field_type == PRINT_SYMBOL)
 		handler_name = "define_symbolic_field";
 
-	t = PyTuple_New(MAX_FIELDS);
+	if (field_type == PRINT_FLAGS)
+		t = PyTuple_New(3);
+	else
+		t = PyTuple_New(2);
 	if (!t)
 		Py_FatalError("couldn't create Python tuple");
 
@@ -125,9 +125,6 @@ static void define_field(enum print_arg_type field_type,
 	if (field_type == PRINT_FLAGS)
 		PyTuple_SetItem(t, n++, PyString_FromString(delim));
 
-	if (_PyTuple_Resize(&t, n) == -1)
-		Py_FatalError("error resizing Python tuple");
-
 	handler = PyDict_GetItemString(main_dict, handler_name);
 	if (handler && PyCallable_Check(handler)) {
 		retval = PyObject_CallObject(handler, t);
#17 lore raw

PATCH 7/12 perf trace/scripting: add syscall tracing scripts

In reply to Tom Zanussi

Adds a set of scripts for that aggregate system call totals and system call errors. Most are Python scripts that also test basic functionality of the new Python engine, but there's also one Perl script added for comparison and for reference in some new Documentation contained in a later patch.

---
 tools/perf/Makefile                                |    3 +
 .../perf/scripts/perl/bin/check-perf-trace-record  |    2 +-
 tools/perf/scripts/perl/bin/failed-syscalls-record |    2 +
 tools/perf/scripts/perl/bin/failed-syscalls-report |    4 +
 tools/perf/scripts/perl/failed-syscalls.pl         |   38 +++++++++
 .../python/bin/failed-syscalls-by-pid-record       |    2 +
 .../python/bin/failed-syscalls-by-pid-report       |    4 +
 .../python/bin/syscall-counts-by-pid-record        |    2 +
 .../python/bin/syscall-counts-by-pid-report        |    4 +
 .../perf/scripts/python/bin/syscall-counts-record  |    2 +
 .../perf/scripts/python/bin/syscall-counts-report  |    4 +
 tools/perf/scripts/python/check-perf-trace.py      |   83 ++++++++++++++++++++
 .../perf/scripts/python/failed-syscalls-by-pid.py  |   68 ++++++++++++++++
 tools/perf/scripts/python/syscall-counts-by-pid.py |   64 +++++++++++++++
 tools/perf/scripts/python/syscall-counts.py        |   58 ++++++++++++++
 15 files changed, 339 insertions(+), 1 deletions(-)
 create mode 100644 tools/perf/scripts/perl/bin/failed-syscalls-record
 create mode 100644 tools/perf/scripts/perl/bin/failed-syscalls-report
 create mode 100644 tools/perf/scripts/perl/failed-syscalls.pl
 create mode 100644 tools/perf/scripts/python/bin/failed-syscalls-by-pid-record
 create mode 100644 tools/perf/scripts/python/bin/failed-syscalls-by-pid-report
 create mode 100644 tools/perf/scripts/python/bin/syscall-counts-by-pid-record
 create mode 100644 tools/perf/scripts/python/bin/syscall-counts-by-pid-report
 create mode 100644 tools/perf/scripts/python/bin/syscall-counts-record
 create mode 100644 tools/perf/scripts/python/bin/syscall-counts-report
 create mode 100644 tools/perf/scripts/python/check-perf-trace.py
 create mode 100644 tools/perf/scripts/python/failed-syscalls-by-pid.py
 create mode 100644 tools/perf/scripts/python/syscall-counts-by-pid.py
 create mode 100644 tools/perf/scripts/python/syscall-counts.py
tools/perf/Makefile +3 -0
index 19d535f..25664d5 100644
@@ -1028,7 +1028,10 @@ install: all
 	$(INSTALL) scripts/perl/*.pl -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl'
 	$(INSTALL) scripts/perl/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/bin'
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace'
+	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin'
 	$(INSTALL) scripts/python/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace'
+	$(INSTALL) scripts/python/*.py -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python'
+	$(INSTALL) scripts/python/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin'
 
 ifdef BUILT_INS
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
tools/perf/scripts/perl/bin/check-perf-trace-record +1 -1
index f439cc3..e6cb147 100644
@@ -1,2 +1,2 @@
 #!/bin/bash
-perf record -c 1 -f -a -M -R -e kmem:kmalloc -e irq:softirq_entry -e kmem:kmalloc
+perf record -c 1 -f -a -M -R -e kmem:kmalloc -e irq:softirq_entry -e kmem:kfree
tools/perf/scripts/perl/bin/failed-syscalls-record new file +2 -0
new file mode 100644
index 0000000..f8885d3
@@ -0,0 +1,2 @@
+#!/bin/bash
+perf record -c 1 -f -a -M -R -e raw_syscalls:sys_exit
tools/perf/scripts/perl/bin/failed-syscalls-report new file +4 -0
new file mode 100644
index 0000000..8bfc660
@@ -0,0 +1,4 @@
+#!/bin/bash
+# description: system-wide failed syscalls
+# args: [comm]
+perf trace -s ~/libexec/perf-core/scripts/perl/failed-syscalls.pl $1
tools/perf/scripts/perl/failed-syscalls.pl new file +38 -0
new file mode 100644
index 0000000..c18e7e2
@@ -0,0 +1,38 @@
+# failed system call counts
+# (c) 2010, Tom Zanussi <[email protected]>
+# Licensed under the terms of the GNU GPL License version 2
+#
+# Displays system-wide failed system call totals
+# If a [comm] arg is specified, only syscalls called by [comm] are displayed.
+
+use lib "$ENV{'PERF_EXEC_PATH'}/scripts/perl/Perf-Trace-Util/lib";
+use lib "./Perf-Trace-Util/lib";
+use Perf::Trace::Core;
+use Perf::Trace::Context;
+use Perf::Trace::Util;
+
+my %failed_syscalls;
+
+sub raw_syscalls::sys_exit
+{
+	my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
+	    $common_pid, $common_comm,
+	    $id, $ret) = @_;
+
+	if ($ret < 0) {
+	    $failed_syscalls{$common_comm}++;
+	}
+}
+
+sub trace_end
+{
+    printf("\nfailed syscalls by comm:\n\n");
+
+    printf("%-20s  %10s\n", "comm", "# errors");
+    printf("%-20s  %6s  %10s\n", "--------------------", "----------");
+
+    foreach my $comm (sort {$failed_syscalls{$b} <=> $failed_syscalls{$a}}
+		      keys %failed_syscalls) {
+	    printf("%-20s  %10s\n", $comm, $failed_syscalls{$comm});
+    }
+}
tools/perf/scripts/python/bin/failed-syscalls-by-pid-record new file +2 -0
new file mode 100644
index 0000000..f8885d3
@@ -0,0 +1,2 @@
+#!/bin/bash
+perf record -c 1 -f -a -M -R -e raw_syscalls:sys_exit
tools/perf/scripts/python/bin/failed-syscalls-by-pid-report new file +4 -0
new file mode 100644
index 0000000..1e0c0a8
@@ -0,0 +1,4 @@
+#!/bin/bash
+# description: system-wide failed syscalls, by pid
+# args: [comm]
+perf trace -s ~/libexec/perf-core/scripts/python/failed-syscalls-by-pid.py $1
tools/perf/scripts/python/bin/syscall-counts-by-pid-record new file +2 -0
new file mode 100644
index 0000000..45a8c50
@@ -0,0 +1,2 @@
+#!/bin/bash
+perf record -c 1 -f -a -M -R -e raw_syscalls:sys_enter
tools/perf/scripts/python/bin/syscall-counts-by-pid-report new file +4 -0
new file mode 100644
index 0000000..f8044d1
@@ -0,0 +1,4 @@
+#!/bin/bash
+# description: system-wide syscall counts, by pid
+# args: [comm]
+perf trace -s ~/libexec/perf-core/scripts/python/syscall-counts-by-pid.py $1
tools/perf/scripts/python/bin/syscall-counts-record new file +2 -0
new file mode 100644
index 0000000..45a8c50
@@ -0,0 +1,2 @@
+#!/bin/bash
+perf record -c 1 -f -a -M -R -e raw_syscalls:sys_enter
tools/perf/scripts/python/bin/syscall-counts-report new file +4 -0
new file mode 100644
index 0000000..a366aa6
@@ -0,0 +1,4 @@
+#!/bin/bash
+# description: system-wide syscall counts
+# args: [comm]
+perf trace -s ~/libexec/perf-core/scripts/python/syscall-counts.py $1
tools/perf/scripts/python/check-perf-trace.py new file +83 -0

83 lines not on this page · raw message

tools/perf/scripts/python/failed-syscalls-by-pid.py new file +68 -0

68 lines not on this page · raw message

tools/perf/scripts/python/syscall-counts-by-pid.py new file +64 -0

64 lines not on this page · raw message

tools/perf/scripts/python/syscall-counts.py new file +58 -0

58 lines not on this page · raw message

Signature · 1 line
1.6.4.GIT
#18 lore raw

[tip:perf/core] perf/scripts: Add syscall tracing scripts

Commit-ID:  4d161f0360d00d46a89827b3fd6da395f00c5d90
Gitweb:     http://git.kernel.org/tip/4d161f0360d00d46a89827b3fd6da395f00c5d90
Author:     Tom Zanussi <[email protected]>
AuthorDate: Wed, 27 Jan 2010 02:27:58 -0600
Committer:  Frederic Weisbecker <[email protected]>
CommitDate: Thu, 25 Feb 2010 04:07:48 +0100

perf/scripts: Add syscall tracing scripts

Adds a set of scripts that aggregate system call totals and system call errors. Most are Python scripts that also test basic functionality of the new Python engine, but there's also one Perl script added for comparison and for reference in some new Documentation contained in a later patch.

Cc Ingo Molnar <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Keiichi KII <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>

LKML-Reference: <[email protected]>

---
 tools/perf/Makefile                                |    3 +
 .../perf/scripts/perl/bin/check-perf-trace-record  |    2 +-
 tools/perf/scripts/perl/bin/failed-syscalls-record |    2 +
 tools/perf/scripts/perl/bin/failed-syscalls-report |    4 +
 tools/perf/scripts/perl/failed-syscalls.pl         |   38 +++++++++
 .../python/bin/failed-syscalls-by-pid-record       |    2 +
 .../python/bin/failed-syscalls-by-pid-report       |    4 +
 .../python/bin/syscall-counts-by-pid-record        |    2 +
 .../python/bin/syscall-counts-by-pid-report        |    4 +
 .../perf/scripts/python/bin/syscall-counts-record  |    2 +
 .../perf/scripts/python/bin/syscall-counts-report  |    4 +
 tools/perf/scripts/python/check-perf-trace.py      |   83 ++++++++++++++++++++
 .../perf/scripts/python/failed-syscalls-by-pid.py  |   68 ++++++++++++++++
 tools/perf/scripts/python/syscall-counts-by-pid.py |   64 +++++++++++++++
 tools/perf/scripts/python/syscall-counts.py        |   58 ++++++++++++++
 15 files changed, 339 insertions(+), 1 deletions(-)
tools/perf/Makefile +3 -0
index 1427316..54a5b50 100644
@@ -1032,7 +1032,10 @@ install: all
 	$(INSTALL) scripts/perl/*.pl -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl'
 	$(INSTALL) scripts/perl/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/bin'
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace'
+	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin'
 	$(INSTALL) scripts/python/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace'
+	$(INSTALL) scripts/python/*.py -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python'
+	$(INSTALL) scripts/python/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin'
 
 ifdef BUILT_INS
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
tools/perf/scripts/perl/bin/check-perf-trace-record +1 -1
index 3c15744..e6cb147 100644
@@ -1,2 +1,2 @@
 #!/bin/bash
-perf record -c 1 -f -a -M -R -e kmem:kmalloc -e irq:softirq_entry
+perf record -c 1 -f -a -M -R -e kmem:kmalloc -e irq:softirq_entry -e kmem:kfree
tools/perf/scripts/perl/bin/failed-syscalls-record new file +2 -0
new file mode 100644
index 0000000..f8885d3
@@ -0,0 +1,2 @@
+#!/bin/bash
+perf record -c 1 -f -a -M -R -e raw_syscalls:sys_exit
tools/perf/scripts/perl/bin/failed-syscalls-report new file +4 -0
new file mode 100644
index 0000000..8bfc660
@@ -0,0 +1,4 @@
+#!/bin/bash
+# description: system-wide failed syscalls
+# args: [comm]
+perf trace -s ~/libexec/perf-core/scripts/perl/failed-syscalls.pl $1
tools/perf/scripts/perl/failed-syscalls.pl new file +38 -0
new file mode 100644
index 0000000..c18e7e2
@@ -0,0 +1,38 @@
+# failed system call counts
+# (c) 2010, Tom Zanussi <[email protected]>
+# Licensed under the terms of the GNU GPL License version 2
+#
+# Displays system-wide failed system call totals
+# If a [comm] arg is specified, only syscalls called by [comm] are displayed.
+
+use lib "$ENV{'PERF_EXEC_PATH'}/scripts/perl/Perf-Trace-Util/lib";
+use lib "./Perf-Trace-Util/lib";
+use Perf::Trace::Core;
+use Perf::Trace::Context;
+use Perf::Trace::Util;
+
+my %failed_syscalls;
+
+sub raw_syscalls::sys_exit
+{
+	my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
+	    $common_pid, $common_comm,
+	    $id, $ret) = @_;
+
+	if ($ret < 0) {
+	    $failed_syscalls{$common_comm}++;
+	}
+}
+
+sub trace_end
+{
+    printf("\nfailed syscalls by comm:\n\n");
+
+    printf("%-20s  %10s\n", "comm", "# errors");
+    printf("%-20s  %6s  %10s\n", "--------------------", "----------");
+
+    foreach my $comm (sort {$failed_syscalls{$b} <=> $failed_syscalls{$a}}
+		      keys %failed_syscalls) {
+	    printf("%-20s  %10s\n", $comm, $failed_syscalls{$comm});
+    }
+}
tools/perf/scripts/python/bin/failed-syscalls-by-pid-record new file +2 -0
new file mode 100644
index 0000000..f8885d3
@@ -0,0 +1,2 @@
+#!/bin/bash
+perf record -c 1 -f -a -M -R -e raw_syscalls:sys_exit
tools/perf/scripts/python/bin/failed-syscalls-by-pid-report new file +4 -0
new file mode 100644
index 0000000..1e0c0a8
@@ -0,0 +1,4 @@
+#!/bin/bash
+# description: system-wide failed syscalls, by pid
+# args: [comm]
+perf trace -s ~/libexec/perf-core/scripts/python/failed-syscalls-by-pid.py $1
tools/perf/scripts/python/bin/syscall-counts-by-pid-record new file +2 -0
new file mode 100644
index 0000000..45a8c50
@@ -0,0 +1,2 @@
+#!/bin/bash
+perf record -c 1 -f -a -M -R -e raw_syscalls:sys_enter
tools/perf/scripts/python/bin/syscall-counts-by-pid-report new file +4 -0
new file mode 100644
index 0000000..f8044d1
@@ -0,0 +1,4 @@
+#!/bin/bash
+# description: system-wide syscall counts, by pid
+# args: [comm]
+perf trace -s ~/libexec/perf-core/scripts/python/syscall-counts-by-pid.py $1
tools/perf/scripts/python/bin/syscall-counts-record new file +2 -0
new file mode 100644
index 0000000..45a8c50
@@ -0,0 +1,2 @@
+#!/bin/bash
+perf record -c 1 -f -a -M -R -e raw_syscalls:sys_enter
tools/perf/scripts/python/bin/syscall-counts-report new file +4 -0
new file mode 100644
index 0000000..a366aa6
@@ -0,0 +1,4 @@
+#!/bin/bash
+# description: system-wide syscall counts
+# args: [comm]
+perf trace -s ~/libexec/perf-core/scripts/python/syscall-counts.py $1
tools/perf/scripts/python/check-perf-trace.py new file +83 -0

83 lines not on this page · raw message

tools/perf/scripts/python/failed-syscalls-by-pid.py new file +68 -0

68 lines not on this page · raw message

tools/perf/scripts/python/syscall-counts-by-pid.py new file +64 -0

64 lines not on this page · raw message

tools/perf/scripts/python/syscall-counts.py new file +58 -0

58 lines not on this page · raw message

#19 lore raw

PATCH 8/12 perf: export some syscall metadata

In reply to Tom Zanussi

Create and export a list of syscall_nr:syscall_name pairs from the data in the syscalls_metadata, for use initially by perf trace.

---
 kernel/trace/trace_syscalls.c |   87 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 87 insertions(+), 0 deletions(-)
kernel/trace/trace_syscalls.c +87 -0
index f6b0712..e037486 100644
@@ -626,5 +626,92 @@ void prof_sysexit_disable(struct ftrace_event_call *call)
 	mutex_unlock(&syscall_trace_lock);
 }
 
+struct syscall_metadata **meta_skip(struct syscall_metadata **meta,
+				    loff_t *pos)
+{
+	struct syscall_metadata **end = syscalls_metadata + NR_syscalls;
+
+	do {
+		meta++;
+		(*pos)++;
+	} while (meta < end && *meta == NULL);
+
+	if (meta >= end)
+		meta = NULL;
+
+	return meta;
+}
+
+static void *syscall_map_start(struct seq_file *s, loff_t *pos)
+{
+	struct syscall_metadata **end = syscalls_metadata + NR_syscalls;
+	struct syscall_metadata **meta = syscalls_metadata + *pos;
+
+	if (meta >= end)
+		return NULL;
+
+	if (*meta == NULL)
+		meta = meta_skip(meta, pos);
+
+	return meta;
+}
+
+static void *syscall_map_next(struct seq_file *s, void *v, loff_t *pos)
+{
+	(*pos)++;
+
+	return syscall_map_start(s, pos);
+}
+
+static int syscall_map_show(struct seq_file *s, void *v)
+{
+	const struct syscall_metadata **meta = v;
+	const struct syscall_metadata *m = *meta;
+
+	seq_printf(s, "%d:", m->syscall_nr);
+	seq_printf(s, "%s\n", m->name);
+
+	return 0;
+}
+
+static void syscall_map_stop(struct seq_file *m, void *p)
+{
+}
+
+static const struct seq_operations show_syscall_map_seq_ops = {
+	.start = syscall_map_start,
+	.next = syscall_map_next,
+	.show = syscall_map_show,
+	.stop = syscall_map_stop,
+};
+
+static int syscall_map_open(struct inode *inode, struct file *file)
+{
+	return seq_open(file, &show_syscall_map_seq_ops);
+}
+
+static const struct file_operations syscall_map_fops = {
+	.open = syscall_map_open,
+	.read = seq_read,
+	.llseek = seq_lseek,
+	.release = seq_release,
+};
+
+static __init int init_syscall_map(void)
+{
+	struct dentry *d_tracer;
+
+	d_tracer = tracing_init_dentry();
+	if (!d_tracer)
+		return 0;
+
+	trace_create_file("syscall_map", 0444, d_tracer,
+			  NULL, &syscall_map_fops);
+
+	return 0;
+}
+
+fs_initcall(init_syscall_map);
+
 #endif /* CONFIG_PERF_EVENTS */
 
Signature · 1 line
1.6.4.GIT
#20 lore raw

Re: [PATCH 08/12] perf: export some syscall metadata

Quoted 4 lines · Tom Zanussi

Create and export a list of syscall_nr:syscall_name pairs from the data in the syscalls_metadata, for use initially by perf trace.

I would have much more preferred we inject a kind of "syscall_map" event for that. Unfortunately the event injection is still in discussion and not yet ready.

I guess we can take this temporary solution and remove that later in profit of injected events. It means we'll need to keep support for that file though.

Hmm...

Quoted 104 lines
---
 kernel/trace/trace_syscalls.c |   87 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 87 insertions(+), 0 deletions(-)
kernel/trace/trace_syscalls.c +87 -0
index f6b0712..e037486 100644
@@ -626,5 +626,92 @@ void prof_sysexit_disable(struct ftrace_event_call *call)
 	mutex_unlock(&syscall_trace_lock);
 }
 
+struct syscall_metadata **meta_skip(struct syscall_metadata **meta,
+				    loff_t *pos)
+{
+	struct syscall_metadata **end = syscalls_metadata + NR_syscalls;
+
+	do {
+		meta++;
+		(*pos)++;
+	} while (meta < end && *meta == NULL);
+
+	if (meta >= end)
+		meta = NULL;
+
+	return meta;
+}
+
+static void *syscall_map_start(struct seq_file *s, loff_t *pos)
+{
+	struct syscall_metadata **end = syscalls_metadata + NR_syscalls;
+	struct syscall_metadata **meta = syscalls_metadata + *pos;
+
+	if (meta >= end)
+		return NULL;
+
+	if (*meta == NULL)
+		meta = meta_skip(meta, pos);
+
+	return meta;
+}
+
+static void *syscall_map_next(struct seq_file *s, void *v, loff_t *pos)
+{
+	(*pos)++;
+
+	return syscall_map_start(s, pos);
+}
+
+static int syscall_map_show(struct seq_file *s, void *v)
+{
+	const struct syscall_metadata **meta = v;
+	const struct syscall_metadata *m = *meta;
+
+	seq_printf(s, "%d:", m->syscall_nr);
+	seq_printf(s, "%s\n", m->name);
+
+	return 0;
+}
+
+static void syscall_map_stop(struct seq_file *m, void *p)
+{
+}
+
+static const struct seq_operations show_syscall_map_seq_ops = {
+	.start = syscall_map_start,
+	.next = syscall_map_next,
+	.show = syscall_map_show,
+	.stop = syscall_map_stop,
+};
+
+static int syscall_map_open(struct inode *inode, struct file *file)
+{
+	return seq_open(file, &show_syscall_map_seq_ops);
+}
+
+static const struct file_operations syscall_map_fops = {
+	.open = syscall_map_open,
+	.read = seq_read,
+	.llseek = seq_lseek,
+	.release = seq_release,
+};
+
+static __init int init_syscall_map(void)
+{
+	struct dentry *d_tracer;
+
+	d_tracer = tracing_init_dentry();
+	if (!d_tracer)
+		return 0;
+
+	trace_create_file("syscall_map", 0444, d_tracer,
+			  NULL, &syscall_map_fops);
+
+	return 0;
+}
+
+fs_initcall(init_syscall_map);
+
 #endif /* CONFIG_PERF_EVENTS */
 
Signature · 1 line
1.6.4.GIT
#21 lore raw

Re: [PATCH 08/12] perf: export some syscall metadata

Quoted 13 lines · Frederic Weisbecker
Quoted 4 lines · Tom Zanussi

Create and export a list of syscall_nr:syscall_name pairs from the data in the syscalls_metadata, for use initially by perf trace.

I would have much more preferred we inject a kind of "syscall_map" event for that. Unfortunately the event injection is still in discussion and not yet ready.

Quoted 7 lines

I guess we can take this temporary solution and remove that later in profit of injected events. It means we'll need to keep support for that file though.

Hmm...

You can skip the syscall metadata patches (7-11) and things will still work - you'll just get syscall numbers in the output instead of the nicer syscall names.

When the event injection stuff is ready, I can re-implement those patches on top of it - it shouldn't be a big deal.

Re event injection - I don't know that much about it, but if it can be used for this, could it also be applied to the rest of the trace and header data too? If so, that would enable 'live mode' tracing. I already have a working prototype that does it by converting all those things into synthesized pseudo-events, but it would be nicer to use the event injection framework instead, if I understand it correctly...

Tom

Quoted 107 lines
Quoted 106 lines

---
 kernel/trace/trace_syscalls.c |   87 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 87 insertions(+), 0 deletions(-)
kernel/trace/trace_syscalls.c +87 -0
index f6b0712..e037486 100644
@@ -626,5 +626,92 @@ void prof_sysexit_disable(struct ftrace_event_call *call)
 	mutex_unlock(&syscall_trace_lock);
 }
 
+struct syscall_metadata **meta_skip(struct syscall_metadata **meta,
+				    loff_t *pos)
+{
+	struct syscall_metadata **end = syscalls_metadata + NR_syscalls;
+
+	do {
+		meta++;
+		(*pos)++;
+	} while (meta < end && *meta == NULL);
+
+	if (meta >= end)
+		meta = NULL;
+
+	return meta;
+}
+
+static void *syscall_map_start(struct seq_file *s, loff_t *pos)
+{
+	struct syscall_metadata **end = syscalls_metadata + NR_syscalls;
+	struct syscall_metadata **meta = syscalls_metadata + *pos;
+
+	if (meta >= end)
+		return NULL;
+
+	if (*meta == NULL)
+		meta = meta_skip(meta, pos);
+
+	return meta;
+}
+
+static void *syscall_map_next(struct seq_file *s, void *v, loff_t *pos)
+{
+	(*pos)++;
+
+	return syscall_map_start(s, pos);
+}
+
+static int syscall_map_show(struct seq_file *s, void *v)
+{
+	const struct syscall_metadata **meta = v;
+	const struct syscall_metadata *m = *meta;
+
+	seq_printf(s, "%d:", m->syscall_nr);
+	seq_printf(s, "%s\n", m->name);
+
+	return 0;
+}
+
+static void syscall_map_stop(struct seq_file *m, void *p)
+{
+}
+
+static const struct seq_operations show_syscall_map_seq_ops = {
+	.start = syscall_map_start,
+	.next = syscall_map_next,
+	.show = syscall_map_show,
+	.stop = syscall_map_stop,
+};
+
+static int syscall_map_open(struct inode *inode, struct file *file)
+{
+	return seq_open(file, &show_syscall_map_seq_ops);
+}
+
+static const struct file_operations syscall_map_fops = {
+	.open = syscall_map_open,
+	.read = seq_read,
+	.llseek = seq_lseek,
+	.release = seq_release,
+};
+
+static __init int init_syscall_map(void)
+{
+	struct dentry *d_tracer;
+
+	d_tracer = tracing_init_dentry();
+	if (!d_tracer)
+		return 0;
+
+	trace_create_file("syscall_map", 0444, d_tracer,
+			  NULL, &syscall_map_fops);
+
+	return 0;
+}
+
+fs_initcall(init_syscall_map);
+
 #endif /* CONFIG_PERF_EVENTS */
 
Signature · 1 line
1.6.4.GIT
#22 lore raw

Re: [PATCH 08/12] perf: export some syscall metadata

Quoted 6 lines · Tom Zanussi

You can skip the syscall metadata patches (7-11) and things will still work - you'll just get syscall numbers in the output instead of the nicer syscall names.

When the event injection stuff is ready, I can re-implement those patches on top of it - it shouldn't be a big deal.

Yeah, this looks more reasonable I think. The 7th patch can still go on though, as it deals with syscall numbers, not yet names, so it's fine.

Ah and I'm keeping the 12th patch too (documentation) with some few modifications, just to tell people syscall names are not yet supported.

I've tested the set and played with it. It works very well.

Actually this work is just amazing. It's so easy to generate a script for any perf.data, with the right things inside, easy to modify as the callbacks are intuitive.

I'm pushing that right away so happily...

#23 lore raw

Re: [PATCH 08/12] perf: export some syscall metadata

Quoted 17 lines · Frederic Weisbecker
Quoted 6 lines · Tom Zanussi

You can skip the syscall metadata patches (7-11) and things will still work - you'll just get syscall numbers in the output instead of the nicer syscall names.

When the event injection stuff is ready, I can re-implement those patches on top of it - it shouldn't be a big deal.

Yeah, this looks more reasonable I think. The 7th patch can still go on though, as it deals with syscall numbers, not yet names, so it's fine.

Ah and I'm keeping the 12th patch too (documentation) with some few modifications, just to tell people syscall names are not yet supported.

Quoted 8 lines

I've tested the set and played with it. It works very well.

Actually this work is just amazing. It's so easy to generate a script for any perf.data, with the right things inside, easy to modify as the callbacks are intuitive.

I'm pushing that right away so happily...

Great! Thanks for reviewing and pushing it all.

Tom

#24 lore raw

Re: [PATCH 08/12] perf: export some syscall metadata

In reply to Tom Zanussi
Quoted 6 lines · Tom Zanussi

Re event injection - I don't know that much about it, but if it can be used for this, could it also be applied to the rest of the trace and header data too? If so, that would enable 'live mode' tracing. I already have a working prototype that does it by converting all those things into synthesized pseudo-events, but it would be nicer to use the event injection framework instead, if I understand it correctly...

I'm not sure what you mean about live mode tracing. But yeah this about synthetizing pseudo-events. The purpose is to catchup with "past events" or "dead events".

The first trial was for lock_init events. Lock init events send the address of the lock plus its name, so that subsequent lock events (lock acquire, lock_release) can just send the address in the event and not the name which can then be retrieved from past lock_init events.

One problem though: when we enable the lock_init event, we only catch the new locks created. So we need the previously registered locks. There may be severals ways to do that: using a perf ioctl or so, it's still in discussion.

But then for syscalls we would have a kind of dead events catching up by asking the kernel to send us the nr:name pairs.

#25 lore raw

Re: [PATCH 08/12] perf: export some syscall metadata

Quoted 19 lines · Frederic Weisbecker
Quoted 6 lines · Tom Zanussi

Re event injection - I don't know that much about it, but if it can be used for this, could it also be applied to the rest of the trace and header data too? If so, that would enable 'live mode' tracing. I already have a working prototype that does it by converting all those things into synthesized pseudo-events, but it would be nicer to use the event injection framework instead, if I understand it correctly...

I'm not sure what you mean about live mode tracing. But yeah this about synthetizing pseudo-events. The purpose is to catchup with "past events" or "dead events".

The first trial was for lock_init events. Lock init events send the address of the lock plus its name, so that subsequent lock events (lock acquire, lock_release) can just send the address in the event and not the name which can then be retrieved from past lock_init events.

Quoted 9 lines

One problem though: when we enable the lock_init event, we only catch the new locks created. So we need the previously registered locks. There may be severals ways to do that: using a perf ioctl or so, it's still in discussion.

But then for syscalls we would have a kind of dead events catching up by asking the kernel to send us the nr:name pairs.

By 'live mode' tracing, I mean feeding the trace stream continuously to the script rather than writing it to disk and then later running the script on the file data. Basically something like this:

$ perf record -e event1 -e event2 -o - | perf trace -s myscript.py -i -

where the output of perf record is streamed to stdout and piped to the the script, which continuously reads and processes events from stdin, until the user hits ctrl-c or the script detects some arbitrary pattern or condition in the trace stream and stops and prints out the results.

This would allow a whole new class of use cases e.g. you could easily convert any of the current scripts into 'top' versions by adding a timer that would display and clear the current results on each tick, say every 5 seconds. Or just actively scan the trace data for some arbitrarily complex condition, while also saving the last n trace records and dumping them when the condition is found, etc...

The main obstacle to doing this with the current perf is the header data, which in my prototype I've converted into 4 pseudo events - attrs, event_types, tracing_data and build_ids, basically getting rid of everything than uses a seek, so I can shove it all over a pipe.

It does seem to me that event injection could be used for this instead e.g. similar to the case of lock_init/subsequent lock events, for the script to be able to process an event it needs the event information contained in the trace_data, which could be sent as an injected event, for that subsequent event. My prototype just sends it all as one huge event right now, but if it were broken down into individual events, that would also allow new events to be added and removed dynamically. So in addition to 'live mode' we could add 'dynamic' mode as well. :-)

So yeah, it looks like it would be useful for the syscall names, but hopefully much more than that...

#26 lore raw

Re: [PATCH 08/12] perf: export some syscall metadata

Quoted 62 lines · Tom Zanussi
Quoted 19 lines · Frederic Weisbecker
Quoted 6 lines · Tom Zanussi

Re event injection - I don't know that much about it, but if it can be used for this, could it also be applied to the rest of the trace and header data too? If so, that would enable 'live mode' tracing. I already have a working prototype that does it by converting all those things into synthesized pseudo-events, but it would be nicer to use the event injection framework instead, if I understand it correctly...

I'm not sure what you mean about live mode tracing. But yeah this about synthetizing pseudo-events. The purpose is to catchup with "past events" or "dead events".

The first trial was for lock_init events. Lock init events send the address of the lock plus its name, so that subsequent lock events (lock acquire, lock_release) can just send the address in the event and not the name which can then be retrieved from past lock_init events.

Quoted 9 lines

One problem though: when we enable the lock_init event, we only catch the new locks created. So we need the previously registered locks. There may be severals ways to do that: using a perf ioctl or so, it's still in discussion.

But then for syscalls we would have a kind of dead events catching up by asking the kernel to send us the nr:name pairs.

By 'live mode' tracing, I mean feeding the trace stream continuously to the script rather than writing it to disk and then later running the script on the file data. Basically something like this:

$ perf record -e event1 -e event2 -o - | perf trace -s myscript.py -i -

where the output of perf record is streamed to stdout and piped to the the script, which continuously reads and processes events from stdin, until the user hits ctrl-c or the script detects some arbitrary pattern or condition in the trace stream and stops and prints out the results.

This would allow a whole new class of use cases e.g. you could easily convert any of the current scripts into 'top' versions by adding a timer that would display and clear the current results on each tick, say every 5 seconds. Or just actively scan the trace data for some arbitrarily complex condition, while also saving the last n trace records and dumping them when the condition is found, etc...

The main obstacle to doing this with the current perf is the header data, which in my prototype I've converted into 4 pseudo events - attrs, event_types, tracing_data and build_ids, basically getting rid of everything than uses a seek, so I can shove it all over a pipe.

It does seem to me that event injection could be used for this instead e.g. similar to the case of lock_init/subsequent lock events, for the script to be able to process an event it needs the event information contained in the trace_data, which could be sent as an injected event, for that subsequent event. My prototype just sends it all as one huge event right now, but if it were broken down into individual events, that would also allow new events to be added and removed dynamically. So in addition to 'live mode' we could add 'dynamic' mode as well. :-)

Quoted 2 lines

So yeah, it looks like it would be useful for the syscall names, but hopefully much more than that...

Ok, I see what you mean by live mode now.
But I don't understand why you'd need the injection for that. If you start a recording, even if it is launched in live mode, you can parse the necessary format information before, right?

#27 lore raw

Re: [PATCH 08/12] perf: export some syscall metadata

Quoted 63 lines · Frederic Weisbecker
Quoted 62 lines · Tom Zanussi
Quoted 19 lines · Frederic Weisbecker
Quoted 6 lines · Tom Zanussi

Re event injection - I don't know that much about it, but if it can be used for this, could it also be applied to the rest of the trace and header data too? If so, that would enable 'live mode' tracing. I already have a working prototype that does it by converting all those things into synthesized pseudo-events, but it would be nicer to use the event injection framework instead, if I understand it correctly...

I'm not sure what you mean about live mode tracing. But yeah this about synthetizing pseudo-events. The purpose is to catchup with "past events" or "dead events".

The first trial was for lock_init events. Lock init events send the address of the lock plus its name, so that subsequent lock events (lock acquire, lock_release) can just send the address in the event and not the name which can then be retrieved from past lock_init events.

Quoted 9 lines

One problem though: when we enable the lock_init event, we only catch the new locks created. So we need the previously registered locks. There may be severals ways to do that: using a perf ioctl or so, it's still in discussion.

But then for syscalls we would have a kind of dead events catching up by asking the kernel to send us the nr:name pairs.

By 'live mode' tracing, I mean feeding the trace stream continuously to the script rather than writing it to disk and then later running the script on the file data. Basically something like this:

$ perf record -e event1 -e event2 -o - | perf trace -s myscript.py -i -

where the output of perf record is streamed to stdout and piped to the the script, which continuously reads and processes events from stdin, until the user hits ctrl-c or the script detects some arbitrary pattern or condition in the trace stream and stops and prints out the results.

This would allow a whole new class of use cases e.g. you could easily convert any of the current scripts into 'top' versions by adding a timer that would display and clear the current results on each tick, say every 5 seconds. Or just actively scan the trace data for some arbitrarily complex condition, while also saving the last n trace records and dumping them when the condition is found, etc...

The main obstacle to doing this with the current perf is the header data, which in my prototype I've converted into 4 pseudo events - attrs, event_types, tracing_data and build_ids, basically getting rid of everything than uses a seek, so I can shove it all over a pipe.

It does seem to me that event injection could be used for this instead e.g. similar to the case of lock_init/subsequent lock events, for the script to be able to process an event it needs the event information contained in the trace_data, which could be sent as an injected event, for that subsequent event. My prototype just sends it all as one huge event right now, but if it were broken down into individual events, that would also allow new events to be added and removed dynamically. So in addition to 'live mode' we could add 'dynamic' mode as well. :-)

Quoted 9 lines
Quoted 2 lines

So yeah, it looks like it would be useful for the syscall names, but hopefully much more than that...

Ok, I see what you mean by live mode now.
But I don't understand why you'd need the injection for that. If you start a recording, even if it is launched in live mode, you can parse the necessary format information before, right?

I was thinking about being able to add new events at any point in time, not just at the beginning of the trace. Injecting individual event descriptions at any point in time would allow interactive toggling of specific events or event classes. Also, if you're doing that over the network, you'd need to package them up in some sendable form anyway, why not as an injected event...

Tom

#28 lore raw

PATCH 9/12 perf tools: save syscall map

In reply to Tom Zanussi

Read the exported syscall metadata and save it in the trace file for post-processing tools.

---
 tools/perf/util/trace-event-info.c  |   25 ++++++++++++++
 tools/perf/util/trace-event-parse.c |   63 +++++++++++++++++++++++++++++++++++
 tools/perf/util/trace-event-read.c  |   18 ++++++++++
 tools/perf/util/trace-event.h       |   10 +++++
 4 files changed, 116 insertions(+), 0 deletions(-)
tools/perf/util/trace-event-info.c +25 -0
index 5ea8973..6a6e5cc 100644
@@ -461,6 +461,30 @@ out:
 	put_tracing_file(path);
 }
 
+static void read_syscall_map(void)
+{
+	unsigned int size, check_size;
+	char *path;
+	struct stat st;
+	int ret;
+
+	path = get_tracing_file("syscall_map");
+	ret = stat(path, &st);
+	if (ret < 0) {
+		/* not found */
+		size = 0;
+		write_or_die(&size, 4);
+		goto out;
+	}
+	size = get_size(path);
+	write_or_die(&size, 4);
+	check_size = copy_file(path);
+	if (size != check_size)
+		die("error in size of file '%s'", path);
+out:
+	put_tracing_file(path);
+}
+
 static struct tracepoint_path *
 get_tracepoints_path(struct perf_event_attr *pattrs, int nb_events)
 {
@@ -523,6 +547,7 @@ int read_tracing_data(int fd, struct perf_event_attr *pattrs, int nb_events)
 	read_event_files(tps);
 	read_proc_kallsyms();
 	read_ftrace_printk();
+	read_syscall_map();
 
 	return 0;
 }
tools/perf/util/trace-event-parse.c +63 -0

69 lines not on this page · raw message

tools/perf/util/trace-event-read.c +18 -0
index 1744422..70fcaec 100644
@@ -171,6 +171,23 @@ static void read_ftrace_printk(void)
 	free(buf);
 }
 
+static void read_syscall_map(void)
+{
+	unsigned int size;
+	char *buf;
+
+	size = read4();
+	if (!size)
+		return;
+
+	buf = malloc_or_die(size);
+	read_or_die(buf, size);
+
+	parse_syscall_map(buf, size);
+
+	free(buf);
+}
+
 static void read_header_files(void)
 {
 	unsigned long long size;
@@ -498,6 +515,7 @@ void trace_report(int fd)
 	read_event_files();
 	read_proc_kallsyms();
 	read_ftrace_printk();
+	read_syscall_map();
 
 	if (show_funcs) {
 		print_funcs();
tools/perf/util/trace-event.h +10 -0
index c3269b9..5313ad8 100644
@@ -178,6 +178,16 @@ int parse_event_file(char *buf, unsigned long size, char *sys);
 void print_event(int cpu, void *data, int size, unsigned long long nsecs,
 		  char *comm);
 
+struct syscall_metadata {
+	char *name;
+	int nr;
+};
+
+void parse_syscall_map(char *file, int size);
+int nr_syscalls(void);
+const struct syscall_metadata *syscall_at_idx(int idx);
+const struct syscall_metadata *find_syscall(int syscall_nr);
+
 extern int file_bigendian;
 extern int host_bigendian;
 
Signature · 1 line
1.6.4.GIT
#29 lore raw

PATCH 10/12 perf trace/scripting: make the syscall map available as a Python dict

In reply to Tom Zanussi

Create a Python extension that makes the perf syscall map into a Python dict.

New instances of the syscall dict can be retrieved at any time by by calling the Python function get_syscall_names().

Also adds a new utility function that makes uses of the syscall name dict:

syscall_name(syscall_nr)

which returns a syscall name given a syscall_nr, or the number itself if the syscall wasn't found in the map (or 'undefined' if the value passed in was bogus).

---
 .../perf/scripts/python/Perf-Trace-Util/Context.c  |   22 ++++++++++++++++++++
 .../python/Perf-Trace-Util/lib/Perf/Trace/Util.py  |   12 ++++++++++
 .../perf/scripts/python/failed-syscalls-by-pid.py  |    3 +-
 tools/perf/scripts/python/syscall-counts-by-pid.py |    3 +-
 tools/perf/scripts/python/syscall-counts.py        |    3 +-
 5 files changed, 40 insertions(+), 3 deletions(-)
tools/perf/scripts/python/Perf-Trace-Util/Context.c +22 -0
index 957085d..ebdcc35 100644
@@ -72,6 +72,26 @@ static PyObject *perf_trace_context_common_lock_depth(PyObject *self,
 	return Py_BuildValue("i", retval);
 }
 
+static PyObject *perf_trace_context_get_syscall_names(PyObject *self,
+						      PyObject *args)
+{
+	const struct syscall_metadata *meta;
+	PyObject *dict;
+	int i;
+
+	dict = PyDict_New();
+	if (!dict)
+		return NULL;
+
+	for (i = 0; i < nr_syscalls(); i++) {
+		meta = syscall_at_idx(i);
+		PyDict_SetItem(dict, PyInt_FromLong(meta->nr),
+			       PyString_FromString(meta->name));
+	}
+
+	return dict;
+}
+
 static PyMethodDef ContextMethods[] = {
 	{ "common_pc", perf_trace_context_common_pc, METH_VARARGS,
 	  "Get the common preempt count event field value."},
@@ -79,6 +99,8 @@ static PyMethodDef ContextMethods[] = {
 	  "Get the common flags event field value."},
 	{ "common_lock_depth", perf_trace_context_common_lock_depth,
 	  METH_VARARGS,	"Get the common lock depth event field value."},
+	{ "get_syscall_names", perf_trace_context_get_syscall_names,
+	  METH_NOARGS,	"Get the syscall_nr->syscall_name dict."},
 	{ NULL, NULL, 0, NULL}
 };
 
tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py +12 -0
index 83e9143..08d7d8e 100644
@@ -6,6 +6,8 @@
 # Public License ("GPL") version 2 as published by the Free Software
 # Foundation.
 
+from perf_trace_context import *
+
 NSECS_PER_SEC    = 1000000000
 
 def avg(total, n):
@@ -23,3 +25,13 @@ def nsecs_nsecs(nsecs):
 def nsecs_str(nsecs):
     str = "%5u.%09u" % (nsecs_secs(nsecs), nsecs_nsecs(nsecs)),
     return str
+
+syscall_name_map = get_syscall_names()
+
+def syscall_name(id):
+	if id == -1:
+		return "undefined"
+	try:
+		return syscall_name_map[id]
+	except KeyError:
+		return str(id)
tools/perf/scripts/python/failed-syscalls-by-pid.py +2 -1
index 0ca0227..007e959 100644
@@ -13,6 +13,7 @@ sys.path.append(os.environ['PERF_EXEC_PATH'] + \
 
 from perf_trace_context import *
 from Core import *
+from Util import *
 
 usage = "perf trace -s syscall-counts-by-pid.py [comm]\n";
 
@@ -62,7 +63,7 @@ def print_error_totals():
 		    print "\n%s [%d]\n" % (comm, pid),
 		    id_keys = syscalls[comm][pid].keys()
 		    for id in id_keys:
-			    print "  syscall: %-16d\n" % (id),
+			    print "  syscall: %-16s\n" % (syscall_name(id)),
 			    ret_keys = syscalls[comm][pid][id].keys()
 			    for ret, val in sorted(syscalls[comm][pid][id].iteritems(), key = lambda(k, v): (v, k),  reverse = True):
 				    print "    err = %-20d  %10d\n" % (ret, val),
tools/perf/scripts/python/syscall-counts-by-pid.py +2 -1
index af722d6..fffe0d6 100644
@@ -13,6 +13,7 @@ sys.path.append(os.environ['PERF_EXEC_PATH'] + \
 
 from perf_trace_context import *
 from Core import *
+from Util import *
 
 usage = "perf trace -s syscall-counts-by-pid.py [comm]\n";
 
@@ -61,4 +62,4 @@ def print_syscall_totals():
 		    id_keys = syscalls[comm][pid].keys()
 		    for id, val in sorted(syscalls[comm][pid].iteritems(), \
 				  key = lambda(k, v): (v, k),  reverse = True):
-			    print "  %-38d  %10d\n" % (id, val),
+			    print "  %-38s  %10d\n" % (syscall_name(id), val),
tools/perf/scripts/python/syscall-counts.py +2 -1
index f977e85..a641c6f 100644
@@ -13,6 +13,7 @@ sys.path.append(os.environ['PERF_EXEC_PATH'] + \
 
 from perf_trace_context import *
 from Core import *
+from Util import *
 
 usage = "perf trace -s syscall-counts.py [comm]\n";
 
@@ -55,4 +56,4 @@ def print_syscall_totals():
 
     for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \
 				  reverse = True):
-	    print "%-40d  %10d\n" % (id, val),
+	    print "%-40s  %10d\n" % (syscall_name(id), val),
Signature · 1 line
1.6.4.GIT
#30 lore raw

PATCH 11/12 perf trace/scripting: make the syscall map available as a Perl hash

In reply to Tom Zanussi

Create a Perl extension that makes the perf syscall map into a Perl hash.

New instances of the syscall hash can be retrieved at any time by by calling the Perl function get_syscall_names(). This is a hash reference, so use hash reference syntax to access its contents.

Also adds a new utility function that makes uses of the syscall name dict:

syscall_name($syscall_nr);

which returns a syscall name given a syscall_nr, or the number itself if the syscall wasn't found in the map (or 'undefined' if the value passed in was bogus).

---
 tools/perf/scripts/perl/Perf-Trace-Util/Context.c  |   46 +++++++++++++++++++-
 tools/perf/scripts/perl/Perf-Trace-Util/Context.xs |   24 ++++++++++
 .../perl/Perf-Trace-Util/lib/Perf/Trace/Context.pm |    2 +-
 .../perl/Perf-Trace-Util/lib/Perf/Trace/Util.pm    |   22 +++++++++-
 tools/perf/scripts/perl/failed-syscalls.pl         |   15 ++++++-
 5 files changed, 105 insertions(+), 4 deletions(-)
tools/perf/scripts/perl/Perf-Trace-Util/Context.c +45 -1
index 01a64ad..ae2279d 100644
@@ -34,11 +34,32 @@
 #include "../../../perf.h"
 #include "../../../util/trace-event.h"
 
+static HV *get_syscall_names(void)
+{
+	const struct syscall_metadata *meta;
+	char buf[8];
+	HV *hash;
+	int i;
+
+	hash = (HV *)sv_2mortal((SV *)newHV());
+	if (!hash)
+		return NULL;
+
+	for (i = 0; i < nr_syscalls(); i++) {
+		meta  = syscall_at_idx(i);
+		sprintf(buf, "%d", meta->nr);
+		(void) hv_store(hash, buf, strlen(buf),
+		       newSVpv(meta->name, 0), 0);
+	}
+
+	return hash;
+}
+
 #ifndef PERL_UNUSED_VAR
 #  define PERL_UNUSED_VAR(var) if (0) var = var
 #endif
 
-#line 42 "Context.c"
+#line 63 "Context.c"
 
 XS(XS_Perf__Trace__Context_common_pc); /* prototype to pass -Wmissing-prototypes */
 XS(XS_Perf__Trace__Context_common_pc)
@@ -108,6 +129,28 @@ XS(XS_Perf__Trace__Context_common_lock_depth)
     XSRETURN(1);
 }
 
+
+XS(XS_Perf__Trace__Context_get_syscall_names); /* prototype to pass -Wmissing-prototypes */
+XS(XS_Perf__Trace__Context_get_syscall_names)
+{
+#ifdef dVAR
+    dVAR; dXSARGS;
+#else
+    dXSARGS;
+#endif
+    if (items != 0)
+       Perl_croak(aTHX_ "Usage: %s(%s)", "Perf::Trace::Context::get_syscall_names", "");
+    PERL_UNUSED_VAR(cv); /* -W */
+    {
+	HV *	RETVAL;
+
+	RETVAL = get_syscall_names();
+	ST(0) = newRV((SV*)RETVAL);
+	sv_2mortal(ST(0));
+    }
+    XSRETURN(1);
+}
+
 #ifdef __cplusplus
 extern "C"
 #endif
@@ -128,6 +171,7 @@ XS(boot_Perf__Trace__Context)
         newXSproto("Perf::Trace::Context::common_pc", XS_Perf__Trace__Context_common_pc, file, "$");
         newXSproto("Perf::Trace::Context::common_flags", XS_Perf__Trace__Context_common_flags, file, "$");
         newXSproto("Perf::Trace::Context::common_lock_depth", XS_Perf__Trace__Context_common_lock_depth, file, "$");
+        newXSproto("Perf::Trace::Context::get_syscall_names", XS_Perf__Trace__Context_get_syscall_names, file, "");
     if (PL_unitcheckav)
          call_list(PL_scopestack_ix, PL_unitcheckav);
     XSRETURN_YES;
tools/perf/scripts/perl/Perf-Trace-Util/Context.xs +24 -0
index 549cf04..d016473 100644
@@ -25,6 +25,27 @@
 #include "../../../perf.h"
 #include "../../../util/trace-event.h"
 
+static HV *get_syscall_names(void)
+{
+	const struct syscall_metadata *meta;
+	char buf[8];
+	HV *hash;
+	int i;
+
+	hash = (HV *)sv_2mortal((SV *)newHV());
+	if (!hash)
+		return NULL;
+
+	for (i = 0; i < nr_syscalls(); i++) {
+		meta  = syscall_at_idx(i);
+		sprintf(buf, "%d", meta->nr);
+		(void) hv_store(hash, buf, strlen(buf),
+		       newSVpv(meta->name, 0), 0);
+	}
+
+	return hash;
+}
+
 MODULE = Perf::Trace::Context		PACKAGE = Perf::Trace::Context
 PROTOTYPES: ENABLE
 
@@ -40,3 +61,6 @@ int
 common_lock_depth(context)
 	struct scripting_context * context
 
+HV *
+get_syscall_names()
+
tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Context.pm +1 -1
index 6c7f365..dc2231e 100644
@@ -14,7 +14,7 @@ our %EXPORT_TAGS = ( 'all' => [ qw(
 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
 
 our @EXPORT = qw(
-	common_pc common_flags common_lock_depth
+	common_pc common_flags common_lock_depth get_syscall_names
 );
 
 our $VERSION = '0.01';
tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Util.pm +21 -1
index f869c48..d62314b 100644
@@ -4,6 +4,9 @@ use 5.010000;
 use strict;
 use warnings;
 
+use Perf::Trace::Core;
+use Perf::Trace::Context;
+
 require Exporter;
 
 our @ISA = qw(Exporter);
@@ -14,7 +17,7 @@ our %EXPORT_TAGS = ( 'all' => [ qw(
 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
 
 our @EXPORT = qw(
-avg nsecs nsecs_secs nsecs_nsecs nsecs_usecs print_nsecs
+avg nsecs nsecs_secs nsecs_nsecs nsecs_usecs print_nsecs syscall_name
 );
 
 our $VERSION = '0.01';
@@ -55,6 +58,23 @@ sub nsecs_str {
     return $str;
 }
 
+my $syscall_name_map = get_syscall_names();
+
+sub syscall_name
+{
+	my ($id) = @_;
+
+	if ($id == -1) {
+	    return "undefined"
+	}
+
+	if ($syscall_name_map->{$id}) {
+	    return $syscall_name_map->{$id};
+	} else {
+	    return $id;
+	}
+}
+
 1;
 __END__
 =head1 NAME
tools/perf/scripts/perl/failed-syscalls.pl +14 -1
index c18e7e2..eeaaa28 100644
@@ -12,6 +12,7 @@ use Perf::Trace::Context;
 use Perf::Trace::Util;
 
 my %failed_syscalls;
+my %failed_syscall_ids;
 
 sub raw_syscalls::sys_exit
 {
@@ -21,12 +22,13 @@ sub raw_syscalls::sys_exit
 
 	if ($ret < 0) {
 	    $failed_syscalls{$common_comm}++;
+	    $failed_syscall_ids{$id}++;
 	}
 }
 
 sub trace_end
 {
-    printf("\nfailed syscalls by comm:\n\n");
+    printf("\nfailed syscalls, by comm:\n\n");
 
     printf("%-20s  %10s\n", "comm", "# errors");
     printf("%-20s  %6s  %10s\n", "--------------------", "----------");
@@ -35,4 +37,15 @@ sub trace_end
 		      keys %failed_syscalls) {
 	    printf("%-20s  %10s\n", $comm, $failed_syscalls{$comm});
     }
+
+    printf("\n\nfailed syscalls, by syscall:\n\n");
+
+    printf("%-30s  %10s\n", "syscall", "# errors");
+    printf("%-30s  %6s  %10s\n", "------------------------------",
+	   "----------");
+
+    foreach my $id (sort {$failed_syscall_ids{$b} <=> $failed_syscall_ids{$a}}
+		    keys %failed_syscall_ids) {
+	printf("%-30s  %10d\n", syscall_name($id), $failed_syscall_ids{$id});
+    }
 }
Signature · 1 line
1.6.4.GIT
#31 lore raw

PATCH 12/12 perf trace/scripting: add perf-trace-python Documentation

In reply to Tom Zanussi

Also small update to perf-trace-perl and perf-trace docs.

---
 tools/perf/Documentation/perf-trace-perl.txt   |    3 +-
 tools/perf/Documentation/perf-trace-python.txt |  624 ++++++++++++++++++++++++
 tools/perf/Documentation/perf-trace.txt        |   11 +-
 3 files changed, 636 insertions(+), 2 deletions(-)
 create mode 100644 tools/perf/Documentation/perf-trace-python.txt
tools/perf/Documentation/perf-trace-perl.txt +2 -1
index c5f55f4..d2206c3 100644
@@ -8,7 +8,7 @@ perf-trace-perl - Process trace data with a Perl script
 SYNOPSIS
 --------
 [verse]
-'perf trace' [-s [lang]:script[.ext] ]
+'perf trace' [-s [Perl]:script[.pl] ]
 
 DESCRIPTION
 -----------
@@ -213,6 +213,7 @@ Various utility functions for use with perf trace:
   nsecs_nsecs($nsecs) - returns nsecs remainder given nsecs
   nsecs_str($nsecs) - returns printable string in the form secs.nsecs
   avg($total, $n) - returns average given a sum and a total number of values
+  syscall_name($id) - returns the syscall name for the specified syscall_nr
 
 SEE ALSO
 --------
tools/perf/Documentation/perf-trace-python.txt new file +624 -0

624 lines not on this page · raw message

tools/perf/Documentation/perf-trace.txt +10 -1
index c00a76f..8879299 100644
@@ -19,6 +19,11 @@ There are several variants of perf trace:
   'perf trace' to see a detailed trace of the workload that was
   recorded.
 
+  You can also run a set of pre-canned scripts that aggregate and
+  summarize the raw trace data in various ways (the list of scripts is
+  available via 'perf trace -l').  The following variants allow you to
+  record and run those scripts:
+
   'perf trace record <script>' to record the events required for 'perf
   trace report'.  <script> is the name displayed in the output of
   'perf trace --list' i.e. the actual script name minus any language
@@ -31,6 +36,9 @@ There are several variants of perf trace:
   record <script>' is used and should be present for this command to
   succeed.
 
+  See the 'SEE ALSO' section for links to language-specific
+  information on how to write and run your own trace scripts.
+
 OPTIONS
 -------
 -D::
@@ -58,4 +66,5 @@ OPTIONS
 
 SEE ALSO
 --------
-linkperf:perf-record[1], linkperf:perf-trace-perl[1]
+linkperf:perf-record[1], linkperf:perf-trace-perl[1],
+linkperf:perf-trace-python[1]
Signature · 1 line
1.6.4.GIT
#32 lore raw

Re: [PATCH 12/12] perf trace/scripting: add perf-trace-python Documentation

Quoted 28 lines · Tom Zanussi
tools/perf/Documentation/perf-trace-python.txt new file +28 -0
+from perf_trace_context import *
+from Core import *
+
+def trace_end():
+	print "in trace_end"
+
+def raw_syscalls__sys_enter(event_name, context, common_cpu,
+	common_secs, common_nsecs, common_pid, common_comm,
+	id, args):
+----
+
+In trace_end(), we'll simply print the results, but first we need to
+generate some results to print.  To do that we need to have our
+sys_enter() handler do the necessary tallying until all events have
+been counted.  A hash table indexed by syscall id is a good way to
+store that information; every time the sys_enter() handler is called,
+we simply increment a count associated with that hash entry indexed by
+that syscall id:
+
+----
+  syscalls = autodict()
+
+  try:
+    syscalls[id] += 1
+  except TypeError:
+    syscalls[id] = 1
+----
+

tools/perf/Documentation/perf-trace-python.txt line 257

Quoted 10 lines
tools/perf/Documentation/perf-trace-python.txt new file +10 -0
+The syscalls 'autodict' object is a special kind of Python dictionary
+(implemented in Core.py) that implements Perl's 'autovivifying' hashes
+in Python i.e. with autovivifying hashes, you can assign nested hash
+values without having to go to the trouble of creating intermediate
+levels if they don't exist e.g syscalls[comm][pid][id] = 1 will create
+the intermediate hash levels and finally assign the value 1 to the
+hash entry for 'id' (because the value being assigned isn't a hash
+object itself, the initial value is assigned in the TypeError
+exception.  Well, there may be a better way to do this in Python but
+that's what works for now).

That's smart. I wish python had a native type for that.

And looking how you made it easily....

def autodict():
return defaultdict(autodict)

#33 lore raw

Re: [PATCH 12/12] perf trace/scripting: add perf-trace-python Documentation

Quoted 43 lines · Frederic Weisbecker
Quoted 28 lines · Tom Zanussi
tools/perf/Documentation/perf-trace-python.txt new file +28 -0
+from perf_trace_context import *
+from Core import *
+
+def trace_end():
+	print "in trace_end"
+
+def raw_syscalls__sys_enter(event_name, context, common_cpu,
+	common_secs, common_nsecs, common_pid, common_comm,
+	id, args):
+----
+
+In trace_end(), we'll simply print the results, but first we need to
+generate some results to print.  To do that we need to have our
+sys_enter() handler do the necessary tallying until all events have
+been counted.  A hash table indexed by syscall id is a good way to
+store that information; every time the sys_enter() handler is called,
+we simply increment a count associated with that hash entry indexed by
+that syscall id:
+
+----
+  syscalls = autodict()
+
+  try:
+    syscalls[id] += 1
+  except TypeError:
+    syscalls[id] = 1
+----
+

tools/perf/Documentation/perf-trace-python.txt line 257

Quoted 10 lines
tools/perf/Documentation/perf-trace-python.txt new file +10 -0
+The syscalls 'autodict' object is a special kind of Python dictionary
+(implemented in Core.py) that implements Perl's 'autovivifying' hashes
+in Python i.e. with autovivifying hashes, you can assign nested hash
+values without having to go to the trouble of creating intermediate
+levels if they don't exist e.g syscalls[comm][pid][id] = 1 will create
+the intermediate hash levels and finally assign the value 1 to the
+hash entry for 'id' (because the value being assigned isn't a hash
+object itself, the initial value is assigned in the TypeError
+exception.  Well, there may be a better way to do this in Python but
+that's what works for now).

That's smart. I wish python had a native type for that.

Quoted 5 lines

And looking how you made it easily....

def autodict():
return defaultdict(autodict)

Yeah, being used to Perl hashes, I was surprised that Python dicts didn't also allow that, or at least have an 'autovivify' option.

I guess defaultdicts, added later, are Python's answer to that shortcoming (depending on how you look at it - I know a lot of people hate them, but it sure makes aggregating trace data a lot easier).

#34 lore raw

[tip:perf/core] perf/scripts: Add perf-trace-python Documentation

In reply to Tom Zanussi
Commit-ID:  cff68e582237cae3cf456f01153202175961dfbe
Gitweb:     http://git.kernel.org/tip/cff68e582237cae3cf456f01153202175961dfbe
Author:     Tom Zanussi <[email protected]>
AuthorDate: Wed, 27 Jan 2010 02:28:03 -0600
Committer:  Frederic Weisbecker <[email protected]>
CommitDate: Thu, 25 Feb 2010 04:07:49 +0100

perf/scripts: Add perf-trace-python Documentation

Also small update to perf-trace-perl and perf-trace docs.

Cc Ingo Molnar <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Keiichi KII <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>

LKML-Reference: <[email protected]>

---
 tools/perf/Documentation/perf-trace-perl.txt   |    3 +-
 tools/perf/Documentation/perf-trace-python.txt |  624 ++++++++++++++++++++++++
 tools/perf/Documentation/perf-trace.txt        |   11 +-
 3 files changed, 636 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-trace-perl.txt +2 -1
index c5f55f4..d2206c3 100644
@@ -8,7 +8,7 @@ perf-trace-perl - Process trace data with a Perl script
 SYNOPSIS
 --------
 [verse]
-'perf trace' [-s [lang]:script[.ext] ]
+'perf trace' [-s [Perl]:script[.pl] ]
 
 DESCRIPTION
 -----------
@@ -213,6 +213,7 @@ Various utility functions for use with perf trace:
   nsecs_nsecs($nsecs) - returns nsecs remainder given nsecs
   nsecs_str($nsecs) - returns printable string in the form secs.nsecs
   avg($total, $n) - returns average given a sum and a total number of values
+  syscall_name($id) - returns the syscall name for the specified syscall_nr
 
 SEE ALSO
 --------
tools/perf/Documentation/perf-trace-python.txt new file +624 -0

624 lines not on this page · raw message

tools/perf/Documentation/perf-trace.txt +10 -1
index c00a76f..8879299 100644
@@ -19,6 +19,11 @@ There are several variants of perf trace:
   'perf trace' to see a detailed trace of the workload that was
   recorded.
 
+  You can also run a set of pre-canned scripts that aggregate and
+  summarize the raw trace data in various ways (the list of scripts is
+  available via 'perf trace -l').  The following variants allow you to
+  record and run those scripts:
+
   'perf trace record <script>' to record the events required for 'perf
   trace report'.  <script> is the name displayed in the output of
   'perf trace --list' i.e. the actual script name minus any language
@@ -31,6 +36,9 @@ There are several variants of perf trace:
   record <script>' is used and should be present for this command to
   succeed.
 
+  See the 'SEE ALSO' section for links to language-specific
+  information on how to write and run your own trace scripts.
+
 OPTIONS
 -------
 -D::
@@ -58,4 +66,5 @@ OPTIONS
 
 SEE ALSO
 --------
-linkperf:perf-record[1], linkperf:perf-trace-perl[1]
+linkperf:perf-record[1], linkperf:perf-trace-perl[1],
+linkperf:perf-trace-python[1]
#35 lore raw
In reply to Tom Zanussi
Quoted 9 lines · Tom Zanussi

This patchset adds a Python scripting engine to perf trace. In the process, it also creates a scripting-engines directory under perf/util and moves the existing Perl support there, to avoid cluttering the main perf/util directory with scripting support files.

It also includes some minor bugfixes and adds Documentation for the Python support, which includes a step-by-step example detailing how to write a new trace stream processing script using Python.

Quoted 5 lines

Finally, it adds several new scripts, all dealing with aggregation of system call trace data. To make those scripts more user-friendly, it adds a couple patches that export some of the syscall metadata, enough to allow syscall names rather than raw numbers to be printed in the output.

Sorry to answer that late.

This looks very nice! And seeing how you made it easy to plug new languages, and how easy it is to write trace report scripts, this looks like a cool new step for the tracing over perf tools.

Focusing on scripts to post-process the tracing will certainly accelerate the movement in this area.

I've looked at some patches in the set, this looks good at a first glance. I'll review it in detail and test it, and then apply/push it if I don't encounter problems.

Thanks a lot!

#36 lore raw
Quoted 23 lines · Frederic Weisbecker
Quoted 9 lines · Tom Zanussi

This patchset adds a Python scripting engine to perf trace. In the process, it also creates a scripting-engines directory under perf/util and moves the existing Perl support there, to avoid cluttering the main perf/util directory with scripting support files.

It also includes some minor bugfixes and adds Documentation for the Python support, which includes a step-by-step example detailing how to write a new trace stream processing script using Python.

Quoted 5 lines

Finally, it adds several new scripts, all dealing with aggregation of system call trace data. To make those scripts more user-friendly, it adds a couple patches that export some of the syscall metadata, enough to allow syscall names rather than raw numbers to be printed in the output.

Sorry to answer that late.

This looks very nice! And seeing how you made it easy to plug new languages, and how easy it is to write trace report scripts, this looks like a cool new step for the tracing over perf tools.

Quoted 7 lines

Focusing on scripts to post-process the tracing will certainly accelerate the movement in this area.

I've looked at some patches in the set, this looks good at a first glance. I'll review it in detail and test it, and then apply/push it if I don't encounter problems.

No problem, thanks for reviewing them!

They've been working fine for me - playing with the Python support over the past few weeks, I haven't seen any problems, but there's one other patch that came up later that you might also want to take a look, with the title [PATCH] perf record: filter out perf process tracepoint events. Here's a link to that patch, in case you've lost track of it:

http://patchwork.kernel.org/patch/76042/

Thanks,

Tom

Quoted 2 lines

Thanks a lot!

#37 lore raw
Quoted 40 lines · Tom Zanussi
Quoted 23 lines · Frederic Weisbecker
Quoted 9 lines · Tom Zanussi

This patchset adds a Python scripting engine to perf trace. In the process, it also creates a scripting-engines directory under perf/util and moves the existing Perl support there, to avoid cluttering the main perf/util directory with scripting support files.

It also includes some minor bugfixes and adds Documentation for the Python support, which includes a step-by-step example detailing how to write a new trace stream processing script using Python.

Quoted 5 lines

Finally, it adds several new scripts, all dealing with aggregation of system call trace data. To make those scripts more user-friendly, it adds a couple patches that export some of the syscall metadata, enough to allow syscall names rather than raw numbers to be printed in the output.

Sorry to answer that late.

This looks very nice! And seeing how you made it easy to plug new languages, and how easy it is to write trace report scripts, this looks like a cool new step for the tracing over perf tools.

Quoted 7 lines

Focusing on scripts to post-process the tracing will certainly accelerate the movement in this area.

I've looked at some patches in the set, this looks good at a first glance. I'll review it in detail and test it, and then apply/push it if I don't encounter problems.

No problem, thanks for reviewing them!

They've been working fine for me - playing with the Python support over the past few weeks, I haven't seen any problems, but there's one other patch that came up later that you might also want to take a look, with the title [PATCH] perf record: filter out perf process tracepoint events. Here's a link to that patch, in case you've lost track of it:

Quoted 5 lines

http://patchwork.kernel.org/patch/76042/

Thanks,

Tom

Ah right. Hmm it's a more sensible patch, and not mandatory for the python scripting support I guess. I'll comment in on its thread.

Thanks (BTW, I've included your change on the Pytuple size).