trace backend: introduce multi tracing backend
PATCH v2 1/1 trace backend: introduce multi tracing backend
This patch implements "multi tracing backend" which enables several tracing backend simultaneously.
QEMU has multiple trace backends, but one of them needs to be chosen at compile time. When investigating issues of QEMU, it'd be much more convenient if we can use multiple trace backends without recompiling, especially 'ftrace backend' and 'dtrace backend'. From the performance perspective, 'ftrace backend' should be the one which runs while the system is in operation, and it provides useful information. But, for some issues, 'dtrace backend' is needed for investigation as 'dtrace backend' provides more information. This patch enables both 'ftrace backend' and 'dtrace backend' (, and some other backends if necessary) at compile time so that we can switch between the two without recompiling.
usage:
We have only to set some tracing backends as follows.
$ ./configure --enable-trace-backend=ftrace,dtrace
Of course, we can compile with single backend as well as before.
$ ./configure --enable-trace-backend=simple
Changes from v1:
- Based on tracing-next branch
- Support ust backend
- Change the way to check whether each tracing backend is included in $trace_backend into the way to use grep
- Add comment on compatible checking in tracetool.generate()
- Change tracetool.backend.compatible() to check "supported_formats" of each backend
- Eliminate CONFIG_TRACE_DTRACE include from tracetool/backend/common.py
- Define SDT_USE_VARIADIC in genrated-tracers.h in order to avoid compilation error when enabling dtrace and ust simultaneously
- Revert tracetool.backend.dtrace.{d(),stap()} back
- Change multi.c:trace_backend_init() to figure out what is wrong when *_backend_init() fails
--- Makefile | 4 +- configure | 16 +++-- scripts/tracetool.py | 9 ++- scripts/tracetool/__init__.py | 31 +++++--- scripts/tracetool/backend/__init__.py | 32 +++++---- scripts/tracetool/backend/common.py | 101 ++++++++++++++++++++++++++ scripts/tracetool/backend/dtrace.py | 33 +++++---- scripts/tracetool/backend/events.py | 2 +- scripts/tracetool/backend/ftrace.py | 60 ++++++++------- scripts/tracetool/backend/simple.py | 128 ++++++++++++++++----------------- scripts/tracetool/backend/stderr.py | 43 ++++++----- scripts/tracetool/backend/ust.py | 36 +++++----- trace/Makefile.objs | 22 ++++-- trace/ftrace.c | 25 +------ trace/ftrace.h | 1 + trace/multi.c | 51 +++++++++++++ trace/simple.c | 18 +----- trace/simple.h | 1 + trace/stderr.c | 30 -------- 19 files changed, 382 insertions(+), 261 deletions(-) create mode 100644 scripts/tracetool/backend/common.py create mode 100644 trace/multi.c delete mode 100644 trace/stderr.c
Makefile +2 -2
@@ -52,12 +52,12 @@ GENERATED_HEADERS += trace/generated-events.h GENERATED_SOURCES += trace/generated-events.c GENERATED_HEADERS += trace/generated-tracers.h -ifeq ($(TRACE_BACKEND),dtrace) +ifeq ($(findstring dtrace,$(TRACE_BACKEND)),dtrace) GENERATED_HEADERS += trace/generated-tracers-dtrace.h endif GENERATED_SOURCES += trace/generated-tracers.c -ifeq ($(TRACE_BACKEND),ust) +ifeq ($(findstring ust,$(TRACE_BACKEND)),ust) GENERATED_HEADERS += trace/generated-ust-provider.h GENERATED_SOURCES += trace/generated-ust.c endif
configure +9 -7
@@ -3363,7 +3363,7 @@ fi ########################################## # For 'ust' backend, test if ust headers are present -if test "$trace_backend" = "ust"; then +if echo "$trace_backend" | grep ust >/dev/null; then cat > $TMPC << EOF #include <lttng/tracepoint.h> int main(void) { return 0; }
@@ -3389,7 +3389,7 @@ fi ########################################## # For 'dtrace' backend, test if 'dtrace' command is present -if test "$trace_backend" = "dtrace"; then +if echo "$trace_backend" | grep dtrace >/dev/null; then if ! has 'dtrace' ; then error_exit "dtrace command is not found in PATH $PATH" fi
@@ -4280,26 +4280,27 @@ echo "TRACE_BACKEND=$trace_backend" >> $config_host_mak if test "$trace_backend" = "nop"; then echo "CONFIG_TRACE_NOP=y" >> $config_host_mak fi -if test "$trace_backend" = "simple"; then + +if echo "$trace_backend" | grep simple >/dev/null; then echo "CONFIG_TRACE_SIMPLE=y" >> $config_host_mak trace_default=no # Set the appropriate trace file. trace_file="\"$trace_file-\" FMT_pid" fi -if test "$trace_backend" = "stderr"; then +if echo "$trace_backend" | grep stderr >/dev/null; then echo "CONFIG_TRACE_STDERR=y" >> $config_host_mak trace_default=no fi -if test "$trace_backend" = "ust"; then +if echo "$trace_backend" | grep ust >/dev/null; then echo "CONFIG_TRACE_UST=y" >> $config_host_mak fi -if test "$trace_backend" = "dtrace"; then +if echo "$trace_backend" | grep dtrace >/dev/null; then echo "CONFIG_TRACE_DTRACE=y" >> $config_host_mak if test "$trace_backend_stap" = "yes" ; then echo "CONFIG_TRACE_SYSTEMTAP=y" >> $config_host_mak fi fi -if test "$trace_backend" = "ftrace"; then +if echo "$trace_backend" | grep ftrace >/dev/null; then if test "$linux" = "yes" ; then echo "CONFIG_TRACE_FTRACE=y" >> $config_host_mak trace_default=no
@@ -4307,6 +4308,7 @@ if test "$trace_backend" = "ftrace"; then feature_not_found "ftrace(trace backend)" fi fi + echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak if test "$trace_default" = "yes"; then echo "CONFIG_TRACE_DEFAULT=y" >> $config_host_mak
scripts/tracetool.py +5 -4
@@ -112,10 +112,11 @@ def main(args): error_opt("backend not set") if check_backend: - if tracetool.backend.exists(arg_backend): - sys.exit(0) - else: - sys.exit(1) + for backend in arg_backend.split(","): + if tracetool.backend.exists(backend): + sys.exit(0) + else: + sys.exit(1) if arg_format == "stap": if binary is None:
scripts/tracetool/__init__.py +19 -12
@@ -242,16 +242,23 @@ def generate(fevents, format, backend, if not tracetool.format.exists(mformat): raise TracetoolError("unknown format: %s" % format) - backend = str(backend) - if len(backend) is 0: - raise TracetoolError("backend not set") - mbackend = backend.replace("-", "_") - if not tracetool.backend.exists(mbackend): - raise TracetoolError("unknown backend: %s" % backend) + backends = str(backend).split(",") + for backend in backends: + if len(backend) is 0: + raise TracetoolError("backend not set") - if not tracetool.backend.compatible(mbackend, mformat): - raise TracetoolError("backend '%s' not compatible with format '%s'" % - (backend, format)) + # At least one backend must support the format + compat = False + for backend in backends: + mbackend = backend.replace("-", "_") + if not tracetool.backend.exists(mbackend): + raise TracetoolError("unknown backend: %s" % backend) + + compat |= tracetool.backend.compatible(mbackend, mformat) + + if not compat: + raise TracetoolError("backends '%s' not compatible with format '%s'" % + (",".join(backends), format)) import tracetool.backend.dtrace tracetool.backend.dtrace.BINARY = binary
@@ -259,15 +266,15 @@ def generate(fevents, format, backend, events = _read_events(fevents) - if backend == "nop": + if backends == ["nop"]: ( e.properies.add("disable") for e in events ) tracetool.format.generate_begin(mformat, events) - tracetool.backend.generate("nop", format, + tracetool.backend.generate(["nop"], format, [ e for e in events if "disable" in e.properties ]) - tracetool.backend.generate(backend, format, + tracetool.backend.generate(backends, format, [ e for e in events if "disable" not in e.properties ])
scripts/tracetool/backend/__init__.py +19 -13
@@ -102,28 +102,34 @@ def compatible(backend, format): if backend == "nop": return True else: - func = tracetool.try_import("tracetool.backend." + backend, - format, None)[1] - return func is not None + # Check whether format is declared in supported_formats. + supported_formats = tracetool.try_import("tracetool.backend." + backend, + "supported_formats")[1] + return format in supported_formats def _empty(events): pass -def generate(backend, format, events): - """Generate the per-event output for the given (backend, format) pair.""" - if not compatible(backend, format): - raise ValueError("backend '%s' not compatible with format '%s'" % - (backend, format)) +def generate(backends, format, events): + """Generate the per-event output for the given (backends, format) pair.""" - backend = backend.replace("-", "_") + # At least one backend must support the format + compat = False + for backend in backends: + compat |= compatible(backend, format) + if not compat: + raise ValueError("backends '%s' not compatible with format '%s'" % + (",".join(backends), format)) + + backends = map(lambda x: x.replace("-", "_"), backends) format = format.replace("-", "_") - if backend == "nop": + if backends == ["nop"]: func = tracetool.try_import("tracetool.format." + format, "nop", _empty)[1] + func(events) else: - func = tracetool.try_import("tracetool.backend." + backend, + func = tracetool.try_import("tracetool.backend.common", format, None)[1] - - func(events) + func(backends, events)
scripts/tracetool/backend/common.py new file +101 -0
101 lines not on this page · raw message
scripts/tracetool/backend/dtrace.py +18 -15
@@ -21,6 +21,8 @@ PUBLIC = True PROBEPREFIX = None +supported_formats = ['c', 'h', 'd', 'stap'] + def _probeprefix(): if PROBEPREFIX is None: raise ValueError("you must set PROBEPREFIX")
@@ -34,25 +36,25 @@ def _binary(): raise ValueError("you must set BINARY") return BINARY - -def c(events): +def c_head(): pass - -def h(events): - out('#include "trace/generated-tracers-dtrace.h"', +def c_body(num, event): + out('{ /* dtrace */', + ' QEMU_%(uppername)s(%(argnames)s);', + '}', + uppername = event.name.upper(), + argnames = ", ".join(event.args.names()), + ) + +def h_head(): + out('#define SDT_USE_VARIADIC', + '#include <sys/sdt.h>', + '#include "trace/generated-tracers-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 h_body(event): + pass def d(events): out('provider qemu {')
@@ -107,3 +109,4 @@ def stap(events): out('}') out() +
scripts/tracetool/backend/events.py +1 -1
@@ -15,7 +15,7 @@ __license__ = "GPL version 2 or (at your option) any later version" __maintainer__ = "Stefan Hajnoczi" __email__ = "[email protected]" - +supported_formats = ['events_c', 'events_h'] def events_h(events): pass
scripts/tracetool/backend/ftrace.py +32 -28
69 lines not on this page · raw message
scripts/tracetool/backend/simple.py +63 -65
145 lines not on this page · raw message
scripts/tracetool/backend/stderr.py +23 -20
54 lines not on this page · raw message
scripts/tracetool/backend/ust.py +19 -17
@@ -17,29 +17,31 @@ from tracetool import out PUBLIC = True +supported_formats = ['c', 'h', 'ust_events_c', 'ust_events_h'] -def c(events): +def c_head(): pass +def c_body(num, event): + argnames = ", ".join(event.args.names()) + if len(event.args) > 0: + argnames = ", " + argnames -def h(events): + out('{ /* ust */', + ' tracepoint(qemu, %(name)s%(tp_args)s);', + '}', + name = event.name, + args = event.args, + tp_args = argnames, + ) + +def h_head(): out('#include <lttng/tracepoint.h>', '#include "trace/generated-ust-provider.h"', '') - for e in events: - argnames = ", ".join(e.args.names()) - if len(e.args) > 0: - argnames = ", " + argnames - - out('static inline void trace_%(name)s(%(args)s)', - '{', - ' tracepoint(qemu, %(name)s%(tp_args)s);', - '}', - '', - name = e.name, - args = e.args, - tp_args = argnames, - ) + +def h_body(event): + pass def ust_events_c(events): pass
@@ -79,4 +81,4 @@ def ust_events_h(events): ')', '', name = e.name, - ) + )
trace/Makefile.objs +16 -6
@@ -3,7 +3,7 @@ ###################################################################### # Auto-generated event descriptions for LTTng ust code -ifeq ($(TRACE_BACKEND),ust) +ifeq ($(findstring ust,$(TRACE_BACKEND)),ust) $(obj)/generated-ust-provider.h: $(obj)/generated-ust-provider.h-timestamp $(obj)/generated-ust-provider.h-timestamp: $(SRC_PATH)/trace-events $(call quiet-command,$(TRACETOOL) \
@@ -60,7 +60,7 @@ $(obj)/generated-tracers.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/conf ###################################################################### # Auto-generated tracing routines (non-DTrace) -ifneq ($(TRACE_BACKEND),dtrace) +ifneq ($(findstring dtrace,$(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_DIR)/config-host.mak
@@ -79,7 +79,14 @@ 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) +ifeq ($(findstring dtrace,$(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_DIR)/config-host.mak + $(call quiet-command,$(TRACETOOL) \ + --format=c \ + --backend=$(TRACE_BACKEND) \ + < $< > $@," GEN $(patsubst %-timestamp,%,$@)") $(obj)/generated-tracers.dtrace: $(obj)/generated-tracers.dtrace-timestamp $(obj)/generated-tracers.dtrace-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak $(call quiet-command,$(TRACETOOL) \
@@ -91,15 +98,18 @@ $(obj)/generated-tracers.dtrace-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR) $(obj)/generated-tracers-dtrace.h: $(obj)/generated-tracers.dtrace $(call quiet-command,dtrace -o $@ -h -s $<, " GEN $@") -$(obj)/generated-tracers.o: $(obj)/generated-tracers.dtrace +$(obj)/generated-tracers.o: $(obj)/generated-tracers.dtrace $(obj)/generated-tracers.c $(obj)/generated-tracers.h endif ###################################################################### # Backend code -util-obj-$(CONFIG_TRACE_DEFAULT) += default.o +ifeq ($(CONFIG_TRACE_DEFAULT),y) +util-obj-y += default.o +else +util-obj-y += multi.o +endif util-obj-$(CONFIG_TRACE_SIMPLE) += simple.o -util-obj-$(CONFIG_TRACE_STDERR) += stderr.o util-obj-$(CONFIG_TRACE_FTRACE) += ftrace.o util-obj-$(CONFIG_TRACE_UST) += generated-ust.o util-obj-y += control.o
trace/ftrace.c +1 -24
@@ -42,35 +42,13 @@ static int find_debugfs(char *debugfs)return 1 ; } -void trace_print_events (FILE *stream,fprintf_function stream_printf) -{ -TraceEventID i; - -for (i =0 ; i <trace_event_count (); i++) { -TraceEvent *ev =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 = state; -} - -bool trace_backend_init (const char *events,const char *file) +bool ftrace_backend_init (const char *events,const char *file) {char debugfs[PATH_MAX ];char path[PATH_MAX ];int debugfs_found;int trace_fd =-1 ; -if (file) { -fprintf (stderr,"error: -trace file=...: " -"option not supported by the selected tracing backend\n" ); -return false; - } - debugfs_found =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; } -trace_backend_init_events (events);return true; }
trace/ftrace.h +1 -0
@@ -6,5 +6,6 @@#define STR (x) _STR(x)extern int trace_marker_fd; +bool ftrace_backend_init (const char *events,const char *file);#endif /* ! TRACE_FTRACE_H */
trace/multi.c new file +51 -0
51 lines not on this page · raw message
trace/simple.c +1 -17
@@ -366,22 +366,6 @@ void st_flush_trace_buffer(void)flush_trace_file (true); } -void trace_print_events (FILE *stream,fprintf_function stream_printf) -{ -unsigned int i; - -for (i =0 ; i <trace_event_count (); i++) { -TraceEvent *ev =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 = state; -} -/* Helper function to create a thread with signals blocked. Use glib's * portable threads since QEMU abstractions cannot be used due to reentrancy in * the tracer. Also note the signal masking on POSIX hosts so that the thread
@@ -410,7 +394,7 @@ static GThread *trace_thread_create(GThreadFunc fn)return thread; } -bool trace_backend_init (const char *events,const char *file) +bool simpletrace_backend_init (const char *events,const char *file) {GThread *thread;
trace/simple.h +1 -0
@@ -54,4 +54,5 @@ void trace_record_write_str(TraceBufferRecord *rec, const char *s, uint32_t slen*/ void trace_record_finish (TraceBufferRecord *rec); +bool simpletrace_backend_init (const char *events,const char *file);#endif /* TRACE_SIMPLE_H */
trace/stderr.c deleted +0 -30
@@ -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 =0 ; i <trace_event_count (); i++) { -TraceEvent *ev =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 = state; -} - -bool trace_backend_init (const char *events,const char *file) -{ -if (file) { -fprintf (stderr,"error: -trace file=...: " -"option not supported by the selected tracing backend\n" ); -return false; - } -trace_backend_init_events (events); -return true; -}
Signature · 1 line
1.7.1
Quoted 2 lines · Kazuya Saito
This patch implements "multi tracing backend" which enables several tracing backend simultaneously.
This series raises some conflicts with the one I'm preparing for TCG tracing.
In order to make it simpler to eventually integrate both, I've been preparing a cleanup of some of the tracing infrastructure. I've also put some of the changes here as a followup of the cleanup series.
I'll send them later for discussion.
Thanks,
Lluis
Signature · 4 lines
"And it's much the same thing with knowledge, for whenever you learn something new, the whole world becomes that much richer." -- The Princess of Pure Reason, as told by Norton Juster in The Phantom Tollbooth