2 # -*- coding: utf-8 -*-
5 Generate .stp file that outputs simpletrace binary traces (DTrace with SystemTAP only).
8 __author__
= "Stefan Hajnoczi <redhat.com>"
9 __copyright__
= "Copyright (C) 2014, Red Hat, Inc."
10 __license__
= "GPL version 2 or (at your option) any later version"
12 __maintainer__
= "Stefan Hajnoczi"
13 __email__
= "stefanha@redhat.com"
16 from tracetool
import out
17 from tracetool
.backend
.dtrace
import binary
, probeprefix
18 from tracetool
.backend
.simple
import is_string
19 from tracetool
.format
.stap
import stap_escape
22 def generate(events
, backend
):
23 out('/* This file is autogenerated by tracetool, do not edit. */',
26 for event_id
, e
in enumerate(events
):
27 if 'disable' in e
.properties
:
30 out('probe %(probeprefix)s.simpletrace.%(name)s = %(probeprefix)s.%(name)s ?',
32 probeprefix
=probeprefix(),
35 # Calculate record size
36 sizes
= ['24'] # sizeof(TraceRecord)
37 for type_
, name
in e
.args
:
38 name
= stap_escape(name
)
41 ' arg%(name)s_str = %(name)s ? user_string_n(%(name)s, 512) : "<null>"',
43 ' arg%(name)s_len = strlen(arg%(name)s_str)',
45 sizes
.append('4 + arg%s_len' % name
)
48 sizestr
= ' + '.join(sizes
)
50 # Generate format string and value pairs for record header and arguments
51 fields
= [('8b', str(event_id
)),
52 ('8b', 'gettimeofday_ns()'),
55 for type_
, name
in e
.args
:
56 name
= stap_escape(name
)
58 fields
.extend([('4b', 'arg%s_len' % name
),
59 ('.*s', 'arg%s_len, arg%s_str' % (name
, name
))])
61 fields
.append(('8b', name
))
63 # Emit the entire record in a single SystemTap printf()
64 fmt_str
= '%'.join(fmt
for fmt
, _
in fields
)
65 arg_str
= ', '.join(arg
for _
, arg
in fields
)
66 out(' printf("%%%(fmt_str)s", %(arg_str)s)',
67 fmt_str
=fmt_str
, arg_str
=arg_str
)