Perf python scripting support
Ingo,
Please pull the perf/core branch that can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
perf/core
I've left out the parts that deal with syscall nr to name resolution as it would be nicer to implement it through events injection instead of yet another debugfs file.
The reason I've made a separate patch to tag syscall_name() helper as unavailable yet is that it makes it easily revertable later, once it gets supported.
I've tested the whole and it works very well.
Thanks,
Frederic
---
Tom Zanussi (9):
perf/scripts: Fix supported language listing option perf/scripts: Fix bug in Util.pm
perf/scripts: Move common code out of Perl-specific files perf/scripts: Move Perl scripting files to scripting-engines dir perf/scripts: Remove check-perf-trace from listed scripts perf/scripts: Add Python scripting engine perf/scripts: Add syscall tracing scripts perf/scripts: Remove unnecessary PyTuple resizes perf/scripts: Add perf-trace-python Documentation
Frederic Weisbecker (1):
perf/scripts: Tag syscall_name helper as not yet available
tools/perf/Documentation/perf-trace-perl.txt | 2 +- tools/perf/Documentation/perf-trace-python.txt | 625 ++++++++++++++++++ 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 | 5 +- tools/perf/scripts/perl/Perf-Trace-Util/Context.xs | 3 +- .../perl/Perf-Trace-Util/lib/Perf/Trace/Util.pm | 2 +- .../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 | 38 ++ .../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 + .../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 ++ .../perf/util/scripting-engines/trace-event-perl.c | 568 +++++++++++++++++ .../util/scripting-engines/trace-event-python.c | 573 +++++++++++++++++ tools/perf/util/trace-event-parse.c | 15 + tools/perf/util/trace-event-perl.c | 661 -------------------- tools/perf/util/trace-event-perl.h | 55 -- tools/perf/util/trace-event-scripting.c | 167 +++++ tools/perf/util/trace-event.h | 10 +- 33 files changed, 2549 insertions(+), 742 deletions(-)
PATCH 1/10 perf/scripts: Fix supported language listing option
From: Tom Zanussi <[email protected]>
'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.
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
@@ -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
@@ -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.2.3
PATCH 2/10 perf/scripts: Fix bug in Util.pm
In reply to Frederic WeisbeckerFrom: Tom Zanussi <[email protected]>
Fix bogus calculation.
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
@@ -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.2.3
PATCH 3/10 perf/scripts: Move common code out of Perl-specific files
In reply to Frederic WeisbeckerFrom: Tom Zanussi <[email protected]>
This stuff is needed by all scripting engines; move it from the Perl engine source to a more common place.
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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.2.3
PATCH 4/10 perf/scripts: Move Perl scripting files to scripting-engines dir
In reply to Frederic WeisbeckerFrom: Tom Zanussi <[email protected]>
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.
LKML-Reference: <[email protected]>
---
tools/perf/Makefile | 9 +-
.../{ => scripting-engines}/trace-event-perl.c | 88 ++--------------
tools/perf/util/trace-event-perl.h | 47 ---------
tools/perf/util/trace-event-scripting.c | 106 ++++++++++++++++++++
4 files changed, 122 insertions(+), 128 deletions(-)
rename tools/perf/util/{ => scripting-engines}/trace-event-perl.c (87%)
delete mode 100644 tools/perf/util/trace-event-perl.h
create mode 100644 tools/perf/util/trace-event-scripting.ctools/perf/Makefile +5 -4
@@ -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 renamed from tools/perf/util/trace-event-perl.c +11 -77
103 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.2.3
PATCH 5/10 perf/scripts: Remove check-perf-trace from listed scripts
In reply to Frederic WeisbeckerFrom: Tom Zanussi <[email protected]>
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
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(-) delete mode 100644 tools/perf/scripts/perl/bin/check-perf-trace-report
tools/perf/scripts/perl/bin/check-perf-trace-record +0 -5
@@ -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
@@ -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.2.3
PATCH 6/10 perf/scripts: Add Python scripting engine
In reply to Frederic WeisbeckerFrom: Tom Zanussi <[email protected]>
Add base support for Python scripting to perf trace.
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(-) 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
@@ -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
@@ -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
@@ -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
@@ -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.2.3
PATCH 7/10 perf/scripts: Add syscall tracing scripts
In reply to Frederic WeisbeckerFrom: Tom Zanussi <[email protected]>
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.
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(-) 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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.2.3
PATCH 8/10 perf/scripts: Remove unnecessary PyTuple resizes
In reply to Frederic WeisbeckerFrom: Tom Zanussi <[email protected]>
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.
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
@@ -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.2.3
PATCH 9/10 perf/scripts: Add perf-trace-python Documentation
In reply to Frederic WeisbeckerFrom: Tom Zanussi <[email protected]>
Also small update to perf-trace-perl and perf-trace docs.
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(-) create mode 100644 tools/perf/Documentation/perf-trace-python.txt
tools/perf/Documentation/perf-trace-perl.txt +2 -1
@@ -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
@@ -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.2.3
PATCH 10/10 perf/scripts: Tag syscall_name helper as not yet available
In reply to Frederic Weisbeckersyscall_name() helper, which resolves a syscall arch number to its name, is not yet available as we first need to implement event injection for it to work.
Remove it from the documentation or tag its references as unavailable yet. Once it's implemented, we can just revert the current patch.
--- tools/perf/Documentation/perf-trace-perl.txt | 1 - tools/perf/Documentation/perf-trace-python.txt | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-)
tools/perf/Documentation/perf-trace-perl.txt +0 -1
@@ -213,7 +213,6 @@ 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 +4 -3
@@ -36,7 +36,8 @@ scripts listed by that command. The syscall-counts script is a simple script, but demonstrates all the basic ideas necessary to create a useful script. Here's an example -of its output: +of its output (syscall names are not yet supported, they will appear +as numbers): ---- syscall events:
@@ -270,7 +271,8 @@ calling the print_syscall_totals() function from the trace_end() handler called at the end of script processing. The final script producing the output shown above is shown in its -entirety below: +entirety below (syscall_name() helper is not yet available, you can +only deal with id's for now): ---- import os
@@ -617,7 +619,6 @@ 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 --------
Signature · 1 line
1.6.2.3
Quoted 11 lines · Frederic Weisbecker
Ingo,
Please pull the perf/core branch that can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
perf/coreI've left out the parts that deal with syscall nr to name resolution as it would be nicer to implement it through events injection instead of yet another debugfs file.
Quoted 5 lines
The reason I've made a separate patch to tag
syscall_name()helper as unavailable yet is that it makes it easily revertable later, once it gets supported.I've tested the whole and it works very well.
Pulled, thanks a lot!
Ingo