xref: /openbmc/qemu/scripts/tracetool/format/stap.py (revision a1857ad1)
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 stap_escape(identifier):
31    # Append underscore to reserved keywords
32    if identifier in RESERVED_WORDS:
33        return identifier + '_'
34    return identifier
35
36
37def generate(events, backend):
38    events = [e for e in events
39              if "disable" not in e.properties]
40
41    out('/* This file is autogenerated by tracetool, do not edit. */',
42        '')
43
44    for e in events:
45        # Define prototype for probe arguments
46        out('probe %(probeprefix)s.%(name)s = process("%(binary)s").mark("%(name)s")',
47            '{',
48            probeprefix=probeprefix(),
49            name=e.name,
50            binary=binary())
51
52        i = 1
53        if len(e.args) > 0:
54            for name in e.args.names():
55                name = stap_escape(name)
56                out('  %s = $arg%d;' % (name, i))
57                i += 1
58
59        out('}')
60
61    out()
62