From: "Lluís Vilanova" <vilanova@ac.upc.edu>
To: qemu-devel@nongnu.org
Cc: stefanha@gmail.com, harsh@linux.vnet.ibm.com,
aneesh.kumar@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH 08/12] trace: [tracetool] Rewrite event argument parsing
Date: Tue, 13 Mar 2012 21:03:21 +0100 [thread overview]
Message-ID: <20120313200321.24179.96627.stgit@ginnungagap.bsc.es> (raw)
In-Reply-To: <20120313200235.24179.63987.stgit@ginnungagap.bsc.es>
Adds an 'Arguments' class to describe event arguments.
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
Signed-off-by: Harsh Prateek Bora <harsh@linux.vnet.ibm.com>
---
scripts/tracetool.py | 113 ++++++++++++++++++++++++--------------------------
1 files changed, 54 insertions(+), 59 deletions(-)
diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index d7c04b4..f017053 100755
--- a/scripts/tracetool.py
+++ b/scripts/tracetool.py
@@ -39,30 +39,6 @@ Options:
'''
sys.exit(1)
-def get_argnames(args):
- nfields = 0
- str = []
- for field in args.split():
- nfields = nfields + 1
- # Drop pointer star
- type, ptr, tail = field.partition('*')
- if type != field:
- field = tail
-
- name, sep, tail = field.partition(',')
-
- if name == field:
- continue
- str.append(name)
- str.append(", ")
-
- if nfields > 1:
- str.append(name)
- return ''.join(str)
- else:
- return ''
-
-
def trace_h_begin():
print '''#ifndef TRACE_H
#define TRACE_H
@@ -102,11 +78,11 @@ def simple_h(events):
print
for num, event in enumerate(events):
- if event.argc:
- argstr = event.argnames.split()
- arg_prefix = '(uint64_t)(uintptr_t)'
+ if len(event.args):
+ argstr = event.args.names()
+ arg_prefix = ', (uint64_t)(uintptr_t)'
cast_args = arg_prefix + arg_prefix.join(argstr)
- simple_args = (str(num) + ', ' + cast_args)
+ simple_args = (str(num) + cast_args)
else:
simple_args = str(num)
@@ -116,7 +92,7 @@ def simple_h(events):
}''' % {
'name': event.name,
'args': event.args,
- 'argc': event.argc,
+ 'argc': len(event.args),
'trace_args': simple_args
}
print
@@ -124,13 +100,6 @@ def simple_h(events):
print 'extern TraceEvent trace_list[NR_TRACE_EVENTS];'
-def is_string(arg):
- strtype = ('const char*', 'char*', 'const char *', 'char *')
- if arg.lstrip().startswith(strtype):
- return True
- else:
- return False
-
def simple_c(events):
print '#include "trace.h"'
print
@@ -150,11 +119,9 @@ def stderr_h(events):
extern TraceEvent trace_list[];'''
for num, event in enumerate(events):
- argnames = event.argnames
- if event.argc > 0:
- argnames = ', ' + event.argnames
- else:
- argnames = ''
+ argnames = ", ".join(event.args.names())
+ if len(event.args) > 0:
+ argnames = ", " + argnames
print '''
static inline void trace_%(name)s(%(args)s)
{
@@ -191,13 +158,13 @@ def ust_h(events):
#undef wmb'''
for event in events:
- if event.argc > 0:
+ if len(event.args) > 0:
print '''
DECLARE_TRACE(ust_%(name)s, TP_PROTO(%(args)s), TP_ARGS(%(argnames)s));
#define trace_%(name)s trace_ust_%(name)s''' % {
'name': event.name,
'args': event.args,
- 'argnames': event.argnames
+ 'argnames': ", ".join(event.args.names())
}
else:
print '''
@@ -215,9 +182,9 @@ def ust_c(events):
#undef wmb
#include "trace.h"'''
for event in events:
- argnames = event.argnames
- if event.argc > 0:
- argnames = ', ' + event.argnames
+ argnames = ", ".join(event.args.names())
+ if len(event.args) > 0:
+ argnames = ', ' + argnames
print '''
DEFINE_TRACE(ust_%(name)s);
@@ -265,7 +232,7 @@ def dtrace_h(events):
'name': event.name,
'args': event.args,
'uppername': event.name.upper(),
- 'argnames': event.argnames,
+ 'argnames': ", ".join(event.args.names()),
}
def dtrace_c(events):
@@ -304,12 +271,12 @@ probe %(probeprefix)s.%(name)s = process("%(binary)s").mark("%(name)s")
'binary': binary
}
i = 1
- if event.argc > 0:
- for arg in event.argnames.split(','):
+ if len(event.args) > 0:
+ for name in event.args.names():
# 'limit' is a reserved keyword
- if arg == 'limit':
- arg = '_limit'
- print ' %s = $arg%d;' % (arg.lstrip(), i)
+ if name == 'limit':
+ name = '_limit'
+ print ' %s = $arg%d;' % (name.lstrip(), i)
i += 1
print '}'
print
@@ -383,6 +350,39 @@ trace_gen = {
},
}
+# Event arguments
+class Arguments:
+ def __init__ (self, arg_str):
+ self._args = []
+ for arg in arg_str.split(","):
+ arg = arg.strip()
+ parts = arg.split()
+ head, sep, tail = parts[-1].rpartition("*")
+ parts = parts[:-1]
+ if tail == "void":
+ assert len(parts) == 0 and sep == ""
+ continue
+ arg_type = " ".join(parts + [ " ".join([head, sep]).strip() ]).strip()
+ self._args.append((arg_type, tail))
+
+ def __iter__(self):
+ return iter(self._args)
+
+ def __len__(self):
+ return len(self._args)
+
+ def __str__(self):
+ if len(self._args) == 0:
+ return "void"
+ else:
+ return ", ".join([ " ".join([t, n]) for t,n in self._args ])
+
+ def names(self):
+ return [ name for _, name in self._args ]
+
+ def types(self):
+ return [ type_ for type_, _ in self._args ]
+
# A trace event
cre = re.compile("((?P<props>.*)\s+)?(?P<name>[^(\s]+)\((?P<args>[^)]*)\)\s*(?P<fmt>\".*)?")
@@ -393,16 +393,11 @@ class Event(object):
m = cre.match(line)
assert m is not None
groups = m.groupdict('')
- self.args = groups["args"]
- self.arglist = self.args.split(',')
self.name = groups["name"]
- if len(self.arglist) == 1 and self.arglist[0] == "void":
- self.argc = 0
- else:
- self.argc = len(self.arglist)
- self.argnames = get_argnames(self.args)
self.fmt = groups["fmt"]
self.properties = groups["props"].split()
+ self.args = Arguments(groups["args"])
+
unknown_props = set(self.properties) - VALID_PROPS
if len(unknown_props) > 0:
raise ValueError("Unknown properties: %s" % ", ".join(unknown_props))
next prev parent reply other threads:[~2012-03-13 20:03 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-13 20:02 [Qemu-devel] [PATCH 00/12] Rewrite tracetool using python Lluís Vilanova
2012-03-13 20:02 ` [Qemu-devel] [PATCH 01/12] Converting tracetool.sh to tracetool.py Lluís Vilanova
2012-03-19 16:51 ` Stefan Hajnoczi
2012-03-13 20:02 ` [Qemu-devel] [PATCH 02/12] trace: [tracetool] Remove unused 'sizestr' attribute in 'Event' Lluís Vilanova
2012-03-13 20:02 ` [Qemu-devel] [PATCH 03/12] trace: [tracetool] Do not rebuild event list in backend code Lluís Vilanova
2012-03-13 20:02 ` [Qemu-devel] [PATCH 04/12] trace: [tracetool] Simplify event line parsing Lluís Vilanova
2012-03-13 20:03 ` [Qemu-devel] [PATCH 05/12] trace: [tracetool] Do not precompute the event number Lluís Vilanova
2012-03-13 20:03 ` [Qemu-devel] [PATCH 06/12] trace: [tracetool] Add support for event properties Lluís Vilanova
2012-03-13 20:03 ` [Qemu-devel] [PATCH 07/12] trace: [tracetool] Process the "disable" event property Lluís Vilanova
2012-03-13 20:03 ` Lluís Vilanova [this message]
2012-03-13 20:03 ` [Qemu-devel] [PATCH 09/12] trace: [tracetool] Make format-specific code optional and with access to events Lluís Vilanova
2012-03-13 20:03 ` [Qemu-devel] [PATCH 10/12] trace: [tracetool] Automatically establish available backends and formats Lluís Vilanova
2012-03-20 9:22 ` Stefan Hajnoczi
2012-03-20 14:00 ` Lluís Vilanova
2012-03-20 16:33 ` Stefan Hajnoczi
2012-03-20 18:45 ` Lluís Vilanova
2012-03-21 9:29 ` Stefan Hajnoczi
2012-03-21 14:10 ` Lluís Vilanova
2012-03-22 8:07 ` Stefan Hajnoczi
2012-03-21 19:59 ` Lluís Vilanova
2012-03-21 21:22 ` Lluís Vilanova
2012-03-13 20:03 ` [Qemu-devel] [PATCH 11/12] trace: Provide a per-event status define for conditional compilation Lluís Vilanova
2012-03-13 20:03 ` [Qemu-devel] [PATCH 12/12] trace: [tracetool] Add error-reporting functions Lluís Vilanova
2012-03-19 17:45 ` Stefan Hajnoczi
2012-03-20 9:24 ` [Qemu-devel] [PATCH 00/12] Rewrite tracetool using python Stefan Hajnoczi
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=20120313200321.24179.96627.stgit@ginnungagap.bsc.es \
--to=vilanova@ac.upc.edu \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=harsh@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).