Skip to contentSkip to conversation

Rewrite tracetool using python modules

RFC PATCH Superseded Lluís Vilanova 2 participants 18 messages Mar 27, 2012 – Apr 2, 2012 Kbuild

v3 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v3 cover Rewrite tracetool using python modules

A full rewrite of the tracetool script using per-format and per-backend modules, so that it's easier to read and extend it in the future.

---
NOTE: This series applies in current master, ignoring the "Rewrite tracetool
using python" series.

Changes in v3:

* Some minor fixes according to comments from Alon Levy:
** Fixed some rogue tabs.
** Fixed definition of '_SCRIPT' in "tracetool.py".
** Fixed some documentation.
** Defensively treat results from 'try_import' in 'get_list'. ** Fixed the no-arguments case in 'tracetool.backend.dtrace.d'. ** Fixed the commandline checks for the "stap" format. ** Added '__repr__' methods for both Event and Arguments objects.

Changes in v2:

* Fixed a strange import error.
* Add a pointer to 'tracetool.out' in the format and backend documentation.

Lluís Vilanova (8):
tracetool: Rewrite infrastructure as python modules
tracetool: Add module for the 'c' format
tracetool: Add module for the 'h' format
tracetool: Add support for the 'stderr' backend
tracetool: Add support for the 'simple' backend
tracetool: Add support for the 'ust' backend
tracetool: Add support for the 'dtrace' backend
tracetool: Add MAINTAINERS info

 MAINTAINERS                           |    2 
 Makefile.objs                         |    6 
 Makefile.target                       |   13 -
 configure                             |    4 
 scripts/tracetool                     |  648 ---------------------------------
 scripts/tracetool.py                  |  141 +++++++
 scripts/tracetool/__init__.py         |  223 +++++++++++
 scripts/tracetool/backend/__init__.py |  119 ++++++
 scripts/tracetool/backend/dtrace.py   |  104 +++++
 scripts/tracetool/backend/simple.py   |   60 +++
 scripts/tracetool/backend/stderr.py   |   61 +++
 scripts/tracetool/backend/ust.py      |  102 +++++
 scripts/tracetool/format/__init__.py  |   96 +++++
 scripts/tracetool/format/c.py         |   20 +
 scripts/tracetool/format/d.py         |   20 +
 scripts/tracetool/format/h.py         |   45 ++
 scripts/tracetool/format/stap.py      |   20 +
 17 files changed, 1025 insertions(+), 659 deletions(-)
 delete mode 100755 scripts/tracetool
 create mode 100755 scripts/tracetool.py
 create mode 100644 scripts/tracetool/__init__.py
 create mode 100644 scripts/tracetool/backend/__init__.py
 create mode 100644 scripts/tracetool/backend/dtrace.py
 create mode 100644 scripts/tracetool/backend/simple.py
 create mode 100644 scripts/tracetool/backend/stderr.py
 create mode 100644 scripts/tracetool/backend/ust.py
 create mode 100644 scripts/tracetool/format/__init__.py
 create mode 100644 scripts/tracetool/format/c.py
 create mode 100644 scripts/tracetool/format/d.py
 create mode 100644 scripts/tracetool/format/h.py
 create mode 100644 scripts/tracetool/format/stap.py
#1 lore raw

RFC PATCH v3 1/8 tracetool: Rewrite infrastructure as python modules

---
 Makefile.objs                         |    6 
 Makefile.target                       |   13 -
 configure                             |    4 
 scripts/tracetool                     |  648 ---------------------------------
 scripts/tracetool.py                  |  110 ++++++
 scripts/tracetool/__init__.py         |  215 +++++++++++
 scripts/tracetool/backend/__init__.py |  119 ++++++
 scripts/tracetool/format/__init__.py  |   96 +++++
 8 files changed, 552 insertions(+), 659 deletions(-)
 delete mode 100755 scripts/tracetool
 create mode 100755 scripts/tracetool.py
 create mode 100644 scripts/tracetool/__init__.py
 create mode 100644 scripts/tracetool/backend/__init__.py
 create mode 100644 scripts/tracetool/format/__init__.py
Makefile.objs +3 -3
index 226b01d..8e56f48 100644
@@ -373,12 +373,12 @@ else
 trace.h: trace.h-timestamp
 endif
 trace.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
-	$(call quiet-command,sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND) -h < $< > $@,"  GEN   trace.h")
+	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/tracetool.py --format=h --backend=$(TRACE_BACKEND) < $< > $@,"  GEN   trace.h")
 	@cmp -s $@ trace.h || cp $@ trace.h
 
 trace.c: trace.c-timestamp
 trace.c-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
-	$(call quiet-command,sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND) -c < $< > $@,"  GEN   trace.c")
+	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/tracetool.py --format=c --backend=$(TRACE_BACKEND) < $< > $@,"  GEN   trace.c")
 	@cmp -s $@ trace.c || cp $@ trace.c
 
 trace.o: trace.c $(GENERATED_HEADERS)
@@ -391,7 +391,7 @@ trace-dtrace.h: trace-dtrace.dtrace
 # rule file. So we use '.dtrace' instead
 trace-dtrace.dtrace: trace-dtrace.dtrace-timestamp
 trace-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
-	$(call quiet-command,sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND) -d < $< > $@,"  GEN   trace-dtrace.dtrace")
+	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/tracetool.py --format=d --backend=$(TRACE_BACKEND) < $< > $@,"  GEN   trace-dtrace.dtrace")
 	@cmp -s $@ trace-dtrace.dtrace || cp $@ trace-dtrace.dtrace
 
 trace-dtrace.o: trace-dtrace.dtrace $(GENERATED_HEADERS)
Makefile.target +7 -6
index 63cf769..fe28e8b 100644
@@ -59,12 +59,13 @@ TARGET_TYPE=system
 endif
 
 $(QEMU_PROG).stp:
-	$(call quiet-command,sh $(SRC_PATH)/scripts/tracetool \
-		--$(TRACE_BACKEND) \
-		--binary $(bindir)/$(QEMU_PROG) \
-		--target-arch $(TARGET_ARCH) \
-		--target-type $(TARGET_TYPE) \
-		--stap < $(SRC_PATH)/trace-events > $(QEMU_PROG).stp,"  GEN   $(QEMU_PROG).stp")
+	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/tracetool.py \
+		--format=stap \
+		--backend=$(TRACE_BACKEND) \
+		--binary=$(bindir)/$(QEMU_PROG) \
+		--target-arch=$(TARGET_ARCH) \
+		--target-type=$(TARGET_TYPE) \
+		< $(SRC_PATH)/trace-events > $(QEMU_PROG).stp,"  GEN   $(QEMU_PROG).stp")
 else
 stap:
 endif
configure +2 -2
index 8b4e3c1..c2d6117 100755
@@ -1097,7 +1097,7 @@ echo "  --disable-docs           disable documentation build"
 echo "  --disable-vhost-net      disable vhost-net acceleration support"
 echo "  --enable-vhost-net       enable vhost-net acceleration support"
 echo "  --enable-trace-backend=B Set trace backend"
-echo "                           Available backends:" $("$source_path"/scripts/tracetool --list-backends)
+echo "                           Available backends:" $($python "$source_path"/scripts/tracetool.py --list-backends)
 echo "  --with-trace-file=NAME   Full PATH,NAME of file to store traces"
 echo "                           Default:trace-<pid>"
 echo "  --disable-spice          disable spice"
@@ -2654,7 +2654,7 @@ fi
 ##########################################
 # check if trace backend exists
 
-sh "$source_path/scripts/tracetool" "--$trace_backend" --check-backend > /dev/null 2> /dev/null
+$python "$source_path/scripts/tracetool.py" "--backend=$trace_backend" --check-backend  > /dev/null 2> /dev/null
 if test "$?" -ne 0 ; then
   echo
   echo "Error: invalid trace backend"
scripts/tracetool deleted +0 -648

648 lines not on this page · raw message

scripts/tracetool.py new file +110 -0

110 lines not on this page · raw message

scripts/tracetool/__init__.py new file +215 -0

215 lines not on this page · raw message

scripts/tracetool/backend/__init__.py new file +119 -0

119 lines not on this page · raw message

scripts/tracetool/format/__init__.py new file +96 -0

96 lines not on this page · raw message

#2 lore raw

Re: [Qemu-devel] [RFC PATCH v3 1/8] tracetool: Rewrite infrastructure as python modules

Quoted 101 lines · Lluís Vilanova
scripts/tracetool.py new file +95 -0
new file mode 100755
index 0000000..70bf79a
@@ -0,0 +1,110 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+Command-line wrapper for the tracetool machinery.
+"""
+
+__author__     = "Lluís Vilanova <[email protected]>"
+__copyright__  = "Copyright 2012, Lluís Vilanova <[email protected]>"
+__license__    = "GPL version 2 or (at your option) any later version"
+
+__maintainer__ = "Stefan Hajnoczi"
+__email__      = "[email protected]"
+
+
+import sys
+import getopt
+
+from tracetool import error_write, out
+import tracetool.backend
+import tracetool.format
+
+
+_SCRIPT = ""
+
+def error_opt(msg = None):
+    if msg is not None:
+        error_write("Error: " + msg + "\n")
+
+    backend_descr = "\n".join([ "    %-15s %s" % (n, d)
+                                for n,d in tracetool.backend.get_list() ])
+    format_descr = "\n".join([ "    %-15s %s" % (n, d)
+                               for n,d in tracetool.format.get_list() ])
+    error_write("""\
+Usage: %(script)s --format=<format> --backend=<backend> [<options>]
+
+Backends:
+%(backends)s
+
+Formats:
+%(formats)s
+
+Options:
+    --help                   This help message.
+    --list-backends          Print list of available backends.
+    --check-backend          Check if the given backend is valid.
+""" % {
+            "script" : _SCRIPT,
+            "backends" : backend_descr,
+            "formats" : format_descr,
+            })
+
+    if msg is None:
+        sys.exit(0)
+    else:
+        sys.exit(1)
+
+
+def main(args):
+    global _SCRIPT
+    _SCRIPT = args[0]
+
+    long_opts  = [ "backend=", "format=", "help", "list-backends", "check-backend" ]
+    long_opts += [ "binary=", "target-type=", "target-arch=", "probe-prefix=" ]
+
+    try:
+        opts, args = getopt.getopt(args[1:], "", long_opts)
+    except getopt.GetoptError as err:
+        error_opt(str(err))
+
+    check_backend = False
+    arg_backend = ""
+    arg_format = ""
+    for opt, arg in opts:
+        if opt == "--help":
+            error_opt()
+
+        elif opt == "--backend":
+            arg_backend = arg
+        elif opt == "--format":
+            arg_format = arg
+
+        elif opt == "--list-backends":
+            public_backends = tracetool.backend.get_list(only_public = True)
+            out(", ".join([ b for b,_ in public_backends ]))
+            sys.exit(0)
+        elif opt == "--check-backend":
+            check_backend = True
+
+        else:
+            error_opt("unhandled option: %s" % opt)
+
+    if arg_backend is None:
+        error_opt("backend not set")
+

scripts/tracetool.py line 105

Quoted 10 lines
scripts/tracetool.py new file +10 -0
+    if check_backend:
+        if tracetool.backend.exists(arg_backend):
+            sys.exit(0)
+        else:
+            sys.exit(1)
+
+    kwargs = {}
+
+    try:
+        tracetool.generate(sys.stdin, arg_format, arg_backend, **kwargs)

If forgot to ask what kwargs is doing here? Can we default to {}?
Otherwise let's drop it for now since there are no options defined yet.

Stefan

#3 lore raw

Re: [Qemu-devel] [RFC PATCH v3 1/8] tracetool: Rewrite infrastructure as python modules

Quoted 7 lines · Stefan Hajnoczi

scripts/tracetool.py line 105

Quoted 4 lines
scripts/tracetool.py new file +4 -0
+    kwargs = {}
+
+    try:
+        tracetool.generate(sys.stdin, arg_format, arg_backend, **kwargs)

If forgot to ask what kwargs is doing here? Can we default to {}?
Otherwise let's drop it for now since there are no options defined yet.

It's used later in the patch adding dtrace support. I just thought it would be better to maintain the interface of 'tracetool.generate' instead of adding new parameters later when necessary.

Lluis

Signature · 4 lines
 "And it's much the same thing with knowledge, for whenever you learn
 something new, the whole world becomes that much richer."
 -- The Princess of Pure Reason, as told by Norton Juster in The Phantom
 Tollbooth
#4 lore raw

Re: [Qemu-devel] [RFC PATCH v3 1/8] tracetool: Rewrite infrastructure as python modules

Quoted 6 lines · Lluís Vilanova
Quoted 4 lines · Stefan Hajnoczi
Quoted 4 lines
scripts/tracetool.py new file +4 -0
+    kwargs = {}
+
+    try:
+        tracetool.generate(sys.stdin, arg_format, arg_backend, **kwargs)
Quoted 6 lines
Quoted 2 lines

If forgot to ask what kwargs is doing here? Can we default to {}?
Otherwise let's drop it for now since there are no options defined yet.

It's used later in the patch adding dtrace support. I just thought it would be better to maintain the interface of 'tracetool.generate' instead of adding new parameters later when necessary.

Thanks for pointing that out. I went back to look at how the dtrace-specific options get passed in. I noticed you assigned them directly to dtrace.py module variables - probably because you didn't want to add the (mostly unused) kwargs argument to all code generation functions?

For now I think this is okay since most backends don't care about kwargs. If we need it more maybe we should think of a cleaner solution.

Stefan

#5 lore raw

Re: [Qemu-devel] [RFC PATCH v3 1/8] tracetool: Rewrite infrastructure as python modules

Quoted 14 lines · Stefan Hajnoczi
Quoted 6 lines · Lluís Vilanova
Quoted 4 lines · Stefan Hajnoczi
Quoted 4 lines
scripts/tracetool.py new file +4 -0
+    kwargs = {}
+
+    try:
+        tracetool.generate(sys.stdin, arg_format, arg_backend, **kwargs)
Quoted 6 lines
Quoted 2 lines

If forgot to ask what kwargs is doing here? Can we default to {}?
Otherwise let's drop it for now since there are no options defined yet.

It's used later in the patch adding dtrace support. I just thought it would be better to maintain the interface of 'tracetool.generate' instead of adding new parameters later when necessary.

Quoted 8 lines

Thanks for pointing that out. I went back to look at how the dtrace-specific options get passed in. I noticed you assigned them directly to dtrace.py module variables - probably because you didn't want to add the (mostly unused) kwargs argument to all code generation functions?

For now I think this is okay since most backends don't care about kwargs. If we need it more maybe we should think of a cleaner solution.

Exactly. Using the kwargs approach all over the place would do the job, but right now there are only two of these arguments, which looks manageable using explicit arguments (since v4).

Lluis

Signature · 4 lines
 "And it's much the same thing with knowledge, for whenever you learn
 something new, the whole world becomes that much richer."
 -- The Princess of Pure Reason, as told by Norton Juster in The Phantom
 Tollbooth
#6 lore raw

RFC PATCH v3 2/8 tracetool: Add module for the 'c' format

In reply to Lluís Vilanova
---
 scripts/tracetool/format/c.py |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
 create mode 100644 scripts/tracetool/format/c.py
scripts/tracetool/format/c.py new file +20 -0
new file mode 100644
index 0000000..35555ae
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+Generate .c file.
+"""
+
+__author__     = "Lluís Vilanova <[email protected]>"
+__copyright__  = "Copyright 2012, Lluís Vilanova <[email protected]>"
+__license__    = "GPL version 2 or (at your option) any later version"
+
+__maintainer__ = "Stefan Hajnoczi"
+__email__      = "[email protected]"
+
+
+from tracetool import out
+
+
+def begin(events):
+    out('/* This file is autogenerated by tracetool, do not edit. */')
#7 lore raw

RFC PATCH v3 3/8 tracetool: Add module for the 'h' format

In reply to Lluís Vilanova
---
 scripts/tracetool/format/h.py |   45 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)
 create mode 100644 scripts/tracetool/format/h.py
scripts/tracetool/format/h.py new file +45 -0
new file mode 100644
index 0000000..41a3e2b
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+Generate .h file.
+"""
+
+__author__     = "Lluís Vilanova <[email protected]>"
+__copyright__  = "Copyright 2012, Lluís Vilanova <[email protected]>"
+__license__    = "GPL version 2 or (at your option) any later version"
+
+__maintainer__ = "Stefan Hajnoczi"
+__email__      = "[email protected]"
+
+
+from tracetool import out
+
+
+def begin(events):
+    out('/* This file is autogenerated by tracetool, do not edit. */',
+        '',
+        '#ifndef TRACE_H',
+        '#define TRACE_H',
+        '',
+        '#include "qemu-common.h"')
+
+def end(events):
+    for e in events:
+        if "disable" in e.properties:
+            enabled = 0
+        else:
+            enabled = 1
+        out('#define TRACE_%s_ENABLED %d' % (e.name.upper(), enabled))
+    out('',
+        '#endif /* TRACE_H */')
+
+def nop(events):
+    for e in events:
+        out('',
+            'static inline void trace_%(name)s(%(args)s)' % {
+                'name': e.name,
+                'args': e.args
+                },
+            '{',
+            '}')
#8 lore raw

RFC PATCH v3 4/8 tracetool: Add support for the 'stderr' backend

In reply to Lluís Vilanova
---
 scripts/tracetool/backend/stderr.py |   61 +++++++++++++++++++++++++++++++++++
 1 files changed, 61 insertions(+), 0 deletions(-)
 create mode 100644 scripts/tracetool/backend/stderr.py
scripts/tracetool/backend/stderr.py new file +61 -0
new file mode 100644
index 0000000..5f9abcd
@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+Stderr built-in backend.
+"""
+
+__author__     = "Lluís Vilanova <[email protected]>"
+__copyright__  = "Copyright 2012, Lluís Vilanova <[email protected]>"
+__license__    = "GPL version 2 or (at your option) any later version"
+
+__maintainer__ = "Stefan Hajnoczi"
+__email__      = "[email protected]"
+
+
+from tracetool import out
+
+
+PUBLIC = True
+
+
+def c(events):
+    out('#include "trace.h"',
+        '',
+        'TraceEvent trace_list[] = {')
+
+    for e in events:
+        out('{.tp_name = "%(name)s", .state=0},' %
+            {
+                'name': e.name,
+                })
+
+    out('};')
+
+def h(events):
+    out('#include <stdio.h>',
+        '#include "trace/stderr.h"',
+        '',
+        'extern TraceEvent trace_list[];')
+
+    for num, e in enumerate(events):
+        argnames = ", ".join(e.args.names())
+        if len(e.args) > 0:
+            argnames = ", " + argnames
+
+        out('''
+static inline void trace_%(name)s(%(args)s)
+{
+    if (trace_list[%(event_num)s].state != 0) {
+        fprintf(stderr, "%(name)s " %(fmt)s "\\n" %(argnames)s);
+    }
+}''' % {
+                'name': e.name,
+                'args': e.args,
+                'event_num': num,
+                'fmt': e.fmt,
+                'argnames': argnames,
+                })
+
+    out('',
+        '#define NR_TRACE_EVENTS %d' % len(events))
#9 lore raw

RFC PATCH v3 5/8 tracetool: Add support for the 'simple' backend

In reply to Lluís Vilanova
---
 scripts/tracetool/backend/simple.py |   60 +++++++++++++++++++++++++++++++++++
 1 files changed, 60 insertions(+), 0 deletions(-)
 create mode 100644 scripts/tracetool/backend/simple.py
scripts/tracetool/backend/simple.py new file +60 -0
new file mode 100644
index 0000000..fea0a37
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+Simple built-in backend.
+"""
+
+__author__     = "Lluís Vilanova <[email protected]>"
+__copyright__  = "Copyright 2012, Lluís Vilanova <[email protected]>"
+__license__    = "GPL version 2 or (at your option) any later version"
+
+__maintainer__ = "Stefan Hajnoczi"
+__email__      = "[email protected]"
+
+
+from tracetool import out
+
+
+PUBLIC = True
+
+
+def c(events):
+    out('#include "trace.h"',
+        '',
+        'TraceEvent trace_list[] = {')
+
+    for e in events:
+        out('{.tp_name = "%(name)s", .state=0},' % {
+                'name': e.name,
+                })
+
+    out('};')
+
+def h(events):
+    out('#include "trace/simple.h"',
+        '')
+
+    for num, e in enumerate(events):
+        if len(e.args):
+            argstr = e.args.names()
+            arg_prefix = ', (uint64_t)(uintptr_t)'
+            cast_args = arg_prefix + arg_prefix.join(argstr)
+            simple_args = (str(num) + cast_args)
+        else:
+            simple_args = str(num)
+
+        out('''\
+static inline void trace_%(name)s(%(args)s)
+{
+    trace%(argc)d(%(trace_args)s);
+}
+''' % {
+                'name': e.name,
+                'args': e.args,
+                'argc': len(e.args),
+                'trace_args': simple_args,
+                })
+
+    out('#define NR_TRACE_EVENTS %d' % len(events))
+    out('extern TraceEvent trace_list[NR_TRACE_EVENTS];')
#10 lore raw

RFC PATCH v3 6/8 tracetool: Add support for the 'ust' backend

In reply to Lluís Vilanova
---
 scripts/tracetool/backend/ust.py |  102 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 102 insertions(+), 0 deletions(-)
 create mode 100644 scripts/tracetool/backend/ust.py
scripts/tracetool/backend/ust.py new file +102 -0
new file mode 100644
index 0000000..6871373
@@ -0,0 +1,102 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+LTTng User Space Tracing backend.
+"""
+
+__author__     = "Lluís Vilanova <[email protected]>"
+__copyright__  = "Copyright 2012, Lluís Vilanova <[email protected]>"
+__license__    = "GPL version 2 or (at your option) any later version"
+
+__maintainer__ = "Stefan Hajnoczi"
+__email__      = "[email protected]"
+
+
+from tracetool import out
+
+
+PUBLIC = True
+
+
+def c(events):
+    out('#include <ust/marker.h>',
+        '#undef mutex_lock',
+        '#undef mutex_unlock',
+        '#undef inline',
+        '#undef wmb',
+        '#include "trace.h"')
+
+    for e in events:
+        argnames = ", ".join(e.args.names())
+        if len(e.args) > 0:
+            argnames = ', ' + argnames
+
+            out('''
+DEFINE_TRACE(ust_%(name)s);
+
+static void ust_%(name)s_probe(%(args)s)
+{
+    trace_mark(ust, %(name)s, %(fmt)s%(argnames)s);
+}''' %
+                {
+                    'name': e.name,
+                    'args': e.args,
+                    'fmt': e.fmt,
+                    'argnames': argnames,
+                    })
+
+        else:
+            out('''
+DEFINE_TRACE(ust_%(name)s);
+
+static void ust_%(name)s_probe(%(args)s)
+{
+    trace_mark(ust, %(name)s, UST_MARKER_NOARGS);
+}''' %
+                {
+                    'name': e.name,
+                    'args': e.args,
+                    })
+
+    # register probes
+    out('',
+        'static void __attribute__((constructor)) trace_init(void)',
+        '{')
+
+    for e in events:
+        out('    register_trace_ust_%(name)s(ust_%(name)s_probe);' %
+            {
+                'name': e.name,
+                })
+
+    out('}')
+
+
+def h(events):
+    out('#include <ust/tracepoint.h>',
+        '#undef mutex_lock',
+        '#undef mutex_unlock',
+        '#undef inline',
+        '#undef wmb')
+
+    for e in events:
+        if len(e.args) > 0:
+            out('''
+DECLARE_TRACE(ust_%(name)s, TP_PROTO(%(args)s), TP_ARGS(%(argnames)s));
+#define trace_%(name)s trace_ust_%(name)s''' %
+                {
+                    'name': e.name,
+                    'args': e.args,
+                    'argnames': ", ".join(e.args.names())
+                    })
+
+        else:
+            out('''
+_DECLARE_TRACEPOINT_NOARGS(ust_%(name)s);
+#define trace_%(name)s trace_ust_%(name)s''' %
+                {
+                    'name': e.name,
+                    })
+
+    out()
#11 lore raw

RFC PATCH v3 7/8 tracetool: Add support for the 'dtrace' backend

In reply to Lluís Vilanova
---
 scripts/tracetool.py                |   31 ++++++++++
 scripts/tracetool/__init__.py       |    8 +++
 scripts/tracetool/backend/dtrace.py |  104 +++++++++++++++++++++++++++++++++++
 scripts/tracetool/format/d.py       |   20 +++++++
 scripts/tracetool/format/stap.py    |   20 +++++++
 5 files changed, 183 insertions(+), 0 deletions(-)
 create mode 100644 scripts/tracetool/backend/dtrace.py
 create mode 100644 scripts/tracetool/format/d.py
 create mode 100644 scripts/tracetool/format/stap.py
scripts/tracetool.py +31 -0
index 70bf79a..eeba1e0 100755
@@ -44,6 +44,11 @@ Options:
     --help                   This help message.
     --list-backends          Print list of available backends.
     --check-backend          Check if the given backend is valid.
+    --binary <path>          Full path to QEMU binary.
+    --target-type <type>     QEMU emulator target type ('system' or 'user').
+    --target-arch <arch>     QEMU emulator target arch.
+    --probe-prefix <prefix>  Prefix for dtrace probe names
+                             (default: qemu-<target-type>-<target-arch>).\
 """ % {
             "script" : _SCRIPT,
             "backends" : backend_descr,
@@ -71,6 +76,10 @@ def main(args):
     check_backend = False
     arg_backend = ""
     arg_format = ""
+    binary = None
+    target_type = None
+    target_arch = None
+    probe_prefix = None
     for opt, arg in opts:
         if opt == "--help":
             error_opt()
@@ -87,6 +96,15 @@ def main(args):
         elif opt == "--check-backend":
             check_backend = True
 
+        elif opt == "--binary":
+            binary = arg
+        elif opt == '--target-type':
+            target_type = arg
+        elif opt == '--target-arch':
+            target_arch = arg
+        elif opt == '--probe-prefix':
+            probe_prefix = arg
+
         else:
             error_opt("unhandled option: %s" % opt)
 
@@ -101,6 +119,19 @@ def main(args):
 
     kwargs = {}
 
+    if arg_format == "stap":
+        if binary is None:
+            error_opt("--binary is required for SystemTAP tapset generator")
+        if probe_prefix is None and target_type is None:
+            error_opt("--target-type is required for SystemTAP tapset generator")
+        if probe_prefix is None and target_arch is None:
+            error_opt("--target-arch is required for SystemTAP tapset generator")
+
+        if probe_prefix is None:
+            probe_prefix = ".".join([ "qemu", target_type, target_arch ])
+    kwargs["binary"] = binary
+    kwargs["probe_prefix"] = probe_prefix
+
     try:
         tracetool.generate(sys.stdin, arg_format, arg_backend, **kwargs)
     except tracetool.TracetoolError as e:
scripts/tracetool/__init__.py +8 -0
index 955b6b8..c22f167 100644
@@ -177,6 +177,9 @@ def generate(fevents, format, backend, **options):
     # fix strange python error (UnboundLocalError tracetool)
     import tracetool
 
+    binary = options.pop("binary", None)
+    probe_prefix = options.pop("probe_prefix", None)
+
     if len(options) > 0:
         raise ValueError("unknown options: " + ", ".join(options))
 
@@ -198,6 +201,11 @@ def generate(fevents, format, backend, **options):
         raise TracetoolError("backend '%s' not compatible with format '%s'" %
                              (backend, format))
 
+    if backend == "dtrace":
+        import tracetool.backend.dtrace
+        tracetool.backend.dtrace.BINARY = binary
+        tracetool.backend.dtrace.PROBEPREFIX = probe_prefix
+
     events = _read_events(fevents)
 
     if backend == "nop":
scripts/tracetool/backend/dtrace.py new file +104 -0

104 lines not on this page · raw message

scripts/tracetool/format/d.py new file +20 -0
new file mode 100644
index 0000000..a2d5947
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+Generate .d file (DTrace only).
+"""
+
+__author__     = "Lluís Vilanova <[email protected]>"
+__copyright__  = "Copyright 2012, Lluís Vilanova <[email protected]>"
+__license__    = "GPL version 2 or (at your option) any later version"
+
+__maintainer__ = "Stefan Hajnoczi"
+__email__      = "[email protected]"
+
+
+from tracetool import out
+
+
+def begin(events):
+    out('/* This file is autogenerated by tracetool, do not edit. */')
scripts/tracetool/format/stap.py new file +20 -0
new file mode 100644
index 0000000..50a4c69
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+Generate .stp file (DTrace with SystemTAP only).
+"""
+
+__author__     = "Lluís Vilanova <[email protected]>"
+__copyright__  = "Copyright 2012, Lluís Vilanova <[email protected]>"
+__license__    = "GPL version 2 or (at your option) any later version"
+
+__maintainer__ = "Stefan Hajnoczi"
+__email__      = "[email protected]"
+
+
+from tracetool import out
+
+
+def begin(events):
+    out('/* This file is autogenerated by tracetool, do not edit. */')
#12 lore raw

RFC PATCH v3 8/8 tracetool: Add MAINTAINERS info

In reply to Lluís Vilanova
---
 MAINTAINERS |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
MAINTAINERS +2 -0
index f83d07c2..0e66dd8 100644
@@ -548,6 +548,8 @@ Tracing
 M: Stefan Hajnoczi <[email protected]>
 S: Maintained
 F: trace/
+F: scripts/tracetool.py
+F: scripts/tracetool/
 F: docs/tracing.txt
 T: git://github.com/stefanha/qemu.git tracing
 
#13 lore raw
In reply to Lluís Vilanova
Quoted 59 lines · Lluís Vilanova

A full rewrite of the tracetool script using per-format and per-backend modules, so that it's easier to read and extend it in the future.

---
NOTE: This series applies in current master, ignoring the "Rewrite tracetool
using python" series.

Changes in v3:

* Some minor fixes according to comments from Alon Levy:
** Fixed some rogue tabs.
** Fixed definition of '_SCRIPT' in "tracetool.py".
** Fixed some documentation.
** Defensively treat results from 'try_import' in 'get_list'. ** Fixed the no-arguments case in 'tracetool.backend.dtrace.d'. ** Fixed the commandline checks for the "stap" format. ** Added '__repr__' methods for both Event and Arguments objects.

Changes in v2:

* Fixed a strange import error.
* Add a pointer to 'tracetool.out' in the format and backend documentation.

Lluís Vilanova (8):
tracetool: Rewrite infrastructure as python modules
tracetool: Add module for the 'c' format
tracetool: Add module for the 'h' format
tracetool: Add support for the 'stderr' backend
tracetool: Add support for the 'simple' backend
tracetool: Add support for the 'ust' backend
tracetool: Add support for the 'dtrace' backend
tracetool: Add MAINTAINERS info

 MAINTAINERS                           |    2 
 Makefile.objs                         |    6 
 Makefile.target                       |   13 -
 configure                             |    4 
 scripts/tracetool                     |  648 ---------------------------------
 scripts/tracetool.py                  |  141 +++++++
 scripts/tracetool/__init__.py         |  223 +++++++++++
 scripts/tracetool/backend/__init__.py |  119 ++++++
 scripts/tracetool/backend/dtrace.py   |  104 +++++
 scripts/tracetool/backend/simple.py   |   60 +++
 scripts/tracetool/backend/stderr.py   |   61 +++
 scripts/tracetool/backend/ust.py      |  102 +++++
 scripts/tracetool/format/__init__.py  |   96 +++++
 scripts/tracetool/format/c.py         |   20 +
 scripts/tracetool/format/d.py         |   20 +
 scripts/tracetool/format/h.py         |   45 ++
 scripts/tracetool/format/stap.py      |   20 +
 17 files changed, 1025 insertions(+), 659 deletions(-)
 delete mode 100755 scripts/tracetool
 create mode 100755 scripts/tracetool.py
 create mode 100644 scripts/tracetool/__init__.py
 create mode 100644 scripts/tracetool/backend/__init__.py
 create mode 100644 scripts/tracetool/backend/dtrace.py
Quoted 8 lines
 create mode 100644 scripts/tracetool/backend/simple.py
 create mode 100644 scripts/tracetool/backend/stderr.py
 create mode 100644 scripts/tracetool/backend/ust.py
 create mode 100644 scripts/tracetool/format/__init__.py
 create mode 100644 scripts/tracetool/format/c.py
 create mode 100644 scripts/tracetool/format/d.py
 create mode 100644 scripts/tracetool/format/h.py
 create mode 100644 scripts/tracetool/format/stap.py

Only one point: please don't introduce PUBLIC yet. Let's add it when it's needed. At the moment nothing uses it.

I have tested this series with all backends and looked at the diff between the old tracetool and tracetool.py.

I'm happy with this series. We need to test it hard for 1.1 to make sure there are no hickups for tracing users.

Stefan

#14 lore raw
Quoted 8 lines · Stefan Hajnoczi

Only one point: please don't introduce PUBLIC yet. Let's add it when it's needed. At the moment nothing uses it.

I have tested this series with all backends and looked at the diff between the old tracetool and tracetool.py.

I'm happy with this series. We need to test it hard for 1.1 to make sure there are no hickups for tracing users.

Sure. I'll send v4 without the PUBLIC-related contents and turning "kwargs" into specific arguments.

Once accepted, I'll send the first two batches of changes in my queue, which are orthogonal to instrumentation (basically tracing cleanups in both the build and the API).

I suppose everyone prefers to wait until after the 1.1 release to start having a look at instrumentation (which I still have to port to this new tracetool).

Lluis

Signature · 4 lines
 "And it's much the same thing with knowledge, for whenever you learn
 something new, the whole world becomes that much richer."
 -- The Princess of Pure Reason, as told by Norton Juster in The Phantom
 Tollbooth
#15 lore raw
Quoted 13 lines · Lluís Vilanova
Quoted 8 lines · Stefan Hajnoczi

Only one point: please don't introduce PUBLIC yet. Let's add it when it's needed. At the moment nothing uses it.

I have tested this series with all backends and looked at the diff between the old tracetool and tracetool.py.

I'm happy with this series. We need to test it hard for 1.1 to make sure there are no hickups for tracing users.

Sure. I'll send v4 without the PUBLIC-related contents and turning "kwargs" into specific arguments.

Quoted 6 lines

Once accepted, I'll send the first two batches of changes in my queue, which are orthogonal to instrumentation (basically tracing cleanups in both the build and the API).

I suppose everyone prefers to wait until after the 1.1 release to start having a look at instrumentation (which I still have to port to this new tracetool).

Great. I'd like to merge the Python tracetool for 1.1. I've diffed the generated code and it appears compatible with the shell tracetool output. Therefore I'm pretty confident with this series.

Future series will not make it into 1.1 just because we're running out of time to review and test.

Stefan

#16 lore raw
Quoted 21 lines · Stefan Hajnoczi
Quoted 13 lines · Lluís Vilanova
Quoted 8 lines · Stefan Hajnoczi

Only one point: please don't introduce PUBLIC yet. Let's add it when it's needed. At the moment nothing uses it.

I have tested this series with all backends and looked at the diff between the old tracetool and tracetool.py.

I'm happy with this series. We need to test it hard for 1.1 to make sure there are no hickups for tracing users.

Sure. I'll send v4 without the PUBLIC-related contents and turning "kwargs" into specific arguments.

Quoted 6 lines

Once accepted, I'll send the first two batches of changes in my queue, which are orthogonal to instrumentation (basically tracing cleanups in both the build and the API).

I suppose everyone prefers to wait until after the 1.1 release to start having a look at instrumentation (which I still have to port to this new tracetool).

Quoted 6 lines

Great. I'd like to merge the Python tracetool for 1.1. I've diffed the generated code and it appears compatible with the shell tracetool output. Therefore I'm pretty confident with this series.

Future series will not make it into 1.1 just because we're running out of time to review and test.

Do you mean future versions of this series (e.g., v5) or just other series?

Thanks,
Lluis

Signature · 4 lines
 "And it's much the same thing with knowledge, for whenever you learn
 something new, the whole world becomes that much richer."
 -- The Princess of Pure Reason, as told by Norton Juster in The Phantom
 Tollbooth
#17 lore raw
Quoted 23 lines · Lluís Vilanova
Quoted 20 lines · Stefan Hajnoczi
Quoted 19 lines · Lluís Vilanova
Quoted 8 lines · Stefan Hajnoczi

Only one point: please don't introduce PUBLIC yet.  Let's add it when it's needed.  At the moment nothing uses it.

I have tested this series with all backends and looked at the diff between the old tracetool and tracetool.py.

I'm happy with this series.  We need to test it hard for 1.1 to make sure there are no hickups for tracing users.

Sure. I'll send v4 without the PUBLIC-related contents and turning "kwargs" into specific arguments.

Once accepted, I'll send the first two batches of changes in my queue, which are orthogonal to instrumentation (basically tracing cleanups in both the build and the API).

I suppose everyone prefers to wait until after the 1.1 release to start having a look at instrumentation (which I still have to port to this new tracetool).

Quoted 8 lines
Quoted 6 lines

Great.  I'd like to merge the Python tracetool for 1.1.  I've diffed the generated code and it appears compatible with the shell tracetool output.  Therefore I'm pretty confident with this series.

Future series will not make it into 1.1 just because we're running out of time to review and test.

Do you mean future versions of this series (e.g., v5) or just other series?

Just other series :). I would definitely like to get this one in for 1.1.

Stefan