lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1264580883-15324-11-git-send-email-tzanussi@gmail.com>
Date:	Wed, 27 Jan 2010 02:28:01 -0600
From:	Tom Zanussi <tzanussi@...il.com>
To:	linux-kernel@...r.kernel.org
Cc:	mingo@...e.hu, fweisbec@...il.com, rostedt@...dmis.org,
	k-keiichi@...jp.nec.com
Subject: [PATCH 10/12] perf trace/scripting: make the syscall map available as a Python dict

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).

Signed-off-by: Tom Zanussi <tzanussi@...il.com>
---
 .../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(-)

diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Context.c b/tools/perf/scripts/python/Perf-Trace-Util/Context.c
index 957085d..ebdcc35 100644
--- a/tools/perf/scripts/python/Perf-Trace-Util/Context.c
+++ b/tools/perf/scripts/python/Perf-Trace-Util/Context.c
@@ -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}
 };
 
diff --git a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py
index 83e9143..08d7d8e 100644
--- a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py
+++ b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py
@@ -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)
diff --git a/tools/perf/scripts/python/failed-syscalls-by-pid.py b/tools/perf/scripts/python/failed-syscalls-by-pid.py
index 0ca0227..007e959 100644
--- a/tools/perf/scripts/python/failed-syscalls-by-pid.py
+++ b/tools/perf/scripts/python/failed-syscalls-by-pid.py
@@ -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),
diff --git a/tools/perf/scripts/python/syscall-counts-by-pid.py b/tools/perf/scripts/python/syscall-counts-by-pid.py
index af722d6..fffe0d6 100644
--- a/tools/perf/scripts/python/syscall-counts-by-pid.py
+++ b/tools/perf/scripts/python/syscall-counts-by-pid.py
@@ -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),
diff --git a/tools/perf/scripts/python/syscall-counts.py b/tools/perf/scripts/python/syscall-counts.py
index f977e85..a641c6f 100644
--- a/tools/perf/scripts/python/syscall-counts.py
+++ b/tools/perf/scripts/python/syscall-counts.py
@@ -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),
-- 
1.6.4.GIT

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ