1 # -*- coding: utf-8 -*-
4 Generate .stp file that outputs simpletrace binary traces (DTrace with SystemTAP only).
7 __author__
= "Stefan Hajnoczi <redhat.com>"
8 __copyright__
= "Copyright (C) 2014, Red Hat, Inc."
9 __license__
= "GPL version 2 or (at your option) any later version"
11 __maintainer__
= "Stefan Hajnoczi"
12 __email__
= "stefanha@redhat.com"
15 from tracetool
import out
16 from tracetool
.backend
.dtrace
import probeprefix
17 from tracetool
.backend
.simple
import is_string
18 from tracetool
.format
.stap
import stap_escape
20 def global_var_name(name
):
21 return probeprefix().replace(".", "_") + "_" + name
23 def generate(events
, backend
, group
):
24 out('/* This file is autogenerated by tracetool, do not edit. */',
27 for event_id
, e
in enumerate(events
):
28 if 'disable' in e
.properties
:
31 out('probe %(probeprefix)s.simpletrace.%(name)s = %(probeprefix)s.%(name)s ?',
33 probeprefix
=probeprefix(),
36 # Calculate record size
37 sizes
= ['24'] # sizeof(TraceRecord)
38 for type_
, name
in e
.args
:
39 name
= stap_escape(name
)
42 ' arg%(name)s_str = %(name)s ? user_string_n(%(name)s, 512) : "<null>"',
44 ' arg%(name)s_len = strlen(arg%(name)s_str)',
46 sizes
.append('4 + arg%s_len' % name
)
49 sizestr
= ' + '.join(sizes
)
51 # Generate format string and value pairs for record header and arguments
52 fields
= [('8b', str(event_id
)),
53 ('8b', 'gettimeofday_ns()'),
56 for type_
, name
in e
.args
:
57 name
= stap_escape(name
)
59 fields
.extend([('4b', 'arg%s_len' % name
),
60 ('.*s', 'arg%s_len, arg%s_str' % (name
, name
))])
62 fields
.append(('8b', name
))
64 # Emit the entire record in a single SystemTap printf()
65 fmt_str
= '%'.join(fmt
for fmt
, _
in fields
)
66 arg_str
= ', '.join(arg
for _
, arg
in fields
)
67 out(' printf("%%8b%%%(fmt_str)s", 1, %(arg_str)s)',
68 fmt_str
=fmt_str
, arg_str
=arg_str
)