[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH v5 07/14] trace: [tracetool] Rewrite event argum
From: |
Harsh Prateek Bora |
Subject: |
[Qemu-devel] [RFC PATCH v5 07/14] trace: [tracetool] Rewrite event argument parsing |
Date: |
Thu, 1 Mar 2012 18:55:33 +0530 |
From: Lluís Vilanova <address@hidden>
Signed-off-by: Lluís Vilanova <address@hidden>
Signed-off-by: Harsh Prateek Bora <address@hidden>
---
scripts/tracetool.py | 136 +++++++++++++++++++++++---------------------------
1 files changed, 62 insertions(+), 74 deletions(-)
diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index 1cf5c8f..986dc4d 100755
--- a/scripts/tracetool.py
+++ b/scripts/tracetool.py
@@ -39,44 +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 calc_sizeofargs(args, argc):
- str = []
- newstr = ""
- if argc > 0:
- str = args.split(',')
- for elem in str:
- if is_string(elem): #string
- type, sep, var = elem.rpartition('*')
- newstr = newstr+"4 + strlen("+var.lstrip()+") + "
- else:
- newstr = newstr + '8 + '
- newstr = newstr + '0' # takes care of last +
- return newstr
-
-
def trace_h_begin():
print '''#ifndef TRACE_H
#define TRACE_H
@@ -116,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)
@@ -130,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
@@ -138,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
@@ -164,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)
{
@@ -205,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 '''
@@ -229,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);
@@ -279,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):
@@ -318,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
@@ -397,6 +350,47 @@ trace_gen = {
},
}
+# Event arguments
+def type_is_string(type_):
+ strtype = ('const char*', 'char*', 'const char *', 'char *')
+ return type_.lstrip().startswith(strtype)
+
+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 ]
+
+ def size_str(self):
+ res = ""
+ return res
+
# A trace event
cre =
re.compile("((?P<props>.*)\s+)?(?P<name>[^(\s]+)\((?P<args>[^)]*)\)\s*(?P<fmt>\".*)?")
@@ -407,17 +401,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.sizestr = calc_sizeofargs(self.args, self.argc)
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))
--
1.7.1.1
- [Qemu-devel] [RFC PATCH v5 00/14] Tracing Improvements, Simpletrace v2, Harsh Prateek Bora, 2012/03/01
- [Qemu-devel] [RFC PATCH v5 06/14] trace: [tracetool] Process the "disable" event property, Harsh Prateek Bora, 2012/03/01
- [Qemu-devel] [RFC PATCH v5 12/14] monitor: remove unused do_info_trace, Harsh Prateek Bora, 2012/03/01
- [Qemu-devel] [RFC PATCH v5 14/14] scripts/simpltrace.py changes: Support simplettrace v2, Harsh Prateek Bora, 2012/03/01
- [Qemu-devel] [RFC PATCH v5 05/14] trace: [tracetool] Add support for event properties, Harsh Prateek Bora, 2012/03/01
- [Qemu-devel] [RFC PATCH v5 07/14] trace: [tracetool] Rewrite event argument parsing,
Harsh Prateek Bora <=
- [Qemu-devel] [RFC PATCH v5 11/14] trace: [tracetool] Add error-reporting functions, Harsh Prateek Bora, 2012/03/01
- [Qemu-devel] [RFC PATCH v5 02/14] trace: [tracetool] Do not rebuild event list in backend code, Harsh Prateek Bora, 2012/03/01
- [Qemu-devel] [RFC PATCH v5 08/14] trace: [tracetool] Make format-specific code optional with access to events, Harsh Prateek Bora, 2012/03/01
- [Qemu-devel] [RFC PATCH v5 03/14] trace: [tracetool] Simplify event line parsing, Harsh Prateek Bora, 2012/03/01
- [Qemu-devel] [RFC PATCH v5 13/14] Simpletrace v2: Handle var num of args, strings., Harsh Prateek Bora, 2012/03/01
- [Qemu-devel] [RFC PATCH v5 09/14] trace: [tracetool] Automatically establish available backends and formats, Harsh Prateek Bora, 2012/03/01
- [Qemu-devel] [RFC PATCH v5 04/14] trace: [tracetool] Do not precompute the event number, Harsh Prateek Bora, 2012/03/01
- [Qemu-devel] [RFC PATCH v5 10/14] trace: Provide a per-event status define for conditional compilation, Harsh Prateek Bora, 2012/03/01