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
23 strtype = ('const char*', 'char*', 'const char *', 'char *')
24 if arg.lstrip().startswith(strtype):
30 out('#include "trace.h"',
31 '#include "trace/simple.h"',
33 'TraceEvent trace_list[] = {')
36 out('{.tp_name = "%(name)s", .state=0},',
43 for num, event in enumerate(events):
44 out('void trace_%(name)s(%(args)s)',
46 ' TraceBufferRecord rec;',
51 for type_, name in event.args:
53 out(' size_t arg%(name)s_len = %(name)s ? MIN(strlen(%(name)s), MAX_TRACE_STRLEN) : 0;',
56 strsizeinfo = "4 + arg%s_len" % name
57 sizes.append(strsizeinfo)
60 sizestr = " + ".join(sizes)
61 if len(event.args) == 0:
66 ' if (!trace_list[%(event_id)s].state) {',
70 ' if (trace_record_start(&rec, %(event_id)s, %(size_str)s)) {',
71 ' return; /* Trace Buffer Full, Event Dropped ! */',
77 if len(event.args) > 0:
78 for type_, name in event.args:
81 out(' trace_record_write_str(&rec, %(name)s, arg%(name)s_len);',
84 # pointer var (not string)
85 elif type_.endswith('*'):
86 out(' trace_record_write_u64(&rec, (uintptr_t)(uint64_t *)%(name)s);',
91 out(' trace_record_write_u64(&rec, (uint64_t)%(name)s);',
95 out(' trace_record_finish(&rec);',
101 out('#include "trace/simple.h"',
105 out('void trace_%(name)s(%(args)s);',
110 out('#define NR_TRACE_EVENTS %d' % len(events))
111 out('extern TraceEvent trace_list[NR_TRACE_EVENTS];')