1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""
5trace/generated-ust-provider.h
6"""
7
8__author__     = "Mohamad Gebai <mohamad.gebai@polymtl.ca>"
9__copyright__  = "Copyright 2012, Mohamad Gebai <mohamad.gebai@polymtl.ca>"
10__license__    = "GPL version 2 or (at your option) any later version"
11
12__maintainer__ = "Stefan Hajnoczi"
13__email__      = "stefanha@redhat.com"
14
15
16from tracetool import out
17
18
19def generate(events, backend, group):
20    events = [e for e in events
21              if "disabled" not in e.properties]
22
23    if group == "all":
24        include = "trace-ust-all.h"
25    else:
26        include = "trace-ust.h"
27
28    out('/* This file is autogenerated by tracetool, do not edit. */',
29        '',
30        '#undef TRACEPOINT_PROVIDER',
31        '#define TRACEPOINT_PROVIDER qemu',
32        '',
33        '#undef TRACEPOINT_INCLUDE_FILE',
34        '#define TRACEPOINT_INCLUDE_FILE ./%s' % include,
35        '',
36        '#if !defined (TRACE_%s_GENERATED_UST_H) || \\'  % group.upper(),
37        '     defined(TRACEPOINT_HEADER_MULTI_READ)',
38        '#define TRACE_%s_GENERATED_UST_H' % group.upper(),
39        '',
40        '#include <lttng/tracepoint.h>',
41        '',
42        '/*',
43        ' * LTTng ust 2.0 does not allow you to use TP_ARGS(void) for tracepoints',
44        ' * requiring no arguments. We define these macros introduced in more recent'
45        ' * versions of LTTng ust as a workaround',
46        ' */',
47        '#ifndef _TP_EXPROTO1',
48        '#define _TP_EXPROTO1(a)               void',
49        '#endif',
50        '#ifndef _TP_EXDATA_PROTO1',
51        '#define _TP_EXDATA_PROTO1(a)          void *__tp_data',
52        '#endif',
53        '#ifndef _TP_EXDATA_VAR1',
54        '#define _TP_EXDATA_VAR1(a)            __tp_data',
55        '#endif',
56        '#ifndef _TP_EXVAR1',
57        '#define _TP_EXVAR1(a)',
58        '#endif',
59        '')
60
61    for e in events:
62        if len(e.args) > 0:
63            out('TRACEPOINT_EVENT(',
64                '   qemu,',
65                '   %(name)s,',
66                '   TP_ARGS(%(args)s),',
67                '   TP_FIELDS(',
68                name=e.name,
69                args=", ".join(", ".join(i) for i in e.args))
70
71            types = e.args.types()
72            names = e.args.names()
73            fmts = e.formats()
74            for t,n,f in zip(types, names, fmts):
75                if ('char *' in t) or ('char*' in t):
76                    out('       ctf_string(' + n + ', ' + n + ')')
77                elif ("%p" in f) or ("x" in f) or ("PRIx" in f):
78                    out('       ctf_integer_hex('+ t + ', ' + n + ', ' + n + ')')
79                elif ("ptr" in t) or ("*" in t):
80                    out('       ctf_integer_hex('+ t + ', ' + n + ', ' + n + ')')
81                elif ('int' in t) or ('long' in t) or ('unsigned' in t) \
82                        or ('size_t' in t) or ('bool' in t):
83                    out('       ctf_integer(' + t + ', ' + n + ', ' + n + ')')
84                elif ('double' in t) or ('float' in t):
85                    out('       ctf_float(' + t + ', ' + n + ', ' + n + ')')
86                elif ('void *' in t) or ('void*' in t):
87                    out('       ctf_integer_hex(unsigned long, ' + n + ', ' + n + ')')
88
89            out('   )',
90                ')',
91                '')
92
93        else:
94            out('TRACEPOINT_EVENT(',
95                '   qemu,',
96                '   %(name)s,',
97                '   TP_ARGS(void),',
98                '   TP_FIELDS()',
99                ')',
100                '',
101                name=e.name)
102
103    out('#endif /* TRACE_%s_GENERATED_UST_H */' % group.upper(),
104        '',
105        '/* This part must be outside ifdef protection */',
106        '#include <lttng/tracepoint-event.h>')
107