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 "qemu-common.h"',
41        '#include <lttng/tracepoint.h>',
42        '',
43        '/*',
44        ' * LTTng ust 2.0 does not allow you to use TP_ARGS(void) for tracepoints',
45        ' * requiring no arguments. We define these macros introduced in more recent'
46        ' * versions of LTTng ust as a workaround',
47        ' */',
48        '#ifndef _TP_EXPROTO1',
49        '#define _TP_EXPROTO1(a)               void',
50        '#endif',
51        '#ifndef _TP_EXDATA_PROTO1',
52        '#define _TP_EXDATA_PROTO1(a)          void *__tp_data',
53        '#endif',
54        '#ifndef _TP_EXDATA_VAR1',
55        '#define _TP_EXDATA_VAR1(a)            __tp_data',
56        '#endif',
57        '#ifndef _TP_EXVAR1',
58        '#define _TP_EXVAR1(a)',
59        '#endif',
60        '')
61
62    for e in events:
63        if len(e.args) > 0:
64            out('TRACEPOINT_EVENT(',
65                '   qemu,',
66                '   %(name)s,',
67                '   TP_ARGS(%(args)s),',
68                '   TP_FIELDS(',
69                name=e.name,
70                args=", ".join(", ".join(i) for i in e.args))
71
72            types = e.args.types()
73            names = e.args.names()
74            fmts = e.formats()
75            for t,n,f in zip(types, names, fmts):
76                if ('char *' in t) or ('char*' in t):
77                    out('       ctf_string(' + n + ', ' + n + ')')
78                elif ("%p" in f) or ("x" in f) or ("PRIx" in f):
79                    out('       ctf_integer_hex('+ t + ', ' + n + ', ' + n + ')')
80                elif ("ptr" in t) or ("*" in t):
81                    out('       ctf_integer_hex('+ t + ', ' + n + ', ' + n + ')')
82                elif ('int' in t) or ('long' in t) or ('unsigned' in t) or ('size_t' 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