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    out('/* This file is autogenerated by tracetool, do not edit. */',
24        '',
25        '#undef TRACEPOINT_PROVIDER',
26        '#define TRACEPOINT_PROVIDER qemu',
27        '',
28        '#undef TRACEPOINT_INCLUDE_FILE',
29        '#define TRACEPOINT_INCLUDE_FILE ./generated-ust-provider.h',
30        '',
31        '#if !defined (TRACE_%s_GENERATED_UST_H) || \\'  % group.upper(),
32        '     defined(TRACEPOINT_HEADER_MULTI_READ)',
33        '#define TRACE_%s_GENERATED_UST_H' % group.upper(),
34        '',
35        '#include "qemu-common.h"',
36        '#include <lttng/tracepoint.h>',
37        '',
38        '/*',
39        ' * LTTng ust 2.0 does not allow you to use TP_ARGS(void) for tracepoints',
40        ' * requiring no arguments. We define these macros introduced in more recent'
41        ' * versions of LTTng ust as a workaround',
42        ' */',
43        '#ifndef _TP_EXPROTO1',
44        '#define _TP_EXPROTO1(a)               void',
45        '#endif',
46        '#ifndef _TP_EXDATA_PROTO1',
47        '#define _TP_EXDATA_PROTO1(a)          void *__tp_data',
48        '#endif',
49        '#ifndef _TP_EXDATA_VAR1',
50        '#define _TP_EXDATA_VAR1(a)            __tp_data',
51        '#endif',
52        '#ifndef _TP_EXVAR1',
53        '#define _TP_EXVAR1(a)',
54        '#endif',
55        '')
56
57    for e in events:
58        if len(e.args) > 0:
59            out('TRACEPOINT_EVENT(',
60                '   qemu,',
61                '   %(name)s,',
62                '   TP_ARGS(%(args)s),',
63                '   TP_FIELDS(',
64                name=e.name,
65                args=", ".join(", ".join(i) for i in e.args))
66
67            types = e.args.types()
68            names = e.args.names()
69            fmts = e.formats()
70            for t,n,f in zip(types, names, fmts):
71                if ('char *' in t) or ('char*' in t):
72                    out('       ctf_string(' + n + ', ' + n + ')')
73                elif ("%p" in f) or ("x" in f) or ("PRIx" in f):
74                    out('       ctf_integer_hex('+ t + ', ' + n + ', ' + n + ')')
75                elif ("ptr" in t) or ("*" in t):
76                    out('       ctf_integer_hex('+ t + ', ' + n + ', ' + n + ')')
77                elif ('int' in t) or ('long' in t) or ('unsigned' in t) or ('size_t' in t):
78                    out('       ctf_integer(' + t + ', ' + n + ', ' + n + ')')
79                elif ('double' in t) or ('float' in t):
80                    out('       ctf_float(' + t + ', ' + n + ', ' + n + ')')
81                elif ('void *' in t) or ('void*' in t):
82                    out('       ctf_integer_hex(unsigned long, ' + n + ', ' + n + ')')
83
84            out('   )',
85                ')',
86                '')
87
88        else:
89            out('TRACEPOINT_EVENT(',
90                '   qemu,',
91                '   %(name)s,',
92                '   TP_ARGS(void),',
93                '   TP_FIELDS()',
94                ')',
95                '',
96                name=e.name)
97
98    out('#endif /* TRACE_%s_GENERATED_UST_H */' % group.upper(),
99        '',
100        '/* This part must be outside ifdef protection */',
101        '#include <lttng/tracepoint-event.h>')
102