]>
Commit | Line | Data |
---|---|---|
dd03a39e LV |
1 | # -*- coding: utf-8 -*- |
2 | ||
3 | """ | |
4 | Simple built-in backend. | |
5 | """ | |
6 | ||
7 | __author__ = "Lluís Vilanova <vilanova@ac.upc.edu>" | |
1ff7b531 | 8 | __copyright__ = "Copyright 2012-2017, Lluís Vilanova <vilanova@ac.upc.edu>" |
dd03a39e LV |
9 | __license__ = "GPL version 2 or (at your option) any later version" |
10 | ||
11 | __maintainer__ = "Stefan Hajnoczi" | |
f892b494 | 12 | __email__ = "stefanha@redhat.com" |
dd03a39e LV |
13 | |
14 | ||
15 | from tracetool import out | |
16 | ||
93fba161 LV |
17 | |
18 | PUBLIC = True | |
19 | ||
20 | ||
62bab732 HPB |
21 | def is_string(arg): |
22 | strtype = ('const char*', 'char*', 'const char *', 'char *') | |
db4df20d FZ |
23 | arg_strip = arg.lstrip() |
24 | if arg_strip.startswith(strtype) and arg_strip.count('*') == 1: | |
62bab732 HPB |
25 | return True |
26 | else: | |
27 | return False | |
dd03a39e | 28 | |
1dad2ce9 | 29 | |
80dd5c49 | 30 | def generate_h_begin(events, group): |
1dad2ce9 LV |
31 | for event in events: |
32 | out('void _simple_%(api)s(%(args)s);', | |
33 | api=event.api(), | |
34 | args=event.args) | |
35 | out('') | |
36 | ||
37 | ||
80dd5c49 | 38 | def generate_h(event, group): |
1ff7b531 | 39 | out(' _simple_%(api)s(%(args)s);', |
1dad2ce9 LV |
40 | api=event.api(), |
41 | args=", ".join(event.args.names())) | |
42 | ||
43 | ||
3932ef3f SH |
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()) | |
47 | ||
48 | ||
80dd5c49 | 49 | def generate_c_begin(events, group): |
2aef8c91 | 50 | out('#include "qemu/osdep.h"', |
60481e21 | 51 | '#include "trace/control.h"', |
62bab732 | 52 | '#include "trace/simple.h"', |
1dad2ce9 LV |
53 | '') |
54 | ||
55 | ||
80dd5c49 | 56 | def generate_c(event, group): |
1dad2ce9 LV |
57 | out('void _simple_%(api)s(%(args)s)', |
58 | '{', | |
59 | ' TraceBufferRecord rec;', | |
60 | api=event.api(), | |
61 | args=event.args) | |
62 | sizes = [] | |
63 | for type_, name in event.args: | |
64 | if is_string(type_): | |
65 | out(' size_t arg%(name)s_len = %(name)s ? MIN(strlen(%(name)s), MAX_TRACE_STRLEN) : 0;', | |
66 | name=name) | |
67 | strsizeinfo = "4 + arg%s_len" % name | |
68 | sizes.append(strsizeinfo) | |
69 | else: | |
70 | sizes.append("8") | |
71 | sizestr = " + ".join(sizes) | |
72 | if len(event.args) == 0: | |
73 | sizestr = '0' | |
74 | ||
40b9cd25 LV |
75 | event_id = 'TRACE_' + event.name.upper() |
76 | if "vcpu" in event.properties: | |
77 | # already checked on the generic format code | |
78 | cond = "true" | |
79 | else: | |
80 | cond = "trace_event_get_state(%s)" % event_id | |
1dad2ce9 LV |
81 | |
82 | out('', | |
40b9cd25 | 83 | ' if (!%(cond)s) {', |
1dad2ce9 LV |
84 | ' return;', |
85 | ' }', | |
dd03a39e | 86 | '', |
ef4c9fc8 | 87 | ' if (trace_record_start(&rec, %(event_obj)s.id, %(size_str)s)) {', |
1dad2ce9 LV |
88 | ' return; /* Trace Buffer Full, Event Dropped ! */', |
89 | ' }', | |
40b9cd25 | 90 | cond=cond, |
ef4c9fc8 | 91 | event_obj=event.api(event.QEMU_EVENT), |
1dad2ce9 LV |
92 | size_str=sizestr) |
93 | ||
94 | if len(event.args) > 0: | |
62bab732 | 95 | for type_, name in event.args: |
1dad2ce9 | 96 | # string |
62bab732 | 97 | if is_string(type_): |
1dad2ce9 LV |
98 | out(' trace_record_write_str(&rec, %(name)s, arg%(name)s_len);', |
99 | name=name) | |
100 | # pointer var (not string) | |
101 | elif type_.endswith('*'): | |
102 | out(' trace_record_write_u64(&rec, (uintptr_t)(uint64_t *)%(name)s);', | |
103 | name=name) | |
104 | # primitive data type | |
62bab732 | 105 | else: |
1dad2ce9 LV |
106 | out(' trace_record_write_u64(&rec, (uint64_t)%(name)s);', |
107 | name=name) | |
108 | ||
109 | out(' trace_record_finish(&rec);', | |
110 | '}', | |
111 | '') |