2 # -*- coding: utf-8 -*-
5 Simple built-in backend.
8 __author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
9 __copyright__ = "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>"
10 __license__ = "GPL version 2 or (at your option) any later version"
12 __maintainer__ = "Stefan Hajnoczi"
13 __email__ = "stefanha@linux.vnet.ibm.com"
16 from tracetool import out
19 strtype = ('const char*', 'char*', 'const char *', 'char *')
20 if arg.lstrip().startswith(strtype):
26 out('#include "trace.h"',
27 '#include "trace/simple.h"',
29 'TraceEvent trace_list[] = {')
32 out('{.tp_name = "%(name)s", .state=0},',
39 for num, event in enumerate(events):
40 out('void trace_%(name)s(%(args)s)',
42 ' TraceBufferRecord rec;',
47 for type_, name in event.args:
49 out(' size_t arg%(name)s_len = %(name)s ? MIN(strlen(%(name)s), MAX_TRACE_STRLEN) : 0;',
52 strsizeinfo = "4 + arg%s_len" % name
53 sizes.append(strsizeinfo)
56 sizestr = " + ".join(sizes)
57 if len(event.args) == 0:
62 ' if (!trace_list[%(event_id)s].state) {',
66 ' if (trace_record_start(&rec, %(event_id)s, %(size_str)s)) {',
67 ' return; /* Trace Buffer Full, Event Dropped ! */',
73 if len(event.args) > 0:
74 for type_, name in event.args:
77 out(' trace_record_write_str(&rec, %(name)s, arg%(name)s_len);',
80 # pointer var (not string)
81 elif type_.endswith('*'):
82 out(' trace_record_write_u64(&rec, (uintptr_t)(uint64_t *)%(name)s);',
87 out(' trace_record_write_u64(&rec, (uint64_t)%(name)s);',
91 out(' trace_record_finish(&rec);',
97 out('#include "trace/simple.h"',
101 out('void trace_%(name)s(%(args)s);',
106 out('#define NR_TRACE_EVENTS %d' % len(events))
107 out('extern TraceEvent trace_list[NR_TRACE_EVENTS];')