2 # -*- coding: utf-8 -*-
5 Simple built-in backend.
8 __author__
= "Lluís Vilanova <vilanova@ac.upc.edu>"
9 __copyright__
= "Copyright 2012-2014, 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 def generate_h_begin(events
):
32 out('void _simple_%(api)s(%(args)s);',
38 def generate_h(event
):
39 out(' _simple_%(api)s(%(args)s);',
41 args
=", ".join(event
.args
.names()))
44 def generate_c_begin(events
):
45 out('#include "trace.h"',
46 '#include "trace/control.h"',
47 '#include "trace/simple.h"',
51 def generate_c(event
):
52 out('void _simple_%(api)s(%(args)s)',
54 ' TraceBufferRecord rec;',
58 for type_
, name
in event
.args
:
60 out(' size_t arg%(name)s_len = %(name)s ? MIN(strlen(%(name)s), MAX_TRACE_STRLEN) : 0;',
62 strsizeinfo
= "4 + arg%s_len" % name
63 sizes
.append(strsizeinfo
)
66 sizestr
= " + ".join(sizes
)
67 if len(event
.args
) == 0:
72 ' if (!trace_event_get_state(%(event_id)s)) {',
76 ' if (trace_record_start(&rec, %(event_id)s, %(size_str)s)) {',
77 ' return; /* Trace Buffer Full, Event Dropped ! */',
79 event_id
='TRACE_' + event
.name
.upper(),
82 if len(event
.args
) > 0:
83 for type_
, name
in event
.args
:
86 out(' trace_record_write_str(&rec, %(name)s, arg%(name)s_len);',
88 # pointer var (not string)
89 elif type_
.endswith('*'):
90 out(' trace_record_write_u64(&rec, (uintptr_t)(uint64_t *)%(name)s);',
94 out(' trace_record_write_u64(&rec, (uint64_t)%(name)s);',
97 out(' trace_record_finish(&rec);',