1 # -*- coding: utf-8 -*-
4 Simple built-in backend.
7 __author__
= "Lluís Vilanova <vilanova@ac.upc.edu>"
8 __copyright__
= "Copyright 2012-2017, Lluís Vilanova <vilanova@ac.upc.edu>"
9 __license__
= "GPL version 2 or (at your option) any later version"
11 __maintainer__
= "Stefan Hajnoczi"
12 __email__
= "stefanha@redhat.com"
15 from tracetool
import out
22 strtype
= ('const char*', 'char*', 'const char *', 'char *')
23 arg_strip
= arg
.lstrip()
24 if arg_strip
.startswith(strtype
) and arg_strip
.count('*') == 1:
30 def generate_h_begin(events
, group
):
32 out('void _simple_%(api)s(%(args)s);',
38 def generate_h(event
, group
):
39 out(' _simple_%(api)s(%(args)s);',
41 args
=", ".join(event
.args
.names()))
44 def generate_h_backend_dstate(event
, group
):
45 out(' trace_event_get_state_dynamic_by_id(%(event_id)s) || \\',
46 event_id
="TRACE_" + event
.name
.upper())
49 def generate_c_begin(events
, group
):
50 out('#include "qemu/osdep.h"',
51 '#include "trace/control.h"',
52 '#include "trace/simple.h"',
56 def generate_c(event
, group
):
57 out('void _simple_%(api)s(%(args)s)',
59 ' TraceBufferRecord rec;',
63 for type_
, name
in event
.args
:
65 out(' size_t arg%(name)s_len = %(name)s ? MIN(strlen(%(name)s), MAX_TRACE_STRLEN) : 0;',
67 strsizeinfo
= "4 + arg%s_len" % name
68 sizes
.append(strsizeinfo
)
71 sizestr
= " + ".join(sizes
)
72 if len(event
.args
) == 0:
75 event_id
= 'TRACE_' + event
.name
.upper()
76 if "vcpu" in event
.properties
:
77 # already checked on the generic format code
80 cond
= "trace_event_get_state(%s)" % event_id
87 ' if (trace_record_start(&rec, %(event_obj)s.id, %(size_str)s)) {',
88 ' return; /* Trace Buffer Full, Event Dropped ! */',
91 event_obj
=event
.api(event
.QEMU_EVENT
),
94 if len(event
.args
) > 0:
95 for type_
, name
in event
.args
:
98 out(' trace_record_write_str(&rec, %(name)s, arg%(name)s_len);',
100 # pointer var (not string)
101 elif type_
.endswith('*'):
102 out(' trace_record_write_u64(&rec, (uintptr_t)(uint64_t *)%(name)s);',
104 # primitive data type
106 out(' trace_record_write_u64(&rec, (uint64_t)%(name)s);',
109 out(' trace_record_finish(&rec);',