From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:56215) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCYBE-0007xZ-3t for qemu-devel@nongnu.org; Tue, 27 Mar 2012 11:19:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SCYB7-0004ZZ-Vf for qemu-devel@nongnu.org; Tue, 27 Mar 2012 11:19:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:14444) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCYB7-0004ZL-Nd for qemu-devel@nongnu.org; Tue, 27 Mar 2012 11:19:21 -0400 Date: Tue, 27 Mar 2012 17:19:11 +0200 From: Alon Levy Message-ID: <20120327151911.GL32389@garlic> References: <20120326173743.20814.3629.stgit@ginnungagap.bsc.es> <20120326173823.20814.27306.stgit@ginnungagap.bsc.es> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <20120326173823.20814.27306.stgit@ginnungagap.bsc.es> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [RFC PATCH v2 7/8] tracetool: Add support for the 'dtrace' backend List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?iso-8859-1?Q?Llu=EDs?= Vilanova Cc: stefanha@gmail.com, qemu-devel@nongnu.org On Mon, Mar 26, 2012 at 07:38:23PM +0200, Llu=EDs Vilanova wrote: > Signed-off-by: Llu=EDs Vilanova > --- > scripts/tracetool.py | 31 ++++++++++ > scripts/tracetool/__init__.py | 8 +++ > scripts/tracetool/backend/dtrace.py | 104 +++++++++++++++++++++++++++= ++++++++ > scripts/tracetool/format/d.py | 20 +++++++ > scripts/tracetool/format/stap.py | 20 +++++++ > 5 files changed, 183 insertions(+), 0 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 >=20 > diff --git a/scripts/tracetool.py b/scripts/tracetool.py > index 22623ae..2dd9da0 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 'u= ser'). > + --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 =3D False > arg_backend =3D "" > arg_format =3D "" > + binary =3D None > + target_type =3D None > + target_arch =3D None > + probe_prefix =3D None > for opt, arg in opts: > if opt =3D=3D "--help": > error_opt() > @@ -87,6 +96,15 @@ def main(args): > elif opt =3D=3D "--check-backend": > check_backend =3D True > =20 > + elif opt =3D=3D "--binary": > + binary =3D arg > + elif opt =3D=3D '--target-type': > + target_type =3D arg > + elif opt =3D=3D '--target-arch': > + target_arch =3D arg > + elif opt =3D=3D '--probe-prefix': > + probe_prefix =3D arg > + > else: > error_opt("unhandled option: %s" % opt) > =20 > @@ -101,6 +119,19 @@ def main(args): > =20 > kwargs =3D {} > =20 > + if format =3D=3D "stap": > + if binary is None: > + error_opt("--binary is required for SystemTAP tapset gener= ator") > + 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 =3D ".".join([ "qemu", target_type, target_ar= ch ]) > + kwargs["binary"] =3D binary > + kwargs["probe_prefix"] =3D probe_prefix > + > try: > tracetool.generate(sys.stdin, arg_format, arg_backend, **kwarg= s) > except tracetool.TracetoolError as e: > diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__= .py > index d8e5cdd..d21f88a 100644 > --- a/scripts/tracetool/__init__.py > +++ b/scripts/tracetool/__init__.py > @@ -167,6 +167,9 @@ def generate(fevents, format, backend, **options): > # fix strange python error (UnboundLocalError tracetool) > import tracetool > =20 > + binary =3D options.pop("binary", None) > + probe_prefix =3D options.pop("probe_prefix", None) > + > if len(options) > 0: > raise ValueError("unknown options: " + ", ".join(options)) > =20 > @@ -188,6 +191,11 @@ def generate(fevents, format, backend, **options): > raise TracetoolError("backend '%s' not compatible with format = '%s'" % > (backend, format)) > =20 > + if backend =3D=3D "dtrace": > + import tracetool.backend.dtrace > + tracetool.backend.dtrace.BINARY =3D binary > + tracetool.backend.dtrace.PROBEPREFIX =3D probe_prefix > + > events =3D _read_events(fevents) > =20 > if backend =3D=3D "nop": > diff --git a/scripts/tracetool/backend/dtrace.py b/scripts/tracetool/ba= ckend/dtrace.py > new file mode 100644 > index 0000000..7c2051c > --- /dev/null > +++ b/scripts/tracetool/backend/dtrace.py > @@ -0,0 +1,104 @@ > +#!/usr/bin/env python > +# -*- coding: utf-8 -*- > + > +""" > +DTrace/SystemTAP backend. > +""" > + > +__author__ =3D "Llu=EDs Vilanova " > +__copyright__ =3D "Copyright 2012, Llu=EDs Vilanova " > +__license__ =3D "GPL version 2 or (at your option) any later versio= n" > + > +__maintainer__ =3D "Stefan Hajnoczi" > +__email__ =3D "stefanha@linux.vnet.ibm.com" > + > + > +from tracetool import out > + > + > +PUBLIC =3D True > + > + > +PROBEPREFIX =3D None > + > +def _probeprefix(): > + if PROBEPREFIX is None: > + raise ValueError("you must set PROBEPREFIX") > + return PROBEPREFIX > + > + > +BINARY =3D 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 =3D e.args > + > + # DTrace provider syntax expects foo() for empty > + # params, not foo(void) > + if args =3D=3D 'void': This fails. since args is now an Arguments instace. Fixed by changing to: + if str(args) =3D=3D 'void': > + args =3D '' > + > + # 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 =3D process("%(binary)s").= mark("%(name)s")' % > + { > + 'probeprefix': _probeprefix(), > + 'name': e.name, > + 'binary': _binary(), > + }, > + '{') > + > + i =3D 1 > + if len(e.args) > 0: > + for name in e.args.names(): > + # 'limit' is a reserved keyword > + if name =3D=3D 'limit': > + name =3D '_limit' > + out(' %s =3D $arg%d;' % (name.lstrip(), i)) > + i +=3D 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__ =3D "Llu=EDs Vilanova " > +__copyright__ =3D "Copyright 2012, Llu=EDs Vilanova " > +__license__ =3D "GPL version 2 or (at your option) any later versio= n" > + > +__maintainer__ =3D "Stefan Hajnoczi" > +__email__ =3D "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/forma= t/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__ =3D "Llu=EDs Vilanova " > +__copyright__ =3D "Copyright 2012, Llu=EDs Vilanova " > +__license__ =3D "GPL version 2 or (at your option) any later versio= n" > + > +__maintainer__ =3D "Stefan Hajnoczi" > +__email__ =3D "stefanha@linux.vnet.ibm.com" > + > + > +from tracetool import out > + > + > +def begin(events): > + out('/* This file is autogenerated by tracetool, do not edit. */') >=20 >=20