]>
Commit | Line | Data |
---|---|---|
52ef093a LV |
1 | #!/usr/bin/env python |
2 | # -*- coding: utf-8 -*- | |
3 | ||
4 | """ | |
5 | DTrace/SystemTAP backend. | |
6 | """ | |
7 | ||
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" | |
11 | ||
12 | __maintainer__ = "Stefan Hajnoczi" | |
13 | __email__ = "stefanha@linux.vnet.ibm.com" | |
14 | ||
15 | ||
16 | from tracetool import out | |
17 | ||
18 | ||
93fba161 LV |
19 | PUBLIC = True |
20 | ||
21 | ||
52ef093a LV |
22 | PROBEPREFIX = None |
23 | ||
24 | def _probeprefix(): | |
25 | if PROBEPREFIX is None: | |
26 | raise ValueError("you must set PROBEPREFIX") | |
27 | return PROBEPREFIX | |
28 | ||
29 | ||
30 | BINARY = None | |
31 | ||
32 | def _binary(): | |
33 | if BINARY is None: | |
34 | raise ValueError("you must set BINARY") | |
35 | return BINARY | |
36 | ||
37 | ||
38 | def c(events): | |
39 | pass | |
40 | ||
41 | ||
42 | def h(events): | |
eac236ea | 43 | out('#include "trace/generated-tracers-dtrace.h"', |
52ef093a LV |
44 | '') |
45 | ||
46 | for e in events: | |
47 | out('static inline void trace_%(name)s(%(args)s) {', | |
48 | ' QEMU_%(uppername)s(%(argnames)s);', | |
49 | '}', | |
50 | name = e.name, | |
51 | args = e.args, | |
52 | uppername = e.name.upper(), | |
53 | argnames = ", ".join(e.args.names()), | |
54 | ) | |
55 | ||
56 | ||
57 | def d(events): | |
58 | out('provider qemu {') | |
59 | ||
60 | for e in events: | |
61 | args = str(e.args) | |
62 | ||
63 | # DTrace provider syntax expects foo() for empty | |
64 | # params, not foo(void) | |
65 | if args == 'void': | |
66 | args = '' | |
67 | ||
68 | # Define prototype for probe arguments | |
69 | out('', | |
70 | 'probe %(name)s(%(args)s);', | |
71 | name = e.name, | |
72 | args = args, | |
73 | ) | |
74 | ||
75 | out('', | |
76 | '};') | |
77 | ||
78 | ||
81dee729 DB |
79 | # Technically 'self' is not used by systemtap yet, but |
80 | # they recommended we keep it in the reserved list anyway | |
81 | RESERVED_WORDS = ( | |
82 | 'break', 'catch', 'continue', 'delete', 'else', 'for', | |
83 | 'foreach', 'function', 'global', 'if', 'in', 'limit', | |
84 | 'long', 'next', 'probe', 'return', 'self', 'string', | |
85 | 'try', 'while' | |
86 | ) | |
87 | ||
52ef093a LV |
88 | def stap(events): |
89 | for e in events: | |
90 | # Define prototype for probe arguments | |
91 | out('probe %(probeprefix)s.%(name)s = process("%(binary)s").mark("%(name)s")', | |
92 | '{', | |
93 | probeprefix = _probeprefix(), | |
94 | name = e.name, | |
95 | binary = _binary(), | |
96 | ) | |
97 | ||
98 | i = 1 | |
99 | if len(e.args) > 0: | |
100 | for name in e.args.names(): | |
256a721d | 101 | # Append underscore to reserved keywords |
81dee729 | 102 | if name in RESERVED_WORDS: |
256a721d SH |
103 | name += '_' |
104 | out(' %s = $arg%d;' % (name, i)) | |
52ef093a LV |
105 | i += 1 |
106 | ||
107 | out('}') | |
108 | ||
109 | out() |