blob: e17edc9b9d829a4dfc8d11d24a4fdcb465159992 [file] [log] [blame]
Lluís Vilanova52ef0932012-04-03 20:48:12 +02001# -*- coding: utf-8 -*-
2
3"""
4DTrace/SystemTAP backend.
5"""
6
7__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
Lluís Vilanova1ff7b532017-07-04 10:50:46 +02008__copyright__ = "Copyright 2012-2017, Lluís Vilanova <vilanova@ac.upc.edu>"
Lluís Vilanova52ef0932012-04-03 20:48:12 +02009__license__ = "GPL version 2 or (at your option) any later version"
10
11__maintainer__ = "Stefan Hajnoczi"
Philippe Mathieu-Daudéf892b492020-05-11 10:28:16 +020012__email__ = "stefanha@redhat.com"
Lluís Vilanova52ef0932012-04-03 20:48:12 +020013
14
15from tracetool import out
16
17
Lluís Vilanova93fba162013-03-05 14:47:26 +010018PUBLIC = True
19
20
Lluís Vilanova52ef0932012-04-03 20:48:12 +020021PROBEPREFIX = None
22
Lluís Vilanova1dad2ce2014-02-23 20:37:40 +010023def probeprefix():
Lluís Vilanova52ef0932012-04-03 20:48:12 +020024 if PROBEPREFIX is None:
25 raise ValueError("you must set PROBEPREFIX")
26 return PROBEPREFIX
27
28
29BINARY = None
30
Lluís Vilanova1dad2ce2014-02-23 20:37:40 +010031def binary():
Lluís Vilanova52ef0932012-04-03 20:48:12 +020032 if BINARY is None:
33 raise ValueError("you must set BINARY")
34 return BINARY
35
36
Daniel P. Berrange80dd5c42016-10-04 14:35:59 +010037def generate_h_begin(events, group):
Daniel P. Berrange0ab8ed12017-01-25 16:14:15 +000038 if group == "root":
39 header = "trace-dtrace-root.h"
40 else:
Paolo Bonzinia81df1b2020-08-19 08:44:56 -040041 header = "trace-dtrace-%s.h" % group
Daniel P. Berrange0ab8ed12017-01-25 16:14:15 +000042
Stefan Hajnoczi27e08ba2020-06-25 15:07:57 +010043 # Workaround for ust backend, which also includes <sys/sdt.h> and may
44 # require SDT_USE_VARIADIC to be defined. If dtrace includes <sys/sdt.h>
45 # first without defining SDT_USE_VARIADIC then ust breaks because the
46 # STAP_PROBEV() macro is not defined.
Stefan Hajnoczi00082242020-07-29 16:39:26 +010047 out('#ifndef SDT_USE_VARIADIC')
Stefan Hajnoczi27e08ba2020-06-25 15:07:57 +010048 out('#define SDT_USE_VARIADIC 1')
Stefan Hajnoczi00082242020-07-29 16:39:26 +010049 out('#endif')
Stefan Hajnoczi27e08ba2020-06-25 15:07:57 +010050
Daniel P. Berrange0ab8ed12017-01-25 16:14:15 +000051 out('#include "%s"' % header,
Lluís Vilanova52ef0932012-04-03 20:48:12 +020052 '')
53
Stefan Hajnoczi00082242020-07-29 16:39:26 +010054 out('#undef SDT_USE_VARIADIC')
55
Stefan Hajnoczi3932ef32017-07-31 15:07:17 +010056 # SystemTap defines <provider>_<name>_ENABLED() but other DTrace
57 # implementations might not.
58 for e in events:
59 out('#ifndef QEMU_%(uppername)s_ENABLED',
60 '#define QEMU_%(uppername)s_ENABLED() true',
61 '#endif',
62 uppername=e.name.upper())
Lluís Vilanova52ef0932012-04-03 20:48:12 +020063
Daniel P. Berrange80dd5c42016-10-04 14:35:59 +010064def generate_h(event, group):
Lluís Vilanova1ff7b532017-07-04 10:50:46 +020065 out(' QEMU_%(uppername)s(%(argnames)s);',
Lluís Vilanova1dad2ce2014-02-23 20:37:40 +010066 uppername=event.name.upper(),
67 argnames=", ".join(event.args.names()))
Stefan Hajnoczi3932ef32017-07-31 15:07:17 +010068
69
70def generate_h_backend_dstate(event, group):
71 out(' QEMU_%(uppername)s_ENABLED() || \\',
72 uppername=event.name.upper())