blob: a218b0445c9b1d724e941c80c82ee0f1cd70fbd1 [file] [log] [blame]
Lluís Vilanova52ef0932012-04-03 20:48:12 +02001# -*- coding: utf-8 -*-
2
3"""
4Generate .stp file (DTrace with SystemTAP only).
5"""
6
7__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
Lluís Vilanova1dad2ce2014-02-23 20:37:40 +01008__copyright__ = "Copyright 2012-2014, 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
Lluís Vilanova1dad2ce2014-02-23 20:37:40 +010016from tracetool.backend.dtrace import binary, probeprefix
Lluís Vilanova52ef0932012-04-03 20:48:12 +020017
18
Lluís Vilanova1dad2ce2014-02-23 20:37:40 +010019# Technically 'self' is not used by systemtap yet, but
20# they recommended we keep it in the reserved list anyway
21RESERVED_WORDS = (
22 'break', 'catch', 'continue', 'delete', 'else', 'for',
23 'foreach', 'function', 'global', 'if', 'in', 'limit',
24 'long', 'next', 'probe', 'return', 'self', 'string',
25 'try', 'while'
26 )
27
28
Stefan Hajnoczia76ccf32014-06-22 21:46:04 +080029def stap_escape(identifier):
30 # Append underscore to reserved keywords
31 if identifier in RESERVED_WORDS:
32 return identifier + '_'
33 return identifier
34
35
Daniel P. Berrange80dd5c42016-10-04 14:35:59 +010036def generate(events, backend, group):
Lluís Vilanova1dad2ce2014-02-23 20:37:40 +010037 events = [e for e in events
38 if "disable" not in e.properties]
39
40 out('/* This file is autogenerated by tracetool, do not edit. */',
41 '')
42
43 for e in events:
44 # Define prototype for probe arguments
45 out('probe %(probeprefix)s.%(name)s = process("%(binary)s").mark("%(name)s")',
46 '{',
47 probeprefix=probeprefix(),
48 name=e.name,
49 binary=binary())
50
51 i = 1
52 if len(e.args) > 0:
53 for name in e.args.names():
Stefan Hajnoczia76ccf32014-06-22 21:46:04 +080054 name = stap_escape(name)
Lluís Vilanova1dad2ce2014-02-23 20:37:40 +010055 out(' %s = $arg%d;' % (name, i))
56 i += 1
57
58 out('}')
59
60 out()