From patchwork Fri Jul 28 13:36:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 9868831 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C79D06037D for ; Fri, 28 Jul 2017 13:38:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE19520144 for ; Fri, 28 Jul 2017 13:38:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A0CE0285EB; Fri, 28 Jul 2017 13:38:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4104520144 for ; Fri, 28 Jul 2017 13:38:02 +0000 (UTC) Received: from localhost ([::1]:48432 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1db5Sr-0007iw-KE for patchwork-qemu-devel@patchwork.kernel.org; Fri, 28 Jul 2017 09:38:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60532) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1db5Rz-0007hl-Vi for qemu-devel@nongnu.org; Fri, 28 Jul 2017 09:37:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1db5Rx-0002NJ-0C for qemu-devel@nongnu.org; Fri, 28 Jul 2017 09:37:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56342) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1db5Rw-0002MI-Lo for qemu-devel@nongnu.org; Fri, 28 Jul 2017 09:37:04 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A3953CE388 for ; Fri, 28 Jul 2017 13:37:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A3953CE388 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=berrange@redhat.com Received: from t460.redhat.com (ovpn-117-113.ams2.redhat.com [10.36.117.113]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E9AB6FE78; Fri, 28 Jul 2017 13:36:59 +0000 (UTC) From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Fri, 28 Jul 2017 14:36:57 +0100 Message-Id: <20170728133657.5525-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 28 Jul 2017 13:37:03 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for 2.10] trace: ensure unique function / variable names per .stp file X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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