xref: /qemu/scripts/tracetool/format/stap.py (revision 72ac97cd)
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""
5Generate .stp file (DTrace with SystemTAP only).
6"""
7
8__author__     = "Lluís Vilanova <vilanova@ac.upc.edu>"
9__copyright__  = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
10__license__    = "GPL version 2 or (at your option) any later version"
11
12__maintainer__ = "Stefan Hajnoczi"
13__email__      = "stefanha@linux.vnet.ibm.com"
14
15
16from tracetool import out
17from tracetool.backend.dtrace import binary, probeprefix
18
19
20# Technically 'self' is not used by systemtap yet, but
21# they recommended we keep it in the reserved list anyway
22RESERVED_WORDS = (
23    'break', 'catch', 'continue', 'delete', 'else', 'for',
24    'foreach', 'function', 'global', 'if', 'in', 'limit',
25    'long', 'next', 'probe', 'return', 'self', 'string',
26    'try', 'while'
27    )
28
29
30def generate(events, backend):
31    events = [e for e in events
32              if "disable" not in e.properties]
33
34    out('/* This file is autogenerated by tracetool, do not edit. */',
35        '')
36
37    for e in events:
38        # Define prototype for probe arguments
39        out('probe %(probeprefix)s.%(name)s = process("%(binary)s").mark("%(name)s")',
40            '{',
41            probeprefix=probeprefix(),
42            name=e.name,
43            binary=binary())
44
45        i = 1
46        if len(e.args) > 0:
47            for name in e.args.names():
48                # Append underscore to reserved keywords
49                if name in RESERVED_WORDS:
50                    name += '_'
51                out('  %s = $arg%d;' % (name, i))
52                i += 1
53
54        out('}')
55
56    out()
57