trace: [tracetool] Explicitly identify public backends
[sdk/emulator/qemu.git] / scripts / tracetool / backend / ust.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 """
5 LTTng User Space Tracing 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
19 PUBLIC = True
20
21
22 def c(events):
23     out('#include <ust/marker.h>',
24         '#undef mutex_lock',
25         '#undef mutex_unlock',
26         '#undef inline',
27         '#undef wmb',
28         '#include "trace.h"')
29
30     for e in events:
31         argnames = ", ".join(e.args.names())
32         if len(e.args) > 0:
33             argnames = ', ' + argnames
34
35             out('DEFINE_TRACE(ust_%(name)s);',
36                 '',
37                 'static void ust_%(name)s_probe(%(args)s)',
38                 '{',
39                 '    trace_mark(ust, %(name)s, %(fmt)s%(argnames)s);',
40                 '}',
41                 name = e.name,
42                 args = e.args,
43                 fmt = e.fmt,
44                 argnames = argnames,
45                 )
46
47         else:
48             out('DEFINE_TRACE(ust_%(name)s);',
49                 '',
50                 'static void ust_%(name)s_probe(%(args)s)',
51                 '{',
52                 '    trace_mark(ust, %(name)s, UST_MARKER_NOARGS);',
53                 '}',
54                 name = e.name,
55                 args = e.args,
56                 )
57
58     # register probes
59     out('',
60         'static void __attribute__((constructor)) trace_init(void)',
61         '{')
62
63     for e in events:
64         out('    register_trace_ust_%(name)s(ust_%(name)s_probe);',
65             name = e.name,
66             )
67
68     out('}')
69
70
71 def h(events):
72     out('#include <ust/tracepoint.h>',
73         '#undef mutex_lock',
74         '#undef mutex_unlock',
75         '#undef inline',
76         '#undef wmb')
77
78     for e in events:
79         if len(e.args) > 0:
80             out('DECLARE_TRACE(ust_%(name)s, TP_PROTO(%(args)s), TP_ARGS(%(argnames)s));',
81                 '#define trace_%(name)s trace_ust_%(name)s',
82                 name = e.name,
83                 args = e.args,
84                 argnames = ", ".join(e.args.names()),
85                 )
86
87         else:
88             out('_DECLARE_TRACEPOINT_NOARGS(ust_%(name)s);',
89                 '#define trace_%(name)s trace_ust_%(name)s',
90                 name = e.name,
91                 )
92
93     out()