From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33515) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WtztY-0006uN-Ap for qemu-devel@nongnu.org; Mon, 09 Jun 2014 09:45:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WtztT-00046T-0s for qemu-devel@nongnu.org; Mon, 09 Jun 2014 09:45:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:30326) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WtztS-000468-HP for qemu-devel@nongnu.org; Mon, 09 Jun 2014 09:45:46 -0400 From: Stefan Hajnoczi Date: Mon, 9 Jun 2014 15:45:15 +0200 Message-Id: <1402321522-18408-8-git-send-email-stefanha@redhat.com> In-Reply-To: <1402321522-18408-1-git-send-email-stefanha@redhat.com> References: <1402321522-18408-1-git-send-email-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 4/5] trace: Multi-backend tracing List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , =?UTF-8?q?Llu=C3=ADs=20Vilanova?= , Stefan Hajnoczi From: Llu=C3=ADs Vilanova Adds support to compile QEMU with multiple tracing backends at the same t= ime. For example, you can compile QEMU with: $ ./configure --enable-trace-backends=3Dftrace,dtrace Where 'ftrace' can be handy for having an in-flight record of events, and= 'dtrace' can be later used to extract more information from the system. This patch allows having both available without recompiling QEMU. Signed-off-by: Llu=C3=ADs Vilanova Signed-off-by: Stefan Hajnoczi --- .travis.yml | 8 +++--- Makefile | 4 +-- Makefile.target | 4 +-- configure | 47 ++++++++++++++++-------------= ---- docs/tracing.txt | 4 +-- qemu-io.c | 2 +- scripts/tracetool.py | 43 +++++++++++++++--------------= - scripts/tracetool/__init__.py | 24 ++++++++--------- scripts/tracetool/backend/__init__.py | 15 ++++++----- trace/Makefile.objs | 32 +++++++++++------------ trace/control-internal.h | 4 +-- trace/control.c | 49 +++++++++++++++++++++++++++++= ++++-- trace/control.h | 27 +++---------------- trace/default.c | 40 ---------------------------- trace/ftrace.c | 25 +----------------- trace/ftrace.h | 5 ++++ trace/simple.c | 19 +------------- trace/simple.h | 1 + trace/stderr.c | 30 --------------------- vl.c | 4 +-- 20 files changed, 153 insertions(+), 234 deletions(-) delete mode 100644 trace/default.c delete mode 100644 trace/stderr.c diff --git a/.travis.yml b/.travis.yml index 04da973..89c30ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -66,16 +66,16 @@ matrix: compiler: gcc # All the trace backends (apart from dtrace) - env: TARGETS=3Di386-softmmu,x86_64-softmmu - EXTRA_CONFIG=3D"--enable-trace-backend=3Dstderr" + EXTRA_CONFIG=3D"--enable-trace-backends=3Dstderr" compiler: gcc - env: TARGETS=3Di386-softmmu,x86_64-softmmu - EXTRA_CONFIG=3D"--enable-trace-backend=3Dsimple" + EXTRA_CONFIG=3D"--enable-trace-backends=3Dsimple" compiler: gcc - env: TARGETS=3Di386-softmmu,x86_64-softmmu - EXTRA_CONFIG=3D"--enable-trace-backend=3Dftrace" + EXTRA_CONFIG=3D"--enable-trace-backends=3Dftrace" TEST_CMD=3D"" compiler: gcc - env: TARGETS=3Di386-softmmu,x86_64-softmmu EXTRA_PKGS=3D"liblttng-ust-dev liburcu-dev" - EXTRA_CONFIG=3D"--enable-trace-backend=3Dust" + EXTRA_CONFIG=3D"--enable-trace-backends=3Dust" compiler: gcc diff --git a/Makefile b/Makefile index d830483..3c8f19c 100644 --- a/Makefile +++ b/Makefile @@ -52,12 +52,12 @@ GENERATED_HEADERS +=3D trace/generated-events.h GENERATED_SOURCES +=3D trace/generated-events.c =20 GENERATED_HEADERS +=3D trace/generated-tracers.h -ifeq ($(TRACE_BACKEND),dtrace) +ifeq ($(findstring dtrace,$(TRACE_BACKENDS)),dtrace) GENERATED_HEADERS +=3D trace/generated-tracers-dtrace.h endif GENERATED_SOURCES +=3D trace/generated-tracers.c =20 -ifeq ($(TRACE_BACKEND),ust) +ifeq ($(findstring ust,$(TRACE_BACKENDS)),ust) GENERATED_HEADERS +=3D trace/generated-ust-provider.h GENERATED_SOURCES +=3D trace/generated-ust.c endif diff --git a/Makefile.target b/Makefile.target index 9986047..8155496 100644 --- a/Makefile.target +++ b/Makefile.target @@ -49,7 +49,7 @@ endif $(QEMU_PROG).stp-installed: $(SRC_PATH)/trace-events $(call quiet-command,$(TRACETOOL) \ --format=3Dstap \ - --backend=3D$(TRACE_BACKEND) \ + --backends=3D$(TRACE_BACKENDS) \ --binary=3D$(bindir)/$(QEMU_PROG) \ --target-name=3D$(TARGET_NAME) \ --target-type=3D$(TARGET_TYPE) \ @@ -58,7 +58,7 @@ $(QEMU_PROG).stp-installed: $(SRC_PATH)/trace-events $(QEMU_PROG).stp: $(SRC_PATH)/trace-events $(call quiet-command,$(TRACETOOL) \ --format=3Dstap \ - --backend=3D$(TRACE_BACKEND) \ + --backends=3D$(TRACE_BACKENDS) \ --binary=3D$(realpath .)/$(QEMU_PROG) \ --target-name=3D$(TARGET_NAME) \ --target-type=3D$(TARGET_TYPE) \ diff --git a/configure b/configure index 0e516f9..a994f41 100755 --- a/configure +++ b/configure @@ -182,6 +182,10 @@ path_of() { return 1 } =20 +have_backend () { + echo "$trace_backends" | grep "$1" >/dev/null +} + # default parameters source_path=3D`dirname "$0"` cpu=3D"" @@ -293,7 +297,7 @@ pkgversion=3D"" pie=3D"" zero_malloc=3D"" qom_cast_debug=3D"yes" -trace_backend=3D"nop" +trace_backends=3D"nop" trace_file=3D"trace" spice=3D"" rbd=3D"" @@ -753,7 +757,10 @@ for opt do ;; --target-list=3D*) target_list=3D"$optarg" ;; - --enable-trace-backend=3D*) trace_backend=3D"$optarg" + --enable-trace-backends=3D*) trace_backends=3D"$optarg" + ;; + # XXX: backwards compatibility + --enable-trace-backend=3D*) trace_backends=3D"$optarg" ;; --with-trace-file=3D*) trace_file=3D"$optarg" ;; @@ -1320,7 +1327,7 @@ Advanced options (experts only): --disable-docs disable documentation build --disable-vhost-net disable vhost-net acceleration support --enable-vhost-net enable vhost-net acceleration support - --enable-trace-backend=3DB Set trace backend + --enable-trace-backends=3DB Set trace backend Available backends: $($python $source_path/sc= ripts/tracetool.py --list-backends) --with-trace-file=3DNAME Full PATH,NAME of file to store traces Default:trace- @@ -3666,15 +3673,15 @@ fi ########################################## # check if trace backend exists =20 -$python "$source_path/scripts/tracetool.py" "--backend=3D$trace_backend"= --check-backend > /dev/null 2> /dev/null +$python "$source_path/scripts/tracetool.py" "--backends=3D$trace_backend= s" --check-backends > /dev/null 2> /dev/null if test "$?" -ne 0 ; then - error_exit "invalid trace backend" \ - "Please choose a supported trace backend." + error_exit "invalid trace backends" \ + "Please choose supported trace backends." fi =20 ########################################## # For 'ust' backend, test if ust headers are present -if test "$trace_backend" =3D "ust"; then +if have_backend "ust"; then cat > $TMPC << EOF #include int main(void) { return 0; } @@ -3700,7 +3707,7 @@ fi =20 ########################################## # For 'dtrace' backend, test if 'dtrace' command is present -if test "$trace_backend" =3D "dtrace"; then +if have_backend "dtrace"; then if ! has 'dtrace' ; then error_exit "dtrace command is not found in PATH $PATH" fi @@ -4170,7 +4177,7 @@ echo "uuid support $uuid" echo "libcap-ng support $cap_ng" echo "vhost-net support $vhost_net" echo "vhost-scsi support $vhost_scsi" -echo "Trace backend $trace_backend" +echo "Trace backends $trace_backends" if test "$trace_backend" =3D "simple"; then echo "Trace output file $trace_file-" fi @@ -4664,43 +4671,35 @@ if test "$tpm" =3D "yes"; then fi fi =20 -# use default implementation for tracing backend-specific routines -trace_default=3Dyes -echo "TRACE_BACKEND=3D$trace_backend" >> $config_host_mak -if test "$trace_backend" =3D "nop"; then +echo "TRACE_BACKENDS=3D$trace_backends" >> $config_host_mak +if have_backend "nop"; then echo "CONFIG_TRACE_NOP=3Dy" >> $config_host_mak fi -if test "$trace_backend" =3D "simple"; then +if have_backend "simple"; then echo "CONFIG_TRACE_SIMPLE=3Dy" >> $config_host_mak - trace_default=3Dno # Set the appropriate trace file. trace_file=3D"\"$trace_file-\" FMT_pid" fi -if test "$trace_backend" =3D "stderr"; then +if have_backend "stderr"; then echo "CONFIG_TRACE_STDERR=3Dy" >> $config_host_mak - trace_default=3Dno fi -if test "$trace_backend" =3D "ust"; then +if have_backend "ust"; then echo "CONFIG_TRACE_UST=3Dy" >> $config_host_mak fi -if test "$trace_backend" =3D "dtrace"; then +if have_backend "dtrace"; then echo "CONFIG_TRACE_DTRACE=3Dy" >> $config_host_mak if test "$trace_backend_stap" =3D "yes" ; then echo "CONFIG_TRACE_SYSTEMTAP=3Dy" >> $config_host_mak fi fi -if test "$trace_backend" =3D "ftrace"; then +if have_backend "ftrace"; then if test "$linux" =3D "yes" ; then echo "CONFIG_TRACE_FTRACE=3Dy" >> $config_host_mak - trace_default=3Dno else feature_not_found "ftrace(trace backend)" "ftrace requires Linux" fi fi echo "CONFIG_TRACE_FILE=3D$trace_file" >> $config_host_mak -if test "$trace_default" =3D "yes"; then - echo "CONFIG_TRACE_DEFAULT=3Dy" >> $config_host_mak -fi =20 if test "$rdma" =3D "yes" ; then echo "CONFIG_RDMA=3Dy" >> $config_host_mak diff --git a/docs/tracing.txt b/docs/tracing.txt index bf2e15c..c6ab1c1 100644 --- a/docs/tracing.txt +++ b/docs/tracing.txt @@ -9,7 +9,7 @@ for debugging, profiling, and observing execution. =20 1. Build with the 'simple' trace backend: =20 - ./configure --enable-trace-backend=3Dsimple + ./configure --enable-trace-backends=3Dsimple make =20 2. Create a file with the events you want to trace: @@ -142,7 +142,7 @@ script. The trace backend is chosen at configure time and only one trace backend= can be built into the binary: =20 - ./configure --trace-backend=3Dsimple + ./configure --trace-backends=3Dsimple =20 For a list of supported trace backends, try ./configure --help or see be= low. =20 diff --git a/qemu-io.c b/qemu-io.c index 795cf46..b55a550 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -433,7 +433,7 @@ int main(int argc, char **argv) } break; case 'T': - if (!trace_backend_init(optarg, NULL)) { + if (!trace_init_backends(optarg, NULL)) { exit(1); /* error message will have been printed */ } break; diff --git a/scripts/tracetool.py b/scripts/tracetool.py index 5f4890f..83bde7b 100755 --- a/scripts/tracetool.py +++ b/scripts/tracetool.py @@ -6,7 +6,7 @@ Command-line wrapper for the tracetool machinery. """ =20 __author__ =3D "Llu=C3=ADs Vilanova " -__copyright__ =3D "Copyright 2012, Llu=C3=ADs Vilanova " +__copyright__ =3D "Copyright 2012-2014, Llu=C3=ADs Vilanova " __license__ =3D "GPL version 2 or (at your option) any later version" =20 __maintainer__ =3D "Stefan Hajnoczi" @@ -32,7 +32,7 @@ def error_opt(msg =3D None): format_descr =3D "\n".join([ " %-15s %s" % (n, d) for n,d in tracetool.format.get_list() ]) error_write("""\ -Usage: %(script)s --format=3D --backend=3D [] +Usage: %(script)s --format=3D --backends=3D [= ] =20 Backends: %(backends)s @@ -43,7 +43,7 @@ Formats: Options: --help This help message. --list-backends Print list of available backends. - --check-backend Check if the given backend is valid. + --check-backends Check if the given backend is valid. --binary Full path to QEMU binary. --target-type QEMU emulator target type ('system' or 'use= r'). --target-name QEMU emulator target name. @@ -65,16 +65,17 @@ def main(args): global _SCRIPT _SCRIPT =3D args[0] =20 - long_opts =3D [ "backend=3D", "format=3D", "help", "list-backends",= "check-backend" ] - long_opts +=3D [ "binary=3D", "target-type=3D", "target-name=3D", "p= robe-prefix=3D" ] + long_opts =3D ["backends=3D", "format=3D", "help", "list-backends", + "check-backends"] + long_opts +=3D ["binary=3D", "target-type=3D", "target-name=3D", "pr= obe-prefix=3D"] =20 try: opts, args =3D getopt.getopt(args[1:], "", long_opts) except getopt.GetoptError, err: error_opt(str(err)) =20 - check_backend =3D False - arg_backend =3D "" + check_backends =3D False + arg_backends =3D [] arg_format =3D "" binary =3D None target_type =3D None @@ -84,8 +85,8 @@ def main(args): if opt =3D=3D "--help": error_opt() =20 - elif opt =3D=3D "--backend": - arg_backend =3D arg + elif opt =3D=3D "--backends": + arg_backends =3D arg.split(",") elif opt =3D=3D "--format": arg_format =3D arg =20 @@ -93,8 +94,8 @@ def main(args): public_backends =3D tracetool.backend.get_list(only_public =3D= True) out(", ".join([ b for b,_ in public_backends ])) sys.exit(0) - elif opt =3D=3D "--check-backend": - check_backend =3D True + elif opt =3D=3D "--check-backends": + check_backends =3D True =20 elif opt =3D=3D "--binary": binary =3D arg @@ -108,14 +109,14 @@ def main(args): else: error_opt("unhandled option: %s" % opt) =20 - if arg_backend is None: - error_opt("backend not set") + if len(arg_backends) =3D=3D 0: + error_opt("no backends specified") =20 - if check_backend: - if tracetool.backend.exists(arg_backend): - sys.exit(0) - else: - sys.exit(1) + if check_backends: + for backend in arg_backends: + if not tracetool.backend.exists(backend): + sys.exit(1) + sys.exit(0) =20 if arg_format =3D=3D "stap": if binary is None: @@ -126,11 +127,11 @@ def main(args): error_opt("--target-name is required for SystemTAP tapset ge= nerator") =20 if probe_prefix is None: - probe_prefix =3D ".".join([ "qemu", target_type, target_name= ]) + probe_prefix =3D ".".join(["qemu", target_type, target_name]= ) =20 try: - tracetool.generate(sys.stdin, arg_format, arg_backend, - binary =3D binary, probe_prefix =3D probe_pre= fix) + tracetool.generate(sys.stdin, arg_format, arg_backends, + binary=3Dbinary, probe_prefix=3Dprobe_prefix) except tracetool.TracetoolError, e: error_opt(str(e)) =20 diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.p= y index eccf552..e8e8edc 100644 --- a/scripts/tracetool/__init__.py +++ b/scripts/tracetool/__init__.py @@ -233,9 +233,9 @@ def try_import(mod_name, attr_name=3DNone, attr_defau= lt=3DNone): return False, None =20 =20 -def generate(fevents, format, backend, +def generate(fevents, format, backends, binary=3DNone, probe_prefix=3DNone): - """Generate the output for the given (format, backend) pair. + """Generate the output for the given (format, backends) pair. =20 Parameters ---------- @@ -243,8 +243,8 @@ def generate(fevents, format, backend, Event description file. format : str Output format name. - backend : str - Output backend name. + backends : list + Output backend names. binary : str or None See tracetool.backend.dtrace.BINARY. probe_prefix : str or None @@ -258,15 +258,13 @@ def generate(fevents, format, backend, raise TracetoolError("format not set") if not tracetool.format.exists(format): raise TracetoolError("unknown format: %s" % format) - format =3D format.replace("-", "_") - - backend =3D str(backend) - if len(backend) is 0: - raise TracetoolError("backend not set") - if not tracetool.backend.exists(backend): - raise TracetoolError("unknown backend: %s" % backend) - backend =3D backend.replace("-", "_") - backend =3D tracetool.backend.Wrapper(backend, format) + + if len(backends) is 0: + raise TracetoolError("no backends specified") + for backend in backends: + if not tracetool.backend.exists(backend): + raise TracetoolError("unknown backend: %s" % backend) + backend =3D tracetool.backend.Wrapper(backends, format) =20 import tracetool.backend.dtrace tracetool.backend.dtrace.BINARY =3D binary diff --git a/scripts/tracetool/backend/__init__.py b/scripts/tracetool/ba= ckend/__init__.py index 5e36f04..5bfa1ef 100644 --- a/scripts/tracetool/backend/__init__.py +++ b/scripts/tracetool/backend/__init__.py @@ -99,17 +99,18 @@ def exists(name): =20 =20 class Wrapper: - def __init__(self, backend, format): - self._backend =3D backend.replace("-", "_") + def __init__(self, backends, format): + self._backends =3D [backend.replace("-", "_") for backend in bac= kends] self._format =3D format.replace("-", "_") - assert exists(self._backend) + assert all(exists(backend) for backend in self._backends) assert tracetool.format.exists(self._format) =20 def _run_function(self, name, *args, **kwargs): - func =3D tracetool.try_import("tracetool.backend." + self._backe= nd, - name % self._format, None)[1] - if func is not None: - func(*args, **kwargs) + for backend in self._backends: + func =3D tracetool.try_import("tracetool.backend." + backend= , + name % self._format, None)[1] + if func is not None: + func(*args, **kwargs) =20 def generate_begin(self, events): self._run_function("generate_%s_begin", events) diff --git a/trace/Makefile.objs b/trace/Makefile.objs index 6a30467..d7a8696 100644 --- a/trace/Makefile.objs +++ b/trace/Makefile.objs @@ -3,12 +3,12 @@ ###################################################################### # Auto-generated event descriptions for LTTng ust code =20 -ifeq ($(TRACE_BACKEND),ust) +ifeq ($(findstring ust,$(TRACE_BACKENDS)),ust) $(obj)/generated-ust-provider.h: $(obj)/generated-ust-provider.h-timesta= mp $(obj)/generated-ust-provider.h-timestamp: $(SRC_PATH)/trace-events $(call quiet-command,$(TRACETOOL) \ --format=3Dust-events-h \ - --backend=3D$(TRACE_BACKEND) \ + --backends=3D$(TRACE_BACKENDS) \ < $< > $@," GEN $(patsubst %-timestamp,%,$@)") @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp= ,%,$@) =20 @@ -16,7 +16,7 @@ $(obj)/generated-ust.c: $(obj)/generated-ust.c-timestam= p $(BUILD_DIR)/config-hos $(obj)/generated-ust.c-timestamp: $(SRC_PATH)/trace-events $(call quiet-command,$(TRACETOOL) \ --format=3Dust-events-c \ - --backend=3D$(TRACE_BACKEND) \ + --backends=3D$(TRACE_BACKENDS) \ < $< > $@," GEN $(patsubst %-timestamp,%,$@)") @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp= ,%,$@) =20 @@ -31,7 +31,7 @@ $(obj)/generated-events.h: $(obj)/generated-events.h-ti= mestamp $(obj)/generated-events.h-timestamp: $(SRC_PATH)/trace-events $(call quiet-command,$(TRACETOOL) \ --format=3Devents-h \ - --backend=3D$(TRACE_BACKEND) \ + --backends=3D$(TRACE_BACKENDS) \ < $< > $@," GEN $(patsubst %-timestamp,%,$@)") @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp= ,%,$@) =20 @@ -39,7 +39,7 @@ $(obj)/generated-events.c: $(obj)/generated-events.c-ti= mestamp $(BUILD_DIR)/conf $(obj)/generated-events.c-timestamp: $(SRC_PATH)/trace-events $(call quiet-command,$(TRACETOOL) \ --format=3Devents-c \ - --backend=3D$(TRACE_BACKEND) \ + --backends=3D$(TRACE_BACKENDS) \ < $< > $@," GEN $(patsubst %-timestamp,%,$@)") @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp= ,%,$@) =20 @@ -54,23 +54,21 @@ $(obj)/generated-tracers.h: $(obj)/generated-tracers.= h-timestamp $(obj)/generated-tracers.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_D= IR)/config-host.mak $(call quiet-command,$(TRACETOOL) \ --format=3Dh \ - --backend=3D$(TRACE_BACKEND) \ + --backends=3D$(TRACE_BACKENDS) \ < $< > $@," GEN $(patsubst %-timestamp,%,$@)") =20 ###################################################################### # Auto-generated tracing routines (non-DTrace) =20 -ifneq ($(TRACE_BACKEND),dtrace) $(obj)/generated-tracers.c: $(obj)/generated-tracers.c-timestamp @cmp -s $< $@ || cp $< $@ $(obj)/generated-tracers.c-timestamp: $(SRC_PATH)/trace-events $(BUILD_D= IR)/config-host.mak $(call quiet-command,$(TRACETOOL) \ --format=3Dc \ - --backend=3D$(TRACE_BACKEND) \ + --backends=3D$(TRACE_BACKENDS) \ < $< > $@," GEN $(patsubst %-timestamp,%,$@)") =20 $(obj)/generated-tracers.o: $(obj)/generated-tracers.c $(obj)/generated-= tracers.h -endif =20 =20 ###################################################################### @@ -79,27 +77,27 @@ endif # Normal practice is to name DTrace probe file with a '.d' extension # but that gets picked up by QEMU's Makefile as an external dependency # rule file. So we use '.dtrace' instead -ifeq ($(TRACE_BACKEND),dtrace) -$(obj)/generated-tracers.dtrace: $(obj)/generated-tracers.dtrace-timesta= mp -$(obj)/generated-tracers.dtrace-timestamp: $(SRC_PATH)/trace-events $(BU= ILD_DIR)/config-host.mak +ifeq ($(findstring dtrace,$(TRACE_BACKENDS)),dtrace) +$(obj)/generated-tracers-dtrace.dtrace: $(obj)/generated-tracers-dtrace.= dtrace-timestamp +$(obj)/generated-tracers-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-even= ts $(BUILD_DIR)/config-host.mak $(call quiet-command,$(TRACETOOL) \ --format=3Dd \ - --backend=3D$(TRACE_BACKEND) \ + --backends=3D$(TRACE_BACKENDS) \ < $< > $@," GEN $(patsubst %-timestamp,%,$@)") @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp= ,%,$@) =20 -$(obj)/generated-tracers-dtrace.h: $(obj)/generated-tracers.dtrace +$(obj)/generated-tracers-dtrace.h: $(obj)/generated-tracers-dtrace.dtrac= e $(call quiet-command,dtrace -o $@ -h -s $<, " GEN $@") =20 -$(obj)/generated-tracers.o: $(obj)/generated-tracers.dtrace +$(obj)/generated-tracers-dtrace.o: $(obj)/generated-tracers-dtrace.dtrac= e + +util-obj-y +=3D generated-tracers-dtrace.o endif =20 ###################################################################### # Backend code =20 -util-obj-$(CONFIG_TRACE_DEFAULT) +=3D default.o util-obj-$(CONFIG_TRACE_SIMPLE) +=3D simple.o -util-obj-$(CONFIG_TRACE_STDERR) +=3D stderr.o util-obj-$(CONFIG_TRACE_FTRACE) +=3D ftrace.o util-obj-$(CONFIG_TRACE_UST) +=3D generated-ust.o util-obj-y +=3D control.o diff --git a/trace/control-internal.h b/trace/control-internal.h index b3f587e..5a8df28 100644 --- a/trace/control-internal.h +++ b/trace/control-internal.h @@ -1,7 +1,7 @@ /* * Interface for configuring and controlling the state of tracing events. * - * Copyright (C) 2011-2012 Llu=C3=ADs Vilanova + * Copyright (C) 2011-2014 Llu=C3=ADs Vilanova * * This work is licensed under the terms of the GNU GPL, version 2 or la= ter. * See the COPYING file in the top-level directory. @@ -61,7 +61,7 @@ static inline void trace_event_set_state_dynamic(TraceE= vent *ev, bool state) { assert(ev !=3D NULL); assert(trace_event_get_state_static(ev)); - return trace_event_set_state_dynamic_backend(ev, state); + ev->dstate =3D state; } =20 #endif /* TRACE__CONTROL_INTERNAL_H */ diff --git a/trace/control.c b/trace/control.c index 4aa02cf..45e6604 100644 --- a/trace/control.c +++ b/trace/control.c @@ -1,13 +1,19 @@ /* * Interface for configuring and controlling the state of tracing events. * - * Copyright (C) 2011-2012 Llu=C3=ADs Vilanova + * Copyright (C) 2011-2014 Llu=C3=ADs Vilanova * * This work is licensed under the terms of the GNU GPL, version 2 or la= ter. * See the COPYING file in the top-level directory. */ =20 #include "trace/control.h" +#ifdef CONFIG_TRACE_SIMPLE +#include "trace/simple.h" +#endif +#ifdef CONFIG_TRACE_FTRACE +#include "trace/ftrace.h" +#endif =20 =20 TraceEvent *trace_event_name(const char *name) @@ -79,7 +85,20 @@ TraceEvent *trace_event_pattern(const char *pat, Trace= Event *ev) return NULL; } =20 -void trace_backend_init_events(const char *fname) +void trace_print_events(FILE *stream, fprintf_function stream_printf) +{ + TraceEventID i; + + for (i =3D 0; i < trace_event_count(); i++) { + TraceEvent *ev =3D trace_event_id(i); + stream_printf(stream, "%s [Event ID %u] : state %u\n", + trace_event_get_name(ev), i, + trace_event_get_state_static(ev) && + trace_event_get_state_dynamic(ev)); + } +} + +static void trace_init_events(const char *fname) { if (fname =3D=3D NULL) { return; @@ -130,3 +149,29 @@ void trace_backend_init_events(const char *fname) exit(1); } } + +bool trace_init_backends(const char *events, const char *file) +{ +#ifdef CONFIG_TRACE_SIMPLE + if (!st_init(file)) { + fprintf(stderr, "failed to initialize simple tracing backend.\n"= ); + return false; + } +#else + if (file) { + fprintf(stderr, "error: -trace file=3D...: " + "option not supported by the selected tracing backends\n= "); + return false; + } +#endif + +#ifdef CONFIG_TRACE_FTRACE + if (!ftrace_init()) { + fprintf(stderr, "failed to initialize ftrace backend.\n"); + return false; + } +#endif + + trace_init_events(events); + return true; +} diff --git a/trace/control.h b/trace/control.h index cde8260..e1ec033 100644 --- a/trace/control.h +++ b/trace/control.h @@ -1,7 +1,7 @@ /* * Interface for configuring and controlling the state of tracing events. * - * Copyright (C) 2011-2012 Llu=C3=ADs Vilanova + * Copyright (C) 2011-2014 Llu=C3=ADs Vilanova * * This work is licensed under the terms of the GNU GPL, version 2 or la= ter. * See the COPYING file in the top-level directory. @@ -146,26 +146,17 @@ static bool trace_event_get_state_dynamic(TraceEven= t *ev); */ static void trace_event_set_state_dynamic(TraceEvent *ev, bool state); =20 -/** - * trace_event_set_state_dynamic_backend: - * - * Warning: This function must be implemented by each tracing backend. - */ -void trace_event_set_state_dynamic_backend(TraceEvent *ev, bool state); - =20 =20 /** * trace_print_events: * * Print the state of all events. - * - * Warning: This function must be implemented by each tracing backend. */ void trace_print_events(FILE *stream, fprintf_function stream_printf); =20 /** - * trace_backend_init: + * trace_init_backends: * @events: Name of file with events to be enabled at startup; may be NU= LL. * Corresponds to commandline option "-trace events=3D...". * @file: Name of trace output file; may be NULL. @@ -173,19 +164,9 @@ void trace_print_events(FILE *stream, fprintf_functi= on stream_printf); * * Initialize the tracing backend. * - * Warning: This function must be implemented by each tracing backend. - * - * Returns: Whether the backend could be successfully initialized. - */ -bool trace_backend_init(const char *events, const char *file); - -/** - * trace_backend_init_events: - * @fname: Name of file with events to enable; may be NULL. - * - * Generic function to initialize the state of events. + * Returns: Whether the backends could be successfully initialized. */ -void trace_backend_init_events(const char *fname); +bool trace_init_backends(const char *events, const char *file); =20 =20 #include "trace/control-internal.h" diff --git a/trace/default.c b/trace/default.c deleted file mode 100644 index 6e07a47..0000000 --- a/trace/default.c +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Default implementation for backend initialization from commandline. - * - * Copyright (C) 2011-2012 Llu=C3=ADs Vilanova - * - * This work is licensed under the terms of the GNU GPL, version 2. See - * the COPYING file in the top-level directory. - */ - -#include "trace/control.h" - - -void trace_print_events(FILE *stream, fprintf_function stream_printf) -{ - fprintf(stderr, "warning: " - "cannot print the trace events with the current backend\n"); - stream_printf(stream, "error: " - "operation not supported with the current backend\n"); -} - -void trace_event_set_state_dynamic_backend(TraceEvent *ev, bool state) -{ - fprintf(stderr, "warning: " - "cannot set the state of a trace event with the current back= end\n"); -} - -bool trace_backend_init(const char *events, const char *file) -{ - if (events) { - fprintf(stderr, "error: -trace events=3D...: " - "option not supported by the selected tracing backend\n"= ); - return false; - } - if (file) { - fprintf(stderr, "error: -trace file=3D...: " - "option not supported by the selected tracing backend\n"= ); - return false; - } - return true; -} diff --git a/trace/ftrace.c b/trace/ftrace.c index 46b7fdb..a7ae371 100644 --- a/trace/ftrace.c +++ b/trace/ftrace.c @@ -42,35 +42,13 @@ static int find_debugfs(char *debugfs) return 1; } =20 -void trace_print_events(FILE *stream, fprintf_function stream_printf) -{ - TraceEventID i; - - for (i =3D 0; i < trace_event_count(); i++) { - TraceEvent *ev =3D trace_event_id(i); - stream_printf(stream, "%s [Event ID %u] : state %u\n", - trace_event_get_name(ev), i, trace_event_get_state= _dynamic(ev)); - } -} - -void trace_event_set_state_dynamic_backend(TraceEvent *ev, bool state) -{ - ev->dstate =3D state; -} - -bool trace_backend_init(const char *events, const char *file) +bool ftrace_init(void) { char debugfs[PATH_MAX]; char path[PATH_MAX]; int debugfs_found; int trace_fd =3D -1; =20 - if (file) { - fprintf(stderr, "error: -trace file=3D...: " - "option not supported by the selected tracing backend\n"= ); - return false; - } - debugfs_found =3D find_debugfs(debugfs); if (debugfs_found) { snprintf(path, PATH_MAX, "%s/tracing/tracing_on", debugfs); @@ -97,6 +75,5 @@ bool trace_backend_init(const char *events, const char = *file) return false; } =20 - trace_backend_init_events(events); return true; } diff --git a/trace/ftrace.h b/trace/ftrace.h index 94cb8d5..863e052 100644 --- a/trace/ftrace.h +++ b/trace/ftrace.h @@ -1,10 +1,15 @@ #ifndef TRACE_FTRACE_H #define TRACE_FTRACE_H =20 +#include + + #define MAX_TRACE_STRLEN 512 #define _STR(x) #x #define STR(x) _STR(x) =20 extern int trace_marker_fd; =20 +bool ftrace_init(void); + #endif /* ! TRACE_FTRACE_H */ diff --git a/trace/simple.c b/trace/simple.c index 5a2e188..a8f923c 100644 --- a/trace/simple.c +++ b/trace/simple.c @@ -368,22 +368,6 @@ void st_flush_trace_buffer(void) flush_trace_file(true); } =20 -void trace_print_events(FILE *stream, fprintf_function stream_printf) -{ - unsigned int i; - - for (i =3D 0; i < trace_event_count(); i++) { - TraceEvent *ev =3D trace_event_id(i); - stream_printf(stream, "%s [Event ID %u] : state %u\n", - trace_event_get_name(ev), i, trace_event_get_state= _dynamic(ev)); - } -} - -void trace_event_set_state_dynamic_backend(TraceEvent *ev, bool state) -{ - ev->dstate =3D state; -} - /* Helper function to create a thread with signals blocked. Use glib's * portable threads since QEMU abstractions cannot be used due to reentr= ancy in * the tracer. Also note the signal masking on POSIX hosts so that the = thread @@ -412,7 +396,7 @@ static GThread *trace_thread_create(GThreadFunc fn) return thread; } =20 -bool trace_backend_init(const char *events, const char *file) +bool st_init(const char *file) { GThread *thread; =20 @@ -430,7 +414,6 @@ bool trace_backend_init(const char *events, const cha= r *file) } =20 atexit(st_flush_trace_buffer); - trace_backend_init_events(events); st_set_trace_file(file); return true; } diff --git a/trace/simple.h b/trace/simple.h index 5260d9a..6997996 100644 --- a/trace/simple.h +++ b/trace/simple.h @@ -21,6 +21,7 @@ void st_print_trace_file_status(FILE *stream, fprintf_function stream_pr= intf); void st_set_trace_file_enabled(bool enable); bool st_set_trace_file(const char *file); +bool st_init(const char *file); void st_flush_trace_buffer(void); =20 typedef struct { diff --git a/trace/stderr.c b/trace/stderr.c deleted file mode 100644 index e212efd..0000000 --- a/trace/stderr.c +++ /dev/null @@ -1,30 +0,0 @@ -#include "trace.h" -#include "trace/control.h" - - -void trace_print_events(FILE *stream, fprintf_function stream_printf) -{ - TraceEventID i; - - for (i =3D 0; i < trace_event_count(); i++) { - TraceEvent *ev =3D trace_event_id(i); - stream_printf(stream, "%s [Event ID %u] : state %u\n", - trace_event_get_name(ev), i, trace_event_get_state= _dynamic(ev)); - } -} - -void trace_event_set_state_dynamic_backend(TraceEvent *ev, bool state) -{ - ev->dstate =3D state; -} - -bool trace_backend_init(const char *events, const char *file) -{ - if (file) { - fprintf(stderr, "error: -trace file=3D...: " - "option not supported by the selected tracing backend\n"= ); - return false; - } - trace_backend_init_events(events); - return true; -} diff --git a/vl.c b/vl.c index a3def97..ac0e3d7 100644 --- a/vl.c +++ b/vl.c @@ -4039,7 +4039,7 @@ int main(int argc, char **argv, char **envp) } =20 if (!is_daemonized()) { - if (!trace_backend_init(trace_events, trace_file)) { + if (!trace_init_backends(trace_events, trace_file)) { exit(1); } } @@ -4559,7 +4559,7 @@ int main(int argc, char **argv, char **envp) os_setup_post(); =20 if (is_daemonized()) { - if (!trace_backend_init(trace_events, trace_file)) { + if (!trace_init_backends(trace_events, trace_file)) { exit(1); } } --=20 1.9.3