Received: from eggs.gnu.org ([208.118.235.92]:34828) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UTzgE-0007Xi-OI for qemu-devel@nongnu.org; Sun, 21 Apr 2013 15:12:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UTzgD-0001i8-1I for qemu-devel@nongnu.org; Sun, 21 Apr 2013 15:12:06 -0400 Received: from roura.ac.upc.es ([147.83.33.10]:33181) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UTzgC-0001hr-Je for qemu-devel@nongnu.org; Sun, 21 Apr 2013 15:12:04 -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 r3LJC4k0001783 for ; Sun, 21 Apr 2013 21:12:04 +0200 Received: from localhost (unknown [84.88.51.85]) by gw.ac.upc.edu (Postfix) with ESMTP id D8E986B01A4 for ; Sun, 21 Apr 2013 21:12:03 +0200 (CEST) From: =?utf-8?b?TGx1w61z?= Vilanova Date: Sun, 21 Apr 2013 21:12:03 +0200 Message-Id: <20130421191203.8947.46803.stgit@fimbulvetr.bsc.es> In-Reply-To: <20130421191129.8947.77964.stgit@fimbulvetr.bsc.es> References: <20130421191129.8947.77964.stgit@fimbulvetr.bsc.es> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v3 06/24] instrument: [none] Add null instrumentation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Splits the QEMU-side tracing interface into different layers (in order of= nested invocation): * trace_* The interface used by QEMU code to signal traceable/instrumentable even= ts (now generated according to the selected instrumentation type). * qi_event_* The interface provided by the user's instrumentation code (for which QE= MU provides default implementations depending on the instrumentation type). * qi_event_*_trace / qi_event_*_nop The interface provided by QEMU to the user's instrumentation code to in= voke the tracing backend. The nop variant simply does nothing. * trace_*_backend The interface provided by the tracing backend in QEMU. Originally expos= ed as 'trace_*' routines. The 'none' instrumentation type (this one) skips through the qi_* layers = and directly calls 'trace_*_backend' from the 'trace_*' routines (providing t= he original tracing behaviour). Signed-off-by: Llu=C3=ADs Vilanova --- .gitignore | 2 + Makefile | 3 + configure | 31 ++++++++++++++ include/trace.h | 2 - instrument/Makefile.objs | 24 +++++++++++ scripts/tracetool/__init__.py | 9 +++- scripts/tracetool/backend/instr_none.py | 41 +++++++++++++++++++ scripts/tracetool/format/api_h.py | 39 ++++++++++++++++++ scripts/tracetool/format/qemu_h.py | 68 +++++++++++++++++++++++++= ++++++ 9 files changed, 216 insertions(+), 3 deletions(-) create mode 100644 instrument/Makefile.objs create mode 100644 scripts/tracetool/backend/instr_none.py create mode 100644 scripts/tracetool/format/api_h.py create mode 100644 scripts/tracetool/format/qemu_h.py diff --git a/.gitignore b/.gitignore index 487813a..2c9695c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,8 @@ trace/generated-tracers.dtrace trace/generated-events.h trace/generated-events.c libcacard/trace/generated-tracers.c +instrument/generated-tracers.h +instrument/qemu-instr/events.h *-timestamp *-softmmu *-darwin-user diff --git a/Makefile b/Makefile index 0b6e6a1..028ef83 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,9 @@ GENERATED_HEADERS =3D config-host.h qemu-options.def GENERATED_HEADERS +=3D qmp-commands.h qapi-types.h qapi-visit.h GENERATED_SOURCES +=3D qmp-marshal.c qapi-types.c qapi-visit.c =20 +GENERATED_HEADERS +=3D instrument/generated-tracers.h +GENERATED_HEADERS +=3D instrument/qemu-instr/events.h + GENERATED_HEADERS +=3D trace/generated-events.h GENERATED_SOURCES +=3D trace/generated-events.c =20 diff --git a/configure b/configure index a3bd336..2cddce4 100755 --- a/configure +++ b/configure @@ -224,6 +224,7 @@ zero_malloc=3D"" trace_events=3D`dirname $0`/trace-events trace_backend=3D"nop" trace_file=3D"trace" +trace_instrument=3D"none" spice=3D"" rbd=3D"" smartcard_nss=3D"" @@ -646,6 +647,8 @@ for opt do ;; --with-trace-file=3D*) trace_file=3D"$optarg" ;; + --with-trace-instrument=3D*) trace_instrument=3D"$optarg" + ;; --enable-gprof) gprof=3D"yes" ;; --enable-gcov) gcov=3D"yes" @@ -1166,6 +1169,8 @@ echo " --enable-trace-backend=3DB Set trace backen= d" echo " Available backends:" $($python "$source= _path"/scripts/tracetool.py --list-backends) echo " --with-trace-file=3DNAME Full PATH,NAME of file to store trace= s" echo " Default:trace-" +echo " --with-trace-instrument=3DTYPE" +echo " Trace instrumentation type (none; defau= lt: $trace_instrument)" echo " --disable-spice disable spice" echo " --enable-spice enable spice" echo " --enable-rbd enable building the rados block device = (rbd)" @@ -3062,6 +3067,15 @@ if test "$trace_backend" =3D "dtrace"; then fi =20 ########################################## +# Check instrumentation type +case "$trace_instrument" in +none) ;; +*) echo "Error: invalid trace instrumentation type: $trace_instrum= ent" + exit 1 + ;; +esac + +########################################## # __sync_fetch_and_and requires at least -march=3Di486. Many toolchains # use i686 as default anyway, but for those that don't, an explicit # specification is necessary @@ -3437,6 +3451,7 @@ echo "vhost-net support $vhost_net" echo "Trace events $trace_events" echo "Trace backend $trace_backend" echo "Trace output file $trace_file-" +echo "Trace instrument $trace_instrument" echo "spice support $spice ($spice_protocol_version/$spice_server_ve= rsion)" echo "rbd support $rbd" echo "xfsctl support $xfs" @@ -3859,6 +3874,22 @@ if test "$trace_default" =3D "yes"; then echo "CONFIG_TRACE_DEFAULT=3Dy" >> $config_host_mak fi =20 +########################################## +# trace instrumentation +config_qi=3Dinstrument/qemu-instr/config.h +mkdir -p `dirname $config_qi` +echo "/* Automatically generated by configure - do not modify */" > $con= fig_qi + +echo "TRACE_INSTRUMENT_BACKEND=3Dinstr-$trace_instrument" >> $config_hos= t_mak + +if test "$trace_instrument" =3D "none"; then + echo "#define QI_TYPE_CONFIG_NONE 1" >> $config_qi + echo "CONFIG_TRACE_INSTRUMENT_NONE=3Dy" >> $config_host_mak +else + echo "CONFIG_TRACE_INSTRUMENT=3Dy" >> $config_host_mak +fi +########################################## + echo "TOOLS=3D$tools" >> $config_host_mak echo "ROMS=3D$roms" >> $config_host_mak echo "MAKE=3D$make" >> $config_host_mak diff --git a/include/trace.h b/include/trace.h index c15f498..5cd06c7 100644 --- a/include/trace.h +++ b/include/trace.h @@ -1,6 +1,6 @@ #ifndef TRACE_H #define TRACE_H =20 -#include "trace/generated-tracers.h" +#include "instrument/generated-tracers.h" =20 #endif /* TRACE_H */ diff --git a/instrument/Makefile.objs b/instrument/Makefile.objs new file mode 100644 index 0000000..9c5d5dc --- /dev/null +++ b/instrument/Makefile.objs @@ -0,0 +1,24 @@ +# -*- mode: makefile -*- + +###################################################################### +# QEMU trace->instrument interface + +$(obj)/generated-tracers.h: $(obj)/generated-tracers.h-timestamp +$(obj)/generated-tracers.h-timestamp: $(TRACE_EVENTS) $(BUILD_DIR)/confi= g-host.mak + $(call quiet-command,$(TRACETOOL) \ + --format=3Dqemu-h \ + --backend=3D$(TRACE_INSTRUMENT_BACKEND) \ + < $< > $@," GEN $(patsubst %-timestamp,%,$@)") + @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp= ,%,$@) + + +###################################################################### +# User interface + +$(obj)/qemu-instr/events.h: $(obj)/qemu-instr/events.h-timestamp +$(obj)/qemu-instr/events.h-timestamp: $(TRACE_EVENTS) $(BUILD_DIR)/confi= g-host.mak + $(call quiet-command,$(TRACETOOL) \ + --format=3Dapi-h \ + --backend=3D$(TRACE_INSTRUMENT_BACKEND) \ + < $< > $@," GEN $(patsubst %-timestamp,%,$@)") + @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp= ,%,$@) diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.p= y index 7e4d651..f849e39 100644 --- a/scripts/tracetool/__init__.py +++ b/scripts/tracetool/__init__.py @@ -122,7 +122,7 @@ class Event(object): =20 _CRE =3D re.compile("((?P.*)\s+)?(?P[^(\s]+)\((?P= [^)]*)\)\s*(?P\".*)?") =20 - _VALID_PROPS =3D set(["disable"]) + _VALID_PROPS =3D set(["disable", "instrument"]) =20 def __init__(self, name, props, fmt, args): """ @@ -146,6 +146,9 @@ class Event(object): if len(unknown_props) > 0: raise ValueError("Unknown properties: %s" % ", ".join(unknow= n_props)) =20 + if "instrument" in self.properties and "disable" in self.propert= ies: + raise ValueError("Cannot instrument a disabled event: %s" % = self.name) + @staticmethod def build(line_str): """Build an Event instance from a string. @@ -175,10 +178,12 @@ class Event(object): =20 =20 QEMU_TRACE =3D "trace_%(name)s" + QEMU_TRACE_BACKEND =3D "trace_%(name)s_backend" + QI_TRACE_INSTRUMENT =3D "qi_event_%(name)s" =20 def api(self, fmt =3D None): if fmt is None: - fmt =3D Event.QEMU_TRACE + fmt =3D Event.QEMU_TRACE_BACKEND return fmt % { "name" : self.name } =20 def _read_events(fobj): diff --git a/scripts/tracetool/backend/instr_none.py b/scripts/tracetool/= backend/instr_none.py new file mode 100644 index 0000000..a1327c0 --- /dev/null +++ b/scripts/tracetool/backend/instr_none.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +No-instrumentation proxy. +""" + +__author__ =3D "Llu=C3=ADs Vilanova " +__copyright__ =3D "Copyright 2012-2013, Llu=C3=ADs Vilanova " +__license__ =3D "GPL version 2 or (at your option) any later version" + +__maintainer__ =3D "Stefan Hajnoczi" +__email__ =3D "stefanha@linux.vnet.ibm.com" + + +from tracetool import out +import tracetool.format.qemu_h + + +def qemu_h(events): + out('#include "instrument/qemu-instr/events.h"', + '', + ) + tracetool.format.qemu_h.process_common(events) + + +def api_h(events): + for e in events: + if "instrument" not in e.properties: + continue + + out('static inline void %(qi)s(%(args)s)', + '{', + ' %(qemu_backend)s(%(argnames)s);', + '}', + '', + qi =3D e.api(e.QI_TRACE_INSTRUMENT), + args =3D e.args, + qemu_backend =3D e.api(e.QEMU_TRACE_BACKEND), + argnames =3D ", ".join(e.args.names()), + ) diff --git a/scripts/tracetool/format/api_h.py b/scripts/tracetool/format= /api_h.py new file mode 100644 index 0000000..70d8e9f --- /dev/null +++ b/scripts/tracetool/format/api_h.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Generate .h for trace instrumentation clients. +""" + +__author__ =3D "Llu=C3=ADs Vilanova " +__copyright__ =3D "Copyright 2012-2013, Llu=C3=ADs Vilanova " +__license__ =3D "GPL version 2 or (at your option) any later version" + +__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. */', + '', + '#ifndef QI__EVENTS_H', + '#define QI__EVENTS_H', + '', + '#ifdef __cplusplus', + 'extern "C" {', + '#endif', + '', + '#include ', + '', + ) + +def end(events): + out('#ifdef __cplusplus', + '}', + '#endif', + '', + '#endif /* QI__EVENTS_H */', + ) diff --git a/scripts/tracetool/format/qemu_h.py b/scripts/tracetool/forma= t/qemu_h.py new file mode 100644 index 0000000..51bd02a --- /dev/null +++ b/scripts/tracetool/format/qemu_h.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Generate .h for trace instrumentation proxy. +""" + +__author__ =3D "Llu=C3=ADs Vilanova " +__copyright__ =3D "Copyright 2012-2013, Llu=C3=ADs Vilanova " +__license__ =3D "GPL version 2 or (at your option) any later version" + +__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. */', + '', + '#ifndef INSTRUMENT__GENERATED_TRACERS_H', + '#define INSTRUMENT__GENERATED_TRACERS_H', + '', + '#include "trace/generated-tracers.h"', + '', + ) + +def end(events): + out('#include "trace/generated-events.h"', + '', + '#endif /* INSTRUMENT__GENERATED_TRACERS_H */', + ) + +def nop(events): + for e in events: + out('static inline void %(qemu)s(%(args)s)', + '{', + ' %(qemu_backend)s(%(argnames)s);', + '}', + '', + qemu =3D e.api(e.QEMU_TRACE), + args =3D e.args, + qemu_backend =3D e.api(e.QEMU_TRACE_BACKEND), + argnames =3D ", ".join(e.args.names()), + ) + +def process_common(events): + for e in events: + if "instrument" not in e.properties: + nop([e]) + continue + + out('static inline void %(qemu)s(%(args)s)', + '{', + '#if defined(QEMU_TOOLS)', + ' %(backend)s(%(argnames)s);', + '#else', + ' %(qi)s(%(argnames)s);', + '#endif', + '}', + '', + qemu =3D e.api(e.QEMU_TRACE), + args =3D e.args, + qi =3D e.api(e.QI_TRACE_INSTRUMENT), + backend =3D e.api(e.QEMU_TRACE_BACKEND), + argnames =3D ", ".join(e.args.names()), + )