diff options
Diffstat (limited to 'scripts/tracetool/format')
-rw-r--r-- | scripts/tracetool/format/__init__.py | 50 | ||||
-rw-r--r-- | scripts/tracetool/format/c.py | 16 | ||||
-rw-r--r-- | scripts/tracetool/format/d.py | 30 | ||||
-rw-r--r-- | scripts/tracetool/format/events_c.py | 15 | ||||
-rw-r--r-- | scripts/tracetool/format/events_h.py | 15 | ||||
-rw-r--r-- | scripts/tracetool/format/h.py | 30 | ||||
-rw-r--r-- | scripts/tracetool/format/stap.py | 42 | ||||
-rw-r--r-- | scripts/tracetool/format/ust_events_c.py | 7 | ||||
-rw-r--r-- | scripts/tracetool/format/ust_events_h.py | 42 |
9 files changed, 167 insertions, 80 deletions
diff --git a/scripts/tracetool/format/__init__.py b/scripts/tracetool/format/__init__.py index 3c2a0d89e0..812570ff6f 100644 --- a/scripts/tracetool/format/__init__.py +++ b/scripts/tracetool/format/__init__.py @@ -20,21 +20,16 @@ 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>" -__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" @@ -53,7 +48,7 @@ def get_list(): for filename in os.listdir(tracetool.format.__path__[0]): if filename.endswith('.py') and filename != '__init__.py': modnames.append(filename.rsplit('.', 1)[0]) - for modname in modnames: + for modname in sorted(modnames): module = tracetool.try_import("tracetool.format." + modname) # just in case; should never fail unless non-module files are put there @@ -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 35555aee1f..699598fb02 100644 --- a/scripts/tracetool/format/c.py +++ b/scripts/tracetool/format/c.py @@ -2,11 +2,11 @@ # -*- coding: utf-8 -*- """ -Generate .c file. +trace/generated-tracers.c """ __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" @@ -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 a2d594773c..46eebb128b 100644 --- a/scripts/tracetool/format/d.py +++ b/scripts/tracetool/format/d.py @@ -2,11 +2,11 @@ # -*- coding: utf-8 -*- """ -Generate .d file (DTrace only). +trace/generated-tracers.dtrace (DTrace 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" @@ -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 d670ec83d5..2d97fa310a 100644 --- a/scripts/tracetool/format/events_c.py +++ b/scripts/tracetool/format/events_c.py @@ -2,11 +2,11 @@ # -*- coding: utf-8 -*- """ -Generate .c for event description. +trace/generated-events.c """ __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" @@ -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 d30ccea8a1..25d913bb25 100644 --- a/scripts/tracetool/format/events_h.py +++ b/scripts/tracetool/format/events_h.py @@ -2,11 +2,11 @@ # -*- coding: utf-8 -*- """ -Generate .h for event description. +trace/generated-events.h """ __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" @@ -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 93132fceaf..9b3943002c 100644 --- a/scripts/tracetool/format/h.py +++ b/scripts/tracetool/format/h.py @@ -2,11 +2,11 @@ # -*- coding: utf-8 -*- """ -Generate .h file. +trace/generated-tracers.h """ __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" @@ -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 trace_%(name)s(%(args)s)', + 'static inline void %(api)s(%(args)s)', '{', - '}', - name = e.name, - 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 116e713225..bc970936be 100644 --- a/scripts/tracetool/format/ust_events_c.py +++ b/scripts/tracetool/format/ust_events_c.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- """ -Generate .c for LTTng ust event description. +trace/generated-ust.c """ __author__ = "Mohamad Gebai <mohamad.gebai@polymtl.ca>" @@ -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 f206eca6ec..5102565470 100644 --- a/scripts/tracetool/format/ust_events_h.py +++ b/scripts/tracetool/format/ust_events_h.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- """ -Generate .h for LTTng ust event description. +trace/generated-ust-provider.h """ __author__ = "Mohamad Gebai <mohamad.gebai@polymtl.ca>" @@ -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 */', |