| 1 | # SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | |
| 3 | """ |
| 4 | Generate .stp file (DTrace with SystemTAP only). |
| 5 | """ |
| 6 | |
| 7 | __author__ = "Lluís Vilanova <vilanova@ac.upc.edu>" |
| 8 | __copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>" |
| 9 | __license__ = "GPL version 2 or (at your option) any later version" |
| 10 | |
| 11 | __maintainer__ = "Stefan Hajnoczi" |
| 12 | __email__ = "stefanha@redhat.com" |
| 13 | |
| 14 | |
| 15 | from tracetool import out |
| 16 | from tracetool.backend.dtrace import binary, probeprefix |
| 17 | |
| 18 | |
| 19 | # Technically 'self' is not used by systemtap yet, but |
| 20 | # they recommended we keep it in the reserved list anyway |
| 21 | RESERVED_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 | |
| 29 | def stap_escape(identifier): |
| 30 | # Append underscore to reserved keywords |
| 31 | if identifier in RESERVED_WORDS: |
| 32 | return identifier + '_' |
| 33 | return identifier |
| 34 | |
| 35 | |
| 36 | def generate(events, backend, group): |
| 37 | 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 | '/* SPDX-License-Identifier: GPL-2.0-or-later */', |
| 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() |