* [Qemu-devel] [PATCH for 2.10] trace: ensure unique function / variable names per .stp file
@ 2017-07-28 13:36 Daniel P. Berrange
2017-07-31 9:50 ` Stefan Hajnoczi
0 siblings, 1 reply; 2+ messages in thread
From: Daniel P. Berrange @ 2017-07-28 13:36 UTC (permalink / raw)
To: qemu-devel; +Cc: Stefan Hajnoczi, Daniel P. Berrange
The simpletrace compatibility code for systemtap creates a
function and some global variables for mapping to event ID
numbers. We generate multiple -simpletrace.stp files though,
one per target and systemtap considers functions & variables
to be globally scoped, not per file. So if trying to use the
simpletrace compat probes, systemtap will complain:
# stap -e 'probe qemu.system.arm.simpletrace.visit_type_str { print( "hello")}'
semantic error: conflicting global variables: identifier 'event_name_to_id_map' at /usr/share/systemtap/tapset/qemu-aarch64-simpletrace.stp:3:8
source: global event_name_to_id_map
^
identifier 'event_name_to_id_map' at /usr/share/systemtap/tapset/qemu-system-arm-simpletrace.stp:3:8
source: global event_name_to_id_map
^
WARNING: cross-file global variable reference to identifier 'event_name_to_id_map' at /usr/share/systemtap/tapset/qemu-system-arm-simpletrace.stp:3:8 from: identifier 'event_name_to_id_map' at /usr/share/systemtap/tapset/qemu-aarch64-simpletrace.stp:8:21
source: if (!([name] in event_name_to_id_map)) {
^
WARNING: cross-file global variable reference to identifier 'event_next_id' at /usr/share/systemtap/tapset/qemu-system-arm-simpletrace.stp:4:8 from: identifier 'event_next_id' at :9:38
source: event_name_to_id_map[name] = event_next_id
^
We already have a string used to prefix probe names, so just
replace '.' with '_' to get a function / variable name prefix
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
scripts/tracetool/format/simpletrace_stap.py | 29 ++++++++++++++++++----------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/scripts/tracetool/format/simpletrace_stap.py b/scripts/tracetool/format/simpletrace_stap.py
index c35e662e00..144b704bcd 100644
--- a/scripts/tracetool/format/simpletrace_stap.py
+++ b/scripts/tracetool/format/simpletrace_stap.py
@@ -18,29 +18,37 @@ from tracetool.backend.dtrace import binary, probeprefix
from tracetool.backend.simple import is_string
from tracetool.format.stap import stap_escape
+def global_var_name(name):
+ return probeprefix().replace(".", "_") + "_" + name
def generate(events, backend, group):
+ id_map = global_var_name("event_name_to_id_map")
+ next_id = global_var_name("event_next_id")
+ map_func = global_var_name("simple_trace_map_event")
out('/* This file is autogenerated by tracetool, do not edit. */',
'',
- 'global event_name_to_id_map',
- 'global event_next_id',
- 'function simple_trace_map_event(name)',
+ 'global %(id_map)s',
+ 'global %(next_id)s',
+ 'function %(map_func)s(name)',
'',
'{',
- ' if (!([name] in event_name_to_id_map)) {',
- ' event_name_to_id_map[name] = event_next_id',
+ ' if (!([name] in %(id_map)s)) {',
+ ' %(id_map)s[name] = %(next_id)s',
' name_len = strlen(name)',
' printf("%%8b%%8b%%4b%%.*s", 0, ',
- ' event_next_id, name_len, name_len, name)',
- ' event_next_id = event_next_id + 1',
+ ' %(next_id)s, name_len, name_len, name)',
+ ' %(next_id)s = %(next_id)s + 1',
' }',
- ' return event_name_to_id_map[name]',
+ ' return %(id_map)s[name]',
'}',
'probe begin',
'{',
' printf("%%8b%%8b%%8b", 0xffffffffffffffff, 0xf2b177cb0aa429b4, 4)',
'}',
- '')
+ '',
+ id_map=id_map,
+ next_id=next_id,
+ map_func=map_func)
for event_id, e in enumerate(events):
if 'disable' in e.properties:
@@ -48,8 +56,9 @@ def generate(events, backend, group):
out('probe %(probeprefix)s.simpletrace.%(name)s = %(probeprefix)s.%(name)s ?',
'{',
- ' id = simple_trace_map_event("%(name)s")',
+ ' id = %(map_func)s("%(name)s")',
probeprefix=probeprefix(),
+ map_func=map_func,
name=e.name)
# Calculate record size
--
2.13.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH for 2.10] trace: ensure unique function / variable names per .stp file
2017-07-28 13:36 [Qemu-devel] [PATCH for 2.10] trace: ensure unique function / variable names per .stp file Daniel P. Berrange
@ 2017-07-31 9:50 ` Stefan Hajnoczi
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Hajnoczi @ 2017-07-31 9:50 UTC (permalink / raw)
To: Daniel P. Berrange; +Cc: qemu-devel, Stefan Hajnoczi
[-- Attachment #1: Type: text/plain, Size: 2027 bytes --]
On Fri, Jul 28, 2017 at 02:36:57PM +0100, Daniel P. Berrange wrote:
> The simpletrace compatibility code for systemtap creates a
> function and some global variables for mapping to event ID
> numbers. We generate multiple -simpletrace.stp files though,
> one per target and systemtap considers functions & variables
> to be globally scoped, not per file. So if trying to use the
> simpletrace compat probes, systemtap will complain:
>
> # stap -e 'probe qemu.system.arm.simpletrace.visit_type_str { print( "hello")}'
> semantic error: conflicting global variables: identifier 'event_name_to_id_map' at /usr/share/systemtap/tapset/qemu-aarch64-simpletrace.stp:3:8
> source: global event_name_to_id_map
> ^
> identifier 'event_name_to_id_map' at /usr/share/systemtap/tapset/qemu-system-arm-simpletrace.stp:3:8
> source: global event_name_to_id_map
> ^
>
> WARNING: cross-file global variable reference to identifier 'event_name_to_id_map' at /usr/share/systemtap/tapset/qemu-system-arm-simpletrace.stp:3:8 from: identifier 'event_name_to_id_map' at /usr/share/systemtap/tapset/qemu-aarch64-simpletrace.stp:8:21
> source: if (!([name] in event_name_to_id_map)) {
> ^
> WARNING: cross-file global variable reference to identifier 'event_next_id' at /usr/share/systemtap/tapset/qemu-system-arm-simpletrace.stp:4:8 from: identifier 'event_next_id' at :9:38
> source: event_name_to_id_map[name] = event_next_id
> ^
>
> We already have a string used to prefix probe names, so just
> replace '.' with '_' to get a function / variable name prefix
>
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> ---
> scripts/tracetool/format/simpletrace_stap.py | 29 ++++++++++++++++++----------
> 1 file changed, 19 insertions(+), 10 deletions(-)
Thanks, applied to my tracing tree:
https://github.com/stefanha/qemu/commits/tracing
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-07-31 9:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-28 13:36 [Qemu-devel] [PATCH for 2.10] trace: ensure unique function / variable names per .stp file Daniel P. Berrange
2017-07-31 9:50 ` Stefan Hajnoczi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).