xref: /openbmc/qemu/scripts/tracetool/backend/ust.py (revision d6032e06)
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""
5LTTng 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
16from tracetool import out
17
18
19PUBLIC = True
20
21def c(events):
22    pass
23
24
25def h(events):
26    out('#include <lttng/tracepoint.h>',
27        '#include "trace/generated-ust-provider.h"',
28        '')
29    for e in events:
30        argnames = ", ".join(e.args.names())
31        if len(e.args) > 0:
32            argnames = ", " + argnames
33
34        out('static inline void trace_%(name)s(%(args)s)',
35            '{',
36            '    tracepoint(qemu, %(name)s%(tp_args)s);',
37            '}',
38            '',
39            name = e.name,
40            args = e.args,
41            tp_args = argnames,
42            )
43
44def ust_events_c(events):
45    pass
46
47def ust_events_h(events):
48    for e in events:
49        if len(e.args) > 0:
50            out('TRACEPOINT_EVENT(',
51                '   qemu,',
52                '   %(name)s,',
53                '   TP_ARGS(%(args)s),',
54                '   TP_FIELDS(',
55                name = e.name,
56                args = ", ".join(", ".join(i) for i in e.args),
57                )
58
59            for t,n in e.args:
60                if ('int' in t) or ('long' in t) or ('unsigned' in t) or ('size_t' in t):
61                    out('       ctf_integer(' + t + ', ' + n + ', ' + n + ')')
62                elif ('double' in t) or ('float' in t):
63                    out('       ctf_float(' + t + ', ' + n + ', ' + n + ')')
64                elif ('char *' in t) or ('char*' in t):
65                    out('       ctf_string(' + n + ', ' + n + ')')
66                elif ('void *' in t) or ('void*' in t):
67                    out('       ctf_integer_hex(unsigned long, ' + n + ', ' + n + ')')
68
69            out('   )',
70                ')',
71                '')
72
73        else:
74            out('TRACEPOINT_EVENT(',
75                '   qemu,',
76                '   %(name)s,',
77                '   TP_ARGS(void),',
78                '   TP_FIELDS()',
79                ')',
80                '',
81                name = e.name,
82                )