]> Git Repo - qemu.git/blame - scripts/tracetool/backend/simple.py
trace: [tracetool] Explicitly identify public backends
[qemu.git] / scripts / tracetool / backend / simple.py
CommitLineData
dd03a39e
LV
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""
5Simple built-in backend.
6"""
7
8__author__ = "Lluís Vilanova <[email protected]>"
9__copyright__ = "Copyright 2012, Lluís Vilanova <[email protected]>"
10__license__ = "GPL version 2 or (at your option) any later version"
11
12__maintainer__ = "Stefan Hajnoczi"
13__email__ = "[email protected]"
14
15
16from tracetool import out
17
93fba161
LV
18
19PUBLIC = True
20
21
62bab732
HPB
22def is_string(arg):
23 strtype = ('const char*', 'char*', 'const char *', 'char *')
24 if arg.lstrip().startswith(strtype):
25 return True
26 else:
27 return False
dd03a39e
LV
28
29def c(events):
30 out('#include "trace.h"',
62bab732 31 '#include "trace/simple.h"',
dd03a39e
LV
32 '',
33 'TraceEvent trace_list[] = {')
34
35 for e in events:
36 out('{.tp_name = "%(name)s", .state=0},',
37 name = e.name,
38 )
39
62bab732
HPB
40 out('};',
41 '')
42
43 for num, event in enumerate(events):
44 out('void trace_%(name)s(%(args)s)',
45 '{',
46 ' TraceBufferRecord rec;',
47 name = event.name,
48 args = event.args,
49 )
50 sizes = []
51 for type_, name in event.args:
52 if is_string(type_):
53 out(' size_t arg%(name)s_len = %(name)s ? MIN(strlen(%(name)s), MAX_TRACE_STRLEN) : 0;',
54 name = name,
55 )
56 strsizeinfo = "4 + arg%s_len" % name
57 sizes.append(strsizeinfo)
58 else:
59 sizes.append("8")
60 sizestr = " + ".join(sizes)
61 if len(event.args) == 0:
62 sizestr = '0'
63
64
65 out('',
66 ' if (!trace_list[%(event_id)s].state) {',
67 ' return;',
68 ' }',
69 '',
70 ' if (trace_record_start(&rec, %(event_id)s, %(size_str)s)) {',
71 ' return; /* Trace Buffer Full, Event Dropped ! */',
72 ' }',
73 event_id = num,
74 size_str = sizestr,
75 )
76
77 if len(event.args) > 0:
78 for type_, name in event.args:
79 # string
80 if is_string(type_):
81 out(' trace_record_write_str(&rec, %(name)s, arg%(name)s_len);',
82 name = name,
83 )
84 # pointer var (not string)
85 elif type_.endswith('*'):
964d0a7b 86 out(' trace_record_write_u64(&rec, (uintptr_t)(uint64_t *)%(name)s);',
62bab732
HPB
87 name = name,
88 )
89 # primitive data type
90 else:
91 out(' trace_record_write_u64(&rec, (uint64_t)%(name)s);',
92 name = name,
93 )
94
95 out(' trace_record_finish(&rec);',
96 '}',
97 '')
98
dd03a39e
LV
99
100def h(events):
101 out('#include "trace/simple.h"',
102 '')
103
62bab732
HPB
104 for event in events:
105 out('void trace_%(name)s(%(args)s);',
106 name = event.name,
107 args = event.args,
dd03a39e 108 )
62bab732 109 out('')
dd03a39e
LV
110 out('#define NR_TRACE_EVENTS %d' % len(events))
111 out('extern TraceEvent trace_list[NR_TRACE_EVENTS];')
This page took 0.159775 seconds and 4 git commands to generate.