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