diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/tracetool.py | 4 | ||||
-rw-r--r-- | scripts/tracetool/backend/__init__.py | 16 | ||||
-rw-r--r-- | scripts/tracetool/backend/dtrace.py | 3 | ||||
-rw-r--r-- | scripts/tracetool/backend/events.py | 23 | ||||
-rw-r--r-- | scripts/tracetool/backend/simple.py | 22 | ||||
-rw-r--r-- | scripts/tracetool/backend/stderr.py | 28 | ||||
-rw-r--r-- | scripts/tracetool/backend/ust.py | 3 | ||||
-rw-r--r-- | scripts/tracetool/format/events_c.py | 39 | ||||
-rw-r--r-- | scripts/tracetool/format/events_h.py | 50 | ||||
-rw-r--r-- | scripts/tracetool/format/h.py | 9 |
10 files changed, 155 insertions, 42 deletions
diff --git a/scripts/tracetool.py b/scripts/tracetool.py index c003cf69ed..a79ec0f096 100755 --- a/scripts/tracetool.py +++ b/scripts/tracetool.py @@ -90,8 +90,8 @@ def main(args): arg_format = arg elif opt == "--list-backends": - backends = tracetool.backend.get_list() - out(", ".join([ b for b,_ in 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 diff --git a/scripts/tracetool/backend/__init__.py b/scripts/tracetool/backend/__init__.py index be43472f7b..f0314ee376 100644 --- a/scripts/tracetool/backend/__init__.py +++ b/scripts/tracetool/backend/__init__.py @@ -17,6 +17,16 @@ considered its short description. All backends must generate their contents through the 'tracetool.out' routine. +Backend attributes +------------------ + +========= ==================================================================== +Attribute Description +========= ==================================================================== +PUBLIC If exists and is set to 'True', the backend is considered "public". +========= ==================================================================== + + Backend functions ----------------- @@ -42,7 +52,7 @@ import os import tracetool -def get_list(): +def get_list(only_public = False): """Get a list of (name, description) pairs.""" res = [("nop", "Tracing disabled.")] modnames = [] @@ -57,6 +67,10 @@ def get_list(): continue module = module[1] + public = getattr(module, "PUBLIC", False) + if only_public and not public: + continue + doc = module.__doc__ if doc is None: doc = "" diff --git a/scripts/tracetool/backend/dtrace.py b/scripts/tracetool/backend/dtrace.py index ad5eb3b0ab..e31bc799f8 100644 --- a/scripts/tracetool/backend/dtrace.py +++ b/scripts/tracetool/backend/dtrace.py @@ -16,6 +16,9 @@ __email__ = "stefanha@linux.vnet.ibm.com" from tracetool import out +PUBLIC = True + + PROBEPREFIX = None def _probeprefix(): diff --git a/scripts/tracetool/backend/events.py b/scripts/tracetool/backend/events.py new file mode 100644 index 0000000000..5afce3e8da --- /dev/null +++ b/scripts/tracetool/backend/events.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Generic event description. + +This is a dummy backend to establish appropriate frontend/backend compatibility +checks. +""" + +__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>" +__copyright__ = "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>" +__license__ = "GPL version 2 or (at your option) any later version" + +__maintainer__ = "Stefan Hajnoczi" +__email__ = "stefanha@linux.vnet.ibm.com" + + +def events_h(events): + pass + +def events_c(events): + pass diff --git a/scripts/tracetool/backend/simple.py b/scripts/tracetool/backend/simple.py index e4b4a7f05d..37ef599324 100644 --- a/scripts/tracetool/backend/simple.py +++ b/scripts/tracetool/backend/simple.py @@ -15,6 +15,10 @@ __email__ = "stefanha@linux.vnet.ibm.com" from tracetool import out + +PUBLIC = True + + def is_string(arg): strtype = ('const char*', 'char*', 'const char *', 'char *') if arg.lstrip().startswith(strtype): @@ -24,17 +28,10 @@ def is_string(arg): def c(events): out('#include "trace.h"', + '#include "trace/control.h"', '#include "trace/simple.h"', '', - 'TraceEvent trace_list[] = {') - - for e in events: - out('{.tp_name = "%(name)s", .state=0},', - name = e.name, - ) - - out('};', - '') + ) for num, event in enumerate(events): out('void trace_%(name)s(%(args)s)', @@ -59,7 +56,9 @@ def c(events): out('', - ' if (!trace_list[%(event_id)s].state) {', + ' TraceEvent *eventp = trace_event_id(%(event_id)s);', + ' bool _state = trace_event_get_state_dynamic(eventp);', + ' if (!_state) {', ' return;', ' }', '', @@ -102,6 +101,3 @@ def h(events): name = event.name, args = event.args, ) - out('') - out('#define NR_TRACE_EVENTS %d' % len(events)) - out('extern TraceEvent trace_list[NR_TRACE_EVENTS];') diff --git a/scripts/tracetool/backend/stderr.py b/scripts/tracetool/backend/stderr.py index 917fde7c15..6f93dbd1ae 100644 --- a/scripts/tracetool/backend/stderr.py +++ b/scripts/tracetool/backend/stderr.py @@ -16,41 +16,33 @@ __email__ = "stefanha@linux.vnet.ibm.com" from tracetool import out -def c(events): - out('#include "trace.h"', - '', - 'TraceEvent trace_list[] = {') +PUBLIC = True - for e in events: - out('{.tp_name = "%(name)s", .state=0},', - name = e.name, - ) - out('};') +def c(events): + pass def h(events): out('#include <stdio.h>', - '#include "trace/stderr.h"', + '#include "trace/control.h"', '', - 'extern TraceEvent trace_list[];') + ) - for num, e in enumerate(events): + for e in 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) {', + ' bool _state = trace_event_get_state(%(event_id)s);', + ' if (_state) {', ' fprintf(stderr, "%(name)s " %(fmt)s "\\n" %(argnames)s);', ' }', '}', name = e.name, args = e.args, - event_num = num, - fmt = e.fmt, + event_id = "TRACE_" + e.name.upper(), + fmt = e.fmt.rstrip("\n"), argnames = argnames, ) - - out('', - '#define NR_TRACE_EVENTS %d' % len(events)) diff --git a/scripts/tracetool/backend/ust.py b/scripts/tracetool/backend/ust.py index 31a2ff0404..ea36995092 100644 --- a/scripts/tracetool/backend/ust.py +++ b/scripts/tracetool/backend/ust.py @@ -16,6 +16,9 @@ __email__ = "stefanha@linux.vnet.ibm.com" from tracetool import out +PUBLIC = True + + def c(events): out('#include <ust/marker.h>', '#undef mutex_lock', diff --git a/scripts/tracetool/format/events_c.py b/scripts/tracetool/format/events_c.py new file mode 100644 index 0000000000..d670ec83d5 --- /dev/null +++ b/scripts/tracetool/format/events_c.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Generate .c for event description. +""" + +__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>" +__copyright__ = "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>" +__license__ = "GPL version 2 or (at your option) any later version" + +__maintainer__ = "Stefan Hajnoczi" +__email__ = "stefanha@linux.vnet.ibm.com" + + +from tracetool import out + + +def begin(events): + 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] = {') + + for e in 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(), + ) + + out('};', + '', + ) diff --git a/scripts/tracetool/format/events_h.py b/scripts/tracetool/format/events_h.py new file mode 100644 index 0000000000..d30ccea8a1 --- /dev/null +++ b/scripts/tracetool/format/events_h.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Generate .h for event description. +""" + +__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>" +__copyright__ = "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>" +__license__ = "GPL version 2 or (at your option) any later version" + +__maintainer__ = "Stefan Hajnoczi" +__email__ = "stefanha@linux.vnet.ibm.com" + + +from tracetool import out + + +def begin(events): + 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 {') + + for e in events: + out(' TRACE_%s,' % e.name.upper()) + + out(' TRACE_EVENT_COUNT', + '} TraceEventID;', + ) + + # static state + 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('#include "trace/event-internal.h"', + '', + '#endif /* TRACE__GENERATED_EVENTS_H */', + ) diff --git a/scripts/tracetool/format/h.py b/scripts/tracetool/format/h.py index 9a58de1331..93132fceaf 100644 --- a/scripts/tracetool/format/h.py +++ b/scripts/tracetool/format/h.py @@ -25,14 +25,7 @@ def begin(events): '#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__GENERATED_TRACERS_H */') + out('#endif /* TRACE__GENERATED_TRACERS_H */') def nop(events): for e in events: |