diff options
Diffstat (limited to 'scripts/tracetool/format')
-rw-r--r-- | scripts/tracetool/format/__init__.py | 46 | ||||
-rw-r--r-- | scripts/tracetool/format/c.py | 12 | ||||
-rw-r--r-- | scripts/tracetool/format/d.py | 26 | ||||
-rw-r--r-- | scripts/tracetool/format/events_c.py | 11 | ||||
-rw-r--r-- | scripts/tracetool/format/events_h.py | 11 | ||||
-rw-r--r-- | scripts/tracetool/format/h.py | 24 | ||||
-rw-r--r-- | scripts/tracetool/format/stap.py | 42 | ||||
-rw-r--r-- | scripts/tracetool/format/ust_events_c.py | 5 | ||||
-rw-r--r-- | scripts/tracetool/format/ust_events_h.py | 40 |
9 files changed, 152 insertions, 65 deletions
diff --git a/scripts/tracetool/format/__init__.py b/scripts/tracetool/format/__init__.py index 2bbbba7011..812570ff6f 100644 --- a/scripts/tracetool/format/__init__.py +++ b/scripts/tracetool/format/__init__.py @@ -20,17 +20,12 @@ All formats must generate their contents through the 'tracetool.out' routine. Format functions ---------------- -All the following functions are optional, and no output will be generated if -they do not exist. - -======== ======================================================================= +======== ================================================================== Function Description -======== ======================================================================= -begin Called to generate the format-specific file header. -end Called to generate the format-specific file footer. -nop Called to generate the per-event contents when the event is disabled or - the selected backend is 'nop'. -======== ======================================================================= +======== ================================================================== +generate Called to generate a format-specific file. +======== ================================================================== + """ __author__ = "Lluís Vilanova <vilanova@ac.upc.edu>" @@ -79,25 +74,12 @@ def exists(name): return tracetool.try_import("tracetool.format." + name)[1] -def _empty(events): - pass - -def generate_begin(name, events): - """Generate the header of the format-specific file.""" - if not exists(name): - raise ValueError("unknown format: %s" % name) - - name = name.replace("-", "_") - func = tracetool.try_import("tracetool.format." + name, - "begin", _empty)[1] - func(events) - -def generate_end(name, events): - """Generate the footer of the format-specific file.""" - if not exists(name): - raise ValueError("unknown format: %s" % name) - - name = name.replace("-", "_") - func = tracetool.try_import("tracetool.format." + name, - "end", _empty)[1] - func(events) +def generate(events, format, backend): + if not exists(format): + raise ValueError("unknown format: %s" % format) + format = format.replace("-", "_") + func = tracetool.try_import("tracetool.format." + format, + "generate")[1] + if func is None: + raise AttributeError("format has no 'generate': %s" % format) + func(events, backend) diff --git a/scripts/tracetool/format/c.py b/scripts/tracetool/format/c.py index 930140b020..699598fb02 100644 --- a/scripts/tracetool/format/c.py +++ b/scripts/tracetool/format/c.py @@ -16,5 +16,13 @@ __email__ = "stefanha@linux.vnet.ibm.com" from tracetool import out -def begin(events): - out('/* This file is autogenerated by tracetool, do not edit. */') +def generate(events, backend): + events = [e for e in events + if "disable" not in e.properties] + + out('/* This file is autogenerated by tracetool, do not edit. */', + '') + backend.generate_begin(events) + for event in events: + backend.generate(event) + backend.generate_end(events) diff --git a/scripts/tracetool/format/d.py b/scripts/tracetool/format/d.py index 74ee0d3626..46eebb128b 100644 --- a/scripts/tracetool/format/d.py +++ b/scripts/tracetool/format/d.py @@ -16,5 +16,27 @@ __email__ = "stefanha@linux.vnet.ibm.com" from tracetool import out -def begin(events): - out('/* This file is autogenerated by tracetool, do not edit. */') +def generate(events, backend): + events = [e for e in events + if "disable" not in e.properties] + + out('/* This file is autogenerated by tracetool, do not edit. */' + '', + 'provider qemu {') + + for e in events: + args = str(e.args) + + # DTrace provider syntax expects foo() for empty + # params, not foo(void) + if args == 'void': + args = '' + + # Define prototype for probe arguments + out('', + 'probe %(name)s(%(args)s);', + name=e.name, + args=args) + + out('', + '};') diff --git a/scripts/tracetool/format/events_c.py b/scripts/tracetool/format/events_c.py index ea668ee099..2d97fa310a 100644 --- a/scripts/tracetool/format/events_c.py +++ b/scripts/tracetool/format/events_c.py @@ -16,14 +16,13 @@ __email__ = "stefanha@linux.vnet.ibm.com" from tracetool import out -def begin(events): +def generate(events, backend): out('/* This file is autogenerated by tracetool, do not edit. */', '', '#include "trace.h"', '#include "trace/generated-events.h"', '#include "trace/control.h"', - '', - ) + '') out('TraceEvent trace_events[TRACE_EVENT_COUNT] = {') @@ -31,9 +30,7 @@ def begin(events): out(' { .id = %(id)s, .name = \"%(name)s\", .sstate = %(sstate)s, .dstate = 0 },', id = "TRACE_" + e.name.upper(), name = e.name, - sstate = "TRACE_%s_ENABLED" % e.name.upper(), - ) + sstate = "TRACE_%s_ENABLED" % e.name.upper()) out('};', - '', - ) + '') diff --git a/scripts/tracetool/format/events_h.py b/scripts/tracetool/format/events_h.py index f3febae937..25d913bb25 100644 --- a/scripts/tracetool/format/events_h.py +++ b/scripts/tracetool/format/events_h.py @@ -16,15 +16,14 @@ __email__ = "stefanha@linux.vnet.ibm.com" from tracetool import out -def begin(events): +def generate(events, backend): out('/* This file is autogenerated by tracetool, do not edit. */', '', '#ifndef TRACE__GENERATED_EVENTS_H', '#define TRACE__GENERATED_EVENTS_H', '', '#include <stdbool.h>', - '' - ) + '') # event identifiers out('typedef enum {') @@ -33,8 +32,7 @@ def begin(events): out(' TRACE_%s,' % e.name.upper()) out(' TRACE_EVENT_COUNT', - '} TraceEventID;', - ) + '} TraceEventID;') # static state for e in events: @@ -46,5 +44,4 @@ def begin(events): out('#include "trace/event-internal.h"', '', - '#endif /* TRACE__GENERATED_EVENTS_H */', - ) + '#endif /* TRACE__GENERATED_EVENTS_H */') diff --git a/scripts/tracetool/format/h.py b/scripts/tracetool/format/h.py index 85f011f76b..9b3943002c 100644 --- a/scripts/tracetool/format/h.py +++ b/scripts/tracetool/format/h.py @@ -16,23 +16,29 @@ __email__ = "stefanha@linux.vnet.ibm.com" from tracetool import out -def begin(events): +def generate(events, backend): out('/* This file is autogenerated by tracetool, do not edit. */', '', '#ifndef TRACE__GENERATED_TRACERS_H', '#define TRACE__GENERATED_TRACERS_H', '', - '#include "qemu-common.h"') + '#include "qemu-common.h"', + '') -def end(events): - out('#endif /* TRACE__GENERATED_TRACERS_H */') + backend.generate_begin(events) -def nop(events): for e in events: out('', 'static inline void %(api)s(%(args)s)', '{', - '}', - api = e.api(), - args = e.args, - ) + api=e.api(), + args=e.args) + + if "disable" not in e.properties: + backend.generate(e) + + out('}') + + backend.generate_end(events) + + out('#endif /* TRACE__GENERATED_TRACERS_H */') diff --git a/scripts/tracetool/format/stap.py b/scripts/tracetool/format/stap.py index 50a4c69954..e24abf7f11 100644 --- a/scripts/tracetool/format/stap.py +++ b/scripts/tracetool/format/stap.py @@ -6,7 +6,7 @@ Generate .stp file (DTrace with SystemTAP only). """ __author__ = "Lluís Vilanova <vilanova@ac.upc.edu>" -__copyright__ = "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>" +__copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>" __license__ = "GPL version 2 or (at your option) any later version" __maintainer__ = "Stefan Hajnoczi" @@ -14,7 +14,43 @@ __email__ = "stefanha@linux.vnet.ibm.com" from tracetool import out +from tracetool.backend.dtrace import binary, probeprefix -def begin(events): - out('/* This file is autogenerated by tracetool, do not edit. */') +# Technically 'self' is not used by systemtap yet, but +# they recommended we keep it in the reserved list anyway +RESERVED_WORDS = ( + 'break', 'catch', 'continue', 'delete', 'else', 'for', + 'foreach', 'function', 'global', 'if', 'in', 'limit', + 'long', 'next', 'probe', 'return', 'self', 'string', + 'try', 'while' + ) + + +def generate(events, backend): + events = [e for e in events + if "disable" not in e.properties] + + out('/* This file is autogenerated by tracetool, do not edit. */', + '') + + for e in events: + # Define prototype for probe arguments + out('probe %(probeprefix)s.%(name)s = process("%(binary)s").mark("%(name)s")', + '{', + probeprefix=probeprefix(), + name=e.name, + binary=binary()) + + i = 1 + if len(e.args) > 0: + for name in e.args.names(): + # Append underscore to reserved keywords + if name in RESERVED_WORDS: + name += '_' + out(' %s = $arg%d;' % (name, i)) + i += 1 + + out('}') + + out() diff --git a/scripts/tracetool/format/ust_events_c.py b/scripts/tracetool/format/ust_events_c.py index d048b0a551..bc970936be 100644 --- a/scripts/tracetool/format/ust_events_c.py +++ b/scripts/tracetool/format/ust_events_c.py @@ -16,7 +16,10 @@ __email__ = "stefanha@redhat.com" from tracetool import out -def begin(events): +def generate(events, backend): + events = [e for e in events + if "disabled" not in e.properties] + out('/* This file is autogenerated by tracetool, do not edit. */', '', '#define TRACEPOINT_DEFINE', diff --git a/scripts/tracetool/format/ust_events_h.py b/scripts/tracetool/format/ust_events_h.py index a3ef7859e6..5102565470 100644 --- a/scripts/tracetool/format/ust_events_h.py +++ b/scripts/tracetool/format/ust_events_h.py @@ -16,7 +16,10 @@ __email__ = "stefanha@redhat.com" from tracetool import out -def begin(events): +def generate(events, backend): + events = [e for e in events + if "disabled" not in e.properties] + out('/* This file is autogenerated by tracetool, do not edit. */', '', '#undef TRACEPOINT_PROVIDER', @@ -50,7 +53,40 @@ def begin(events): '#endif', '') -def end(events): + for e in events: + if len(e.args) > 0: + out('TRACEPOINT_EVENT(', + ' qemu,', + ' %(name)s,', + ' TP_ARGS(%(args)s),', + ' TP_FIELDS(', + name=e.name, + args=", ".join(", ".join(i) for i in e.args)) + + for t, n in e.args: + if ('int' in t) or ('long' in t) or ('unsigned' in t) or ('size_t' in t): + out(' ctf_integer(' + t + ', ' + n + ', ' + n + ')') + elif ('double' in t) or ('float' in t): + out(' ctf_float(' + t + ', ' + n + ', ' + n + ')') + elif ('char *' in t) or ('char*' in t): + out(' ctf_string(' + n + ', ' + n + ')') + elif ('void *' in t) or ('void*' in t): + out(' ctf_integer_hex(unsigned long, ' + n + ', ' + n + ')') + + out(' )', + ')', + '') + + else: + out('TRACEPOINT_EVENT(', + ' qemu,', + ' %(name)s,', + ' TP_ARGS(void),', + ' TP_FIELDS()', + ')', + '', + name=e.name) + out('#endif /* TRACE__GENERATED_UST_H */', '', '/* This part must be outside ifdef protection */', |