From patchwork Sun Apr 1 21:05:30 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Llu=C3=ADs_Vilanova?= X-Patchwork-Id: 149992 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 45CAEB7016 for ; Mon, 2 Apr 2012 07:36:39 +1000 (EST) Received: from localhost ([::1]:42696 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SERy7-0006j4-Nd for incoming@patchwork.ozlabs.org; Sun, 01 Apr 2012 17:05:47 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45089) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SERxo-0006RF-Fr for qemu-devel@nongnu.org; Sun, 01 Apr 2012 17:05:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SERxm-0005fV-2y for qemu-devel@nongnu.org; Sun, 01 Apr 2012 17:05:28 -0400 Received: from roura.ac.upc.es ([147.83.33.10]:59952) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SERxl-0005fR-NE for qemu-devel@nongnu.org; Sun, 01 Apr 2012 17:05:25 -0400 Received: from gw.ac.upc.edu (gw.ac.upc.es [147.83.30.3]) by roura.ac.upc.es (8.13.8/8.13.8) with ESMTP id q31L5N9v027006; Sun, 1 Apr 2012 23:05:23 +0200 Received: from localhost (unknown [84.88.53.92]) by gw.ac.upc.edu (Postfix) with ESMTP id 5C2D92D0017; Sun, 1 Apr 2012 23:05:22 +0200 (CEST) From: =?utf-8?b?TGx1w61z?= Vilanova To: qemu-devel@nongnu.org Date: Sun, 1 Apr 2012 23:05:30 +0200 Message-Id: <20120401210529.32042.36725.stgit@ginnungagap.bsc.es> X-Mailer: git-send-email 1.7.9.1 In-Reply-To: <20120401210449.32042.93979.stgit@ginnungagap.bsc.es> References: <20120401210449.32042.93979.stgit@ginnungagap.bsc.es> User-Agent: StGit/0.16 MIME-Version: 1.0 X-MIME-Autoconverted: from 8bit to quoted-printable by roura.ac.upc.es id q31L5N9v027006 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 147.83.33.10 Cc: stefanha@gmail.com Subject: [Qemu-devel] [PATCH v5 7/8] tracetool: Add support for the 'dtrace' backend X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Lluís Vilanova --- scripts/tracetool.py | 32 +++++++++++- scripts/tracetool/__init__.py | 11 ++++ scripts/tracetool/backend/dtrace.py | 97 +++++++++++++++++++++++++++++++++++ scripts/tracetool/format/d.py | 20 +++++++ scripts/tracetool/format/stap.py | 20 +++++++ 5 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 scripts/tracetool/backend/dtrace.py create mode 100644 scripts/tracetool/format/d.py create mode 100644 scripts/tracetool/format/stap.py diff --git a/scripts/tracetool.py b/scripts/tracetool.py index fe2ea34..cacfd99 100755 --- a/scripts/tracetool.py +++ b/scripts/tracetool.py @@ -44,6 +44,11 @@ Options: --help This help message. --list-backends Print list of available backends. --check-backend Check if the given backend is valid. + --binary Full path to QEMU binary. + --target-type QEMU emulator target type ('system' or 'user'). + --target-arch QEMU emulator target arch. + --probe-prefix Prefix for dtrace probe names + (default: qemu--).\ """ % { "script" : _SCRIPT, "backends" : backend_descr, @@ -71,6 +76,10 @@ def main(args): check_backend = False arg_backend = "" arg_format = "" + binary = None + target_type = None + target_arch = None + probe_prefix = None for opt, arg in opts: if opt == "--help": error_opt() @@ -87,6 +96,15 @@ def main(args): elif opt == "--check-backend": check_backend = True + elif opt == "--binary": + binary = arg + elif opt == '--target-type': + target_type = arg + elif opt == '--target-arch': + target_arch = arg + elif opt == '--probe-prefix': + probe_prefix = arg + else: error_opt("unhandled option: %s" % opt) @@ -99,8 +117,20 @@ def main(args): else: sys.exit(1) + if arg_format == "stap": + if binary is None: + error_opt("--binary is required for SystemTAP tapset generator") + if probe_prefix is None and target_type is None: + error_opt("--target-type is required for SystemTAP tapset generator") + if probe_prefix is None and target_arch is None: + error_opt("--target-arch is required for SystemTAP tapset generator") + + if probe_prefix is None: + probe_prefix = ".".join([ "qemu", target_type, target_arch ]) + try: - tracetool.generate(sys.stdin, arg_format, arg_backend) + tracetool.generate(sys.stdin, arg_format, arg_backend, + binary = binary, probe_prefix = probe_prefix) except tracetool.TracetoolError as e: error_opt(str(e)) diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py index 873629b..019a319 100644 --- a/scripts/tracetool/__init__.py +++ b/scripts/tracetool/__init__.py @@ -177,7 +177,8 @@ def try_import(mod_name, attr_name = None, attr_default = None): return False, None -def generate(fevents, format, backend): +def generate(fevents, format, backend, + binary = None, probe_prefix = None): """Generate the output for the given (format, backend) pair. Parameters @@ -188,6 +189,10 @@ def generate(fevents, format, backend): Output format name. backend : str Output backend name. + binary : str or None + See tracetool.backend.dtrace.BINARY. + probe_prefix : str or None + See tracetool.backend.dtrace.PROBEPREFIX. """ # fix strange python error (UnboundLocalError tracetool) import tracetool @@ -210,6 +215,10 @@ def generate(fevents, format, backend): raise TracetoolError("backend '%s' not compatible with format '%s'" % (backend, format)) + import tracetool.backend.dtrace + tracetool.backend.dtrace.BINARY = binary + tracetool.backend.dtrace.PROBEPREFIX = probe_prefix + events = _read_events(fevents) if backend == "nop": diff --git a/scripts/tracetool/backend/dtrace.py b/scripts/tracetool/backend/dtrace.py new file mode 100644 index 0000000..cebbd57 --- /dev/null +++ b/scripts/tracetool/backend/dtrace.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +DTrace/SystemTAP backend. +""" + +__author__ = "Lluís Vilanova " +__copyright__ = "Copyright 2012, Lluís Vilanova " +__license__ = "GPL version 2 or (at your option) any later version" + +__maintainer__ = "Stefan Hajnoczi" +__email__ = "stefanha@linux.vnet.ibm.com" + + +from tracetool import out + + +PROBEPREFIX = None + +def _probeprefix(): + if PROBEPREFIX is None: + raise ValueError("you must set PROBEPREFIX") + return PROBEPREFIX + + +BINARY = None + +def _binary(): + if BINARY is None: + raise ValueError("you must set BINARY") + return BINARY + + +def c(events): + pass + + +def h(events): + out('#include "trace-dtrace.h"', + '') + + for e in events: + out('static inline void trace_%(name)s(%(args)s) {', + ' QEMU_%(uppername)s(%(argnames)s);', + '}', + name = e.name, + args = e.args, + uppername = e.name.upper(), + argnames = ", ".join(e.args.names()), + ) + + +def d(events): + out('provider qemu {') + + for e in events: + args = str(e.args) + + # DTrace provider syntax expects foo() for empty + # params, not foo(void) + if args == 'void': + args = '' + + # Define prototype for probe arguments + out('', + 'probe %(name)s(%(args)s);', + name = e.name, + args = args, + ) + + out('', + '};') + + +def stap(events): + for e in events: + # Define prototype for probe arguments + out('probe %(probeprefix)s.%(name)s = process("%(binary)s").mark("%(name)s")', + '{', + probeprefix = _probeprefix(), + name = e.name, + binary = _binary(), + ) + + i = 1 + if len(e.args) > 0: + for name in e.args.names(): + # 'limit' is a reserved keyword + if name == 'limit': + name = '_limit' + out(' %s = $arg%d;' % (name.lstrip(), i)) + i += 1 + + out('}') + + out() diff --git a/scripts/tracetool/format/d.py b/scripts/tracetool/format/d.py new file mode 100644 index 0000000..a2d5947 --- /dev/null +++ b/scripts/tracetool/format/d.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Generate .d file (DTrace only). +""" + +__author__ = "Lluís Vilanova " +__copyright__ = "Copyright 2012, Lluís Vilanova " +__license__ = "GPL version 2 or (at your option) any later version" + +__maintainer__ = "Stefan Hajnoczi" +__email__ = "stefanha@linux.vnet.ibm.com" + + +from tracetool import out + + +def begin(events): + out('/* This file is autogenerated by tracetool, do not edit. */') diff --git a/scripts/tracetool/format/stap.py b/scripts/tracetool/format/stap.py new file mode 100644 index 0000000..50a4c69 --- /dev/null +++ b/scripts/tracetool/format/stap.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Generate .stp file (DTrace with SystemTAP only). +""" + +__author__ = "Lluís Vilanova " +__copyright__ = "Copyright 2012, Lluís Vilanova " +__license__ = "GPL version 2 or (at your option) any later version" + +__maintainer__ = "Stefan Hajnoczi" +__email__ = "stefanha@linux.vnet.ibm.com" + + +from tracetool import out + + +def begin(events): + out('/* This file is autogenerated by tracetool, do not edit. */')