From: Tom Zanussi <tzanussi@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: mingo@elte.hu, fweisbec@gmail.com, rostedt@goodmis.org,
k-keiichi@bx.jp.nec.com
Subject: [PATCH 11/12] perf trace/scripting: make the syscall map available as a Perl hash
Date: Wed, 27 Jan 2010 02:28:02 -0600 [thread overview]
Message-ID: <1264580883-15324-12-git-send-email-tzanussi@gmail.com> (raw)
In-Reply-To: <1264580883-15324-1-git-send-email-tzanussi@gmail.com>
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).
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
---
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(-)
diff --git a/tools/perf/scripts/perl/Perf-Trace-Util/Context.c b/tools/perf/scripts/perl/Perf-Trace-Util/Context.c
index 01a64ad..ae2279d 100644
--- a/tools/perf/scripts/perl/Perf-Trace-Util/Context.c
+++ b/tools/perf/scripts/perl/Perf-Trace-Util/Context.c
@@ -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;
diff --git a/tools/perf/scripts/perl/Perf-Trace-Util/Context.xs b/tools/perf/scripts/perl/Perf-Trace-Util/Context.xs
index 549cf04..d016473 100644
--- a/tools/perf/scripts/perl/Perf-Trace-Util/Context.xs
+++ b/tools/perf/scripts/perl/Perf-Trace-Util/Context.xs
@@ -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()
+
diff --git a/tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Context.pm b/tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Context.pm
index 6c7f365..dc2231e 100644
--- a/tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Context.pm
+++ b/tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Context.pm
@@ -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';
diff --git a/tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Util.pm b/tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Util.pm
index f869c48..d62314b 100644
--- a/tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Util.pm
+++ b/tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Util.pm
@@ -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
diff --git a/tools/perf/scripts/perl/failed-syscalls.pl b/tools/perf/scripts/perl/failed-syscalls.pl
index c18e7e2..eeaaa28 100644
--- a/tools/perf/scripts/perl/failed-syscalls.pl
+++ b/tools/perf/scripts/perl/failed-syscalls.pl
@@ -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});
+ }
}
--
1.6.4.GIT
next prev parent reply other threads:[~2010-01-27 8:29 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-27 8:27 [PATCH 00/12] perf trace: Python scripting support Tom Zanussi
2010-01-27 8:27 ` [PATCH 01/12] perf trace/scripting: Fix supported language listing option Tom Zanussi
2010-02-25 10:06 ` [tip:perf/core] perf/scripts: " tip-bot for Tom Zanussi
2010-01-27 8:27 ` [PATCH 02/12] perf trace/scripting: fix bug in Util.pm Tom Zanussi
2010-02-25 10:06 ` [tip:perf/core] perf/scripts: Fix " tip-bot for Tom Zanussi
2010-01-27 8:27 ` [PATCH 03/12] perf trace/scripting: move common code out of Perl-specific files Tom Zanussi
2010-02-25 10:07 ` [tip:perf/core] perf/scripts: Move " tip-bot for Tom Zanussi
2010-01-27 8:27 ` [PATCH 04/12] perf trace/scripting: move Perl scripting files to scripting-engines dir Tom Zanussi
2010-02-25 10:07 ` [tip:perf/core] perf/scripts: Move " tip-bot for Tom Zanussi
2010-01-27 8:27 ` [PATCH 05/12] perf trace/scripting: remove check-perf-trace from listed scripts Tom Zanussi
2010-02-22 1:51 ` Frederic Weisbecker
2010-02-25 10:07 ` [tip:perf/core] perf/scripts: Remove " tip-bot for Tom Zanussi
2010-02-25 10:07 ` [tip:perf/core] perf/scripts: Add Python scripting engine tip-bot for Tom Zanussi
2010-01-27 8:27 ` [PATCH 06/12] perf trace/scripting: add " Tom Zanussi
2010-02-22 2:27 ` Frederic Weisbecker
2010-02-22 7:12 ` Tom Zanussi
2010-02-25 10:08 ` [tip:perf/core] perf/scripts: Remove unnecessary PyTuple resizes tip-bot for Tom Zanussi
2010-01-27 8:27 ` [PATCH 07/12] perf trace/scripting: add syscall tracing scripts Tom Zanussi
2010-02-25 10:08 ` [tip:perf/core] perf/scripts: Add " tip-bot for Tom Zanussi
2010-01-27 8:27 ` [PATCH 08/12] perf: export some syscall metadata Tom Zanussi
2010-02-23 21:44 ` Frederic Weisbecker
2010-02-24 6:00 ` Tom Zanussi
2010-02-25 1:52 ` Frederic Weisbecker
2010-02-25 6:09 ` Tom Zanussi
2010-02-25 2:43 ` Frederic Weisbecker
2010-02-25 6:51 ` Tom Zanussi
2010-03-27 0:37 ` Frederic Weisbecker
2010-03-28 5:18 ` Tom Zanussi
2010-01-27 8:28 ` [PATCH 09/12] perf tools: save syscall map Tom Zanussi
2010-01-27 8:28 ` [PATCH 10/12] perf trace/scripting: make the syscall map available as a Python dict Tom Zanussi
2010-01-27 8:28 ` Tom Zanussi [this message]
2010-01-27 8:28 ` [PATCH 12/12] perf trace/scripting: add perf-trace-python Documentation Tom Zanussi
2010-02-25 1:37 ` Frederic Weisbecker
2010-02-25 6:06 ` Tom Zanussi
2010-02-25 10:08 ` [tip:perf/core] perf/scripts: Add " tip-bot for Tom Zanussi
2010-02-19 21:37 ` [PATCH 00/12] perf trace: Python scripting support Frederic Weisbecker
2010-02-20 21:51 ` Tom Zanussi
2010-02-23 17:31 ` Frederic Weisbecker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1264580883-15324-12-git-send-email-tzanussi@gmail.com \
--to=tzanussi@gmail.com \
--cc=fweisbec@gmail.com \
--cc=k-keiichi@bx.jp.nec.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®