trace: Add static tracing to QEMU
PATCH v2 2/14 trace: Add simple built-in tracing backend
In reply to Stefan HajnocziThis patch adds a simple tracer which produces binary trace files. To try out the simple backend:
$ ./configure --trace-backend=simple $ make
After running QEMU you can pretty-print the trace:
$ ./simpletrace.py trace-events /tmp/trace.log
The output of simpletrace.py looks like this:
qemu_realloc 0.699 ptr=0x24363f0 size=0x3 newptr=0x24363f0 qemu_free 0.768 ptr=0x24363f0
^ ^---- timestamp delta (us)
|____ trace event name
trace: Make trace record fields 64-bit
Explicitly use 64-bit fields in trace records so that timestamps and magic numbers work for 32-bit host builds.
Includes fixes from Prerna Saxena <[email protected]>.
--- .gitignore | 1 + Makefile | 2 + Makefile.objs | 3 + configure | 2 +- simpletrace.c | 159 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ simpletrace.h | 26 +++++++++ simpletrace.py | 93 +++++++++++++++++++++++++++++++++ tracetool | 78 ++++++++++++++++++++++++++- 8 files changed, 360 insertions(+), 4 deletions(-) create mode 100644 simpletrace.c create mode 100644 simpletrace.h create mode 100755 simpletrace.py
.gitignore +1 -0
@@ -42,6 +42,7 @@ QMP/qmp-commands.txt *.log *.pdf *.pg +*.pyc *.toc *.tp *.vr
Makefile +2 -0
@@ -112,6 +112,8 @@ trace.c: $(SRC_PATH)/trace-events config-host.mak trace.o: trace.c $(GENERATED_HEADERS) +simpletrace.o: simpletrace.c $(GENERATED_HEADERS) + ###################################################################### qemu-img.o: qemu-img-cmds.h
Makefile.objs +3 -0
@@ -269,6 +269,9 @@ libdis-$(CONFIG_SPARC_DIS) += sparc-dis.o # trace trace-obj-y = trace.o +ifeq ($(TRACE_BACKEND),simple) +trace-obj-y += simpletrace.o +endif vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
configure +1 -1
@@ -900,7 +900,7 @@ echo " --enable-docs enable documentation build" echo " --disable-docs disable documentation build" echo " --disable-vhost-net disable vhost-net acceleration support" echo " --enable-vhost-net enable vhost-net acceleration support" -echo " --trace-backend=B Trace backend nop" +echo " --trace-backend=B Trace backend nop simple" echo "" echo "NOTE: The object files are built at the place where configure is launched" exit 1
simpletrace.c new file +159 -0
159 lines not on this page · raw message
simpletrace.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* Simple trace backend +* +* Copyright IBM, Corp. 2010 +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +* +*/ + +#ifndef SIMPLETRACE_H +#define SIMPLETRACE_H + +#include <stdint.h> + +typedef uint64_t TraceEventID ; + +void trace0 (TraceEventID event); +void trace1 (TraceEventID event,uint64_t x1); +void trace2 (TraceEventID event,uint64_t x1,uint64_t x2); +void trace3 (TraceEventID event,uint64_t x1,uint64_t x2,uint64_t x3); +void trace4 (TraceEventID event,uint64_t x1,uint64_t x2,uint64_t x3,uint64_t x4); +void trace5 (TraceEventID event,uint64_t x1,uint64_t x2,uint64_t x3,uint64_t x4,uint64_t x5); +void trace6 (TraceEventID event,uint64_t x1,uint64_t x2,uint64_t x3,uint64_t x4,uint64_t x5,uint64_t x6); + +#endif /* SIMPLETRACE_H */
simpletrace.py new file +93 -0
93 lines not on this page · raw message
tracetool +75 -3
105 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v2 3/14 trace: Support for dynamically enabling/disabling trace events
In reply to Stefan HajnocziFrom: Prerna Saxena <[email protected]>
This patch adds support for dynamically enabling/disabling of trace events. This is done by internally maintaining each trace event's state, and permitting logging of data from a trace event only if it is in an 'active' state.
Monitor commands added :
1) info trace-events : to view all available trace events and
their state.
2) trace-event NAME on|off : to enable/disable data logging from a
given trace event.
Eg, trace-event paio_submit off
disables logging of data when paio_submit is hit.
By default, all trace-events are disabled. One can enable desired trace-events via the monitor.
trace: Monitor command 'info trace'
Monitor command 'info trace' to display contents of trace buffer
trace: Remove monitor.h dependency from simpletrace
User-mode targets don't have a monitor so the simple trace backend currently does not build on those targets. This patch abstracts the monitor printing interface so there is no direct coupling between simpletrace and the monitor.
--- configure | 3 +++ monitor.c | 40 ++++++++++++++++++++++++++++++++++++++++ qemu-monitor.hx | 25 +++++++++++++++++++++++++ simpletrace.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ simpletrace.h | 10 ++++++++++ tracetool | 24 ++++++++++++++++++++---- 6 files changed, 149 insertions(+), 4 deletions(-)
configure +3 -0
@@ -2468,6 +2468,9 @@ bsd) esac echo "TRACE_BACKEND=$trace_backend" >> $config_host_mak +if test "$trace_backend" = "simple"; then + echo "CONFIG_SIMPLE_TRACE=y" >> $config_host_mak +fi echo "TOOLS=$tools" >> $config_host_mak echo "ROMS=$roms" >> $config_host_mak echo "MAKE=$make" >> $config_host_mak
monitor.c +40 -0
@@ -56,6 +56,9 @@#include "json-parser.h" #include "osdep.h" #include "exec-all.h" +#ifdef CONFIG_SIMPLE_TRACE +#include "trace.h" +#endif //#define DEBUG //#define DEBUG_COMPLETION
@@ -539,6 +542,15 @@ static void do_help_cmd(Monitor *mon, const QDict *qdict)help_cmd (mon,qdict_get_try_str (qdict,"name" )); } +#ifdef CONFIG_SIMPLE_TRACE +static void do_change_trace_event_state (Monitor *mon,const QDict *qdict) +{ +const char *tp_name =qdict_get_str (qdict,"name" ); +bool new_state =qdict_get_bool (qdict,"option" ); +st_change_trace_event_state (tp_name, new_state); +} +#endif +static void user_monitor_complete (void *opaque,QObject *ret_data) {MonitorCompletionData *data = (MonitorCompletionData *)opaque;
@@ -938,6 +950,18 @@ static void do_info_cpu_stats(Monitor *mon) }#endif +#if defined(CONFIG_SIMPLE_TRACE ) +static void do_info_trace (Monitor *mon) +{ +st_print_trace ((FILE *)mon, &monitor_fprintf); +} + +static void do_info_trace_events (Monitor *mon) +{ +st_print_trace_events ((FILE *)mon, &monitor_fprintf); +} +#endif +/** * do_quit(): Quit QEMU execution */
@@ -2594,6 +2618,22 @@ static const mon_cmd_t info_cmds[] = { .help = "show roms", .mhandler.info = do_info_roms, }, +#if defined(CONFIG_SIMPLE_TRACE) + { + .name = "trace", + .args_type = "", + .params = "", + .help = "show current contents of trace buffer", + .mhandler.info = do_info_trace, + }, + { + .name = "trace-events", + .args_type = "", + .params = "", + .help = "show available trace-events & their state", + .mhandler.info = do_info_trace_events, + }, +#endif { .name = NULL, },
qemu-monitor.hx +25 -0
@@ -281,6 +281,22 @@ STEXI Output logs to @var{filename}. ETEXI +#ifdef CONFIG_SIMPLE_TRACE + { + .name = "trace-event", + .args_type = "name:s,option:b", + .params = "name on|off", + .help = "changes status of a specific trace event", + .mhandler.cmd = do_change_trace_event_state, + }, + +STEXI +@item trace-event +@findex trace-event +changes status of a trace event +ETEXI +#endif + { .name = "log", .args_type = "items:s",
@@ -2529,6 +2545,15 @@ show roms @end table ETEXI +#ifdef CONFIG_SIMPLE_TRACE +STEXI +@item info trace +show contents of trace buffer +@item info trace-events +show available trace events and their state +ETEXI +#endif + HXCOMM DO NOT add new commands after 'info', move your addition before it! STEXI
simpletrace.c +51 -0
60 lines not on this page · raw message
simpletrace.h +10 -0
@@ -12,9 +12,16 @@#define SIMPLETRACE_H #include <stdint.h> +#include <stdbool.h> +#include <stdio.h> typedef uint64_t TraceEventID ; +typedef struct { +const char *tp_name; +bool state; +}TraceEvent ; +void trace0 (TraceEventID event);void trace1 (TraceEventID event,uint64_t x1);void trace2 (TraceEventID event,uint64_t x1,uint64_t x2);
@@ -22,5 +29,8 @@ void trace3(TraceEventID event, uint64_t x1, uint64_t x2, uint64_t x3);void trace4 (TraceEventID event,uint64_t x1,uint64_t x2,uint64_t x3,uint64_t x4);void trace5 (TraceEventID event,uint64_t x1,uint64_t x2,uint64_t x3,uint64_t x4,uint64_t x5);void trace6 (TraceEventID event,uint64_t x1,uint64_t x2,uint64_t x3,uint64_t x4,uint64_t x5,uint64_t x6); +void st_print_trace (FILE *stream,int (*stream_printf)(FILE *stream,const char *fmt, ...)); +void st_print_trace_events (FILE *stream,int (*stream_printf)(FILE *stream,const char *fmt, ...)); +void st_change_trace_event_state (const char *tname,bool tstate);#endif /* SIMPLETRACE_H */
tracetool +20 -4
@@ -169,22 +169,38 @@ EOF linetoh_end_simple() { - return + cat <<EOF +#define NR_TRACE_EVENTS $simple_event_num +extern TraceEvent trace_list[NR_TRACE_EVENTS]; +EOF } linetoc_begin_simple() { - return + cat <<EOF +#include "trace.h" + +TraceEvent trace_list[] = { +EOF + simple_event_num=0 + } linetoc_simple() { - return + local name + name=$(get_name "$1") + cat <<EOF +{.tp_name = "$name", .state=0}, +EOF + simple_event_num=$((simple_event_num + 1)) } linetoc_end_simple() { - return + cat <<EOF +}; +EOF } # Process stdin by calling begin, line, and end functions for the backend
Signature · 1 line
1.7.1
v2 cover trace: Add static tracing to QEMU
This patch series adds static tracing to QEMU. It can be used to instrument QEMU code by means of lightweight logging called trace events.
Prerna and I are now posting the entire patch series with a serious eye towards checking we meet users' and developers' tracing needs and with the goal of getting this functionality merged into qemu.git.
Tracing infrastructure allows debugging, performance analysis, and observation to be performed. Right now there are ad-hoc logging calls in some source files which require rebuilding QEMU with certain #defines and perform poorly. This patch series introduces a single tracing infrastructure which is easy to use and can replace ad-hoc techniques.
Two key points:
1. The trace-events file contains the set of defined trace events which can be called from a source file. For example, trace-events has:
qemu_malloc(size_t size, void *ptr) "size %zu ptr %p"
and qemu-malloc.c uses this trace event like this:
#include "trace.h" /* needed for trace event prototype */
void *qemu_malloc(size_t size)
{
void *ptr;
if (!size && !allow_zero_malloc()) {
abort();
}
ptr = oom_check(malloc(size ? size : 1));
trace_qemu_malloc(size, ptr); /* <-- trace event */
return ptr;
}2. The built-in 'simple' trace backend writes binary traces to /tmp/trace-<pid>. They can be pretty-printed like this:
./simpletrace.py trace-events /tmp/trace-*
Although you can also try LTTng Userspace Tracer ('ust' trace backend), the 'simple' trace backend provides commands within the QEMU monitor to enable/disable trace events at runtime. It is easy to use and should serve as a good default trace backend.
The 'simple' trace backend's limitation is that it isn't thread-safe and can therefore only trace correctly when the QEMU global mutex is held.
For full documentation, see:
http://repo.or.cz/w/qemu/stefanha.git/blob_plain/17cc6e48b93d5c85c2de5862a06ee380855783e3:/docs/tracing.txt
The git branch is here:
http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/tracing_v2
Changes in v2:
* add 6th argument to trace record to avoid changing file format later
* add type usage documentation for trace event declarations
* switch to QemuOptsList for -trace command-line option
* use atexit() once and only once to flush the trace buffer
* keep disabled event ids in sync between tracetool and simpletrace.py
* change echo -n to printf for portability
* move #include statements to correct spot in the patch series
* fix style issues from code review
Stefan
PATCH v2 7/14 trace: Add trace file name command-line option
From: Prerna Saxena <[email protected]>
This patch adds an optional command line switch '-trace' to specify the filename to write traces to, when qemu starts.
Eg, If compiled with the 'simple' trace backend,
[temp@system]$ qemu -trace FILENAME IMAGE Allows the binary traces to be written to FILENAME instead of the option set at config-time.
--- qemu-config.c | 18 ++++++++++++++++++ qemu-options.hx | 11 +++++++++++ vl.c | 21 +++++++++++++++++++++ 3 files changed, 50 insertions(+), 0 deletions(-)
qemu-config.c +18 -0
@@ -288,6 +288,21 @@ static QemuOptsList qemu_mon_opts = { }, }; +#ifdef CONFIG_SIMPLE_TRACE +static QemuOptsList qemu_trace_opts = { + .name ="trace" , + .implied_opt_name ="trace" , + .head =QTAILQ_HEAD_INITIALIZER (qemu_trace_opts.head), + .desc = { + { + .name ="file" , + .type =QEMU_OPT_STRING , + }, + {/* end if list */ } + }, +}; +#endif +static QemuOptsList qemu_cpudef_opts = { .name ="cpudef" , .head =QTAILQ_HEAD_INITIALIZER (qemu_cpudef_opts.head),
@@ -346,6 +361,9 @@ static QemuOptsList *vm_config_groups[32] = { &qemu_global_opts, &qemu_mon_opts, &qemu_cpudef_opts, +#ifdef CONFIG_SIMPLE_TRACE + &qemu_trace_opts, +#endif NULL, };
qemu-options.hx +11 -0
@@ -2230,6 +2230,17 @@ Normally QEMU loads a configuration file from @var{sysconfdir}/qemu.conf and @var{sysconfdir}/target-@var{ARCH}.conf on startup. The @code{-nodefconfig} option will prevent QEMU from loading these configuration files at startup. ETEXI +#ifdef CONFIG_SIMPLE_TRACE +DEF("trace", HAS_ARG, QEMU_OPTION_trace, + "-trace\n" + " Specify a trace file to log traces to\n", + QEMU_ARCH_ALL) +STEXI +@item -trace +@findex -trace +Specify a trace file to log output traces to. +ETEXI +#endif HXCOMM This is the last statement. Insert new options before this line! STEXI
vl.c +21 -0
@@ -47,6 +47,10 @@#include <dirent.h> #include <netdb.h> #include <sys/select.h> +#ifdef CONFIG_SIMPLE_TRACE +#include "trace.h" +#endif +#ifdef CONFIG_BSD #include <sys/stat.h> #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
@@ -1823,6 +1827,9 @@ int main(int argc, char **argv, char **envp)int show_vnc_port =0 ;int defconfig =1 ; +#ifdef CONFIG_SIMPLE_TRACE +const char *trace_file =NULL ; +#endif atexit (qemu_run_exit_notifiers);error_set_progname (argv[0 ]);
@@ -2593,6 +2600,14 @@ int main(int argc, char **argv, char **envp) } xen_mode =XEN_ATTACH ;break ; +#ifdef CONFIG_SIMPLE_TRACE +case QEMU_OPTION_trace: + opts =qemu_opts_parse (qemu_find_opts ("trace" ), optarg,0 ); +if (opts) { + trace_file =qemu_opt_get (opts,"file" ); + } +break ; +#endif case QEMU_OPTION_readconfig: {int ret =qemu_read_config_file (optarg);
@@ -2636,6 +2651,12 @@ int main(int argc, char **argv, char **envp) data_dir =CONFIG_QEMU_DATADIR ; } +#ifdef CONFIG_SIMPLE_TRACE +/* +* Set the trace file name, if specified. +*/ +st_set_trace_file (trace_file); +#endif /* * Default to max_cpus = smp_cpus, in case the user doesn't * specify a max_cpus value.
Signature · 1 line
1.7.1
PATCH v2 1/14 trace: Add trace-events file for declaring trace events
In reply to Stefan HajnocziThis patch introduces the trace-events file where trace events can be declared like so:
qemu_malloc(size_t size) "size %zu"qemu_free(void *ptr) "ptr %p"
These trace event declarations are processed by a new tool called tracetool to generate code for the trace events. Trace event declarations are independent of the backend tracing system (LTTng User Space Tracing, ftrace markers, DTrace).
The default "nop" backend generates empty trace event functions. Therefore trace events are disabled by default.
The trace-events file serves two purposes:
1. Adding trace events is easy. It is not necessary to understand the details of a backend tracing system. The trace-events file is a single location where trace events can be declared without code duplication.
2. QEMU is not tightly coupled to one particular backend tracing system. In order to support tracing across QEMU host platforms and to anticipate new backend tracing systems that are currently maturing, it is important to be flexible and not tied to one system.
trace: Rebuild when switching trace backends
Fix to ensure rebuild is properly triggered when switching trace backends using ./configure.
--- .gitignore | 2 + Makefile | 17 ++++- Makefile.objs | 5 ++ Makefile.target | 1 + configure | 18 ++++++ trace-events | 24 ++++++++ tracetool | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 238 insertions(+), 4 deletions(-) create mode 100644 trace-events create mode 100755 tracetool
.gitignore +2 -0
@@ -2,6 +2,8 @@ config-devices.* config-all-devices.* config-host.* config-target.* +trace.h +trace.c *-softmmu *-darwin-user *-linux-user
Makefile +13 -4
@@ -1,6 +1,6 @@ # Makefile for QEMU. -GENERATED_HEADERS = config-host.h +GENERATED_HEADERS = config-host.h trace.h ifneq ($(wildcard config-host.mak),) # Put the all: rule here so that config-host.mak can contain dependencies.
@@ -104,16 +104,24 @@ ui/vnc.o: QEMU_CFLAGS += $(VNC_TLS_CFLAGS) bt-host.o: QEMU_CFLAGS += $(BLUEZ_CFLAGS) +trace.h: $(SRC_PATH)/trace-events config-host.mak + $(call quiet-command,sh $(SRC_PATH)/tracetool --$(TRACE_BACKEND) -h < $< > $@," GEN $@") + +trace.c: $(SRC_PATH)/trace-events config-host.mak + $(call quiet-command,sh $(SRC_PATH)/tracetool --$(TRACE_BACKEND) -c < $< > $@," GEN $@") + +trace.o: trace.c $(GENERATED_HEADERS) + ###################################################################### qemu-img.o: qemu-img-cmds.h qemu-img.o qemu-tool.o qemu-nbd.o qemu-io.o: $(GENERATED_HEADERS) -qemu-img$(EXESUF): qemu-img.o qemu-tool.o qemu-error.o $(block-obj-y) $(qobject-obj-y) +qemu-img$(EXESUF): qemu-img.o qemu-tool.o qemu-error.o $(trace-obj-y) $(block-obj-y) $(qobject-obj-y) -qemu-nbd$(EXESUF): qemu-nbd.o qemu-tool.o qemu-error.o $(block-obj-y) $(qobject-obj-y) +qemu-nbd$(EXESUF): qemu-nbd.o qemu-tool.o qemu-error.o $(trace-obj-y) $(block-obj-y) $(qobject-obj-y) -qemu-io$(EXESUF): qemu-io.o cmd.o qemu-tool.o qemu-error.o $(block-obj-y) $(qobject-obj-y) +qemu-io$(EXESUF): qemu-io.o cmd.o qemu-tool.o qemu-error.o $(trace-obj-y) $(block-obj-y) $(qobject-obj-y) qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx $(call quiet-command,sh $(SRC_PATH)/hxtool -h < $< > $@," GEN $@")
@@ -133,6 +141,7 @@ clean: rm -f *.o *.d *.a $(TOOLS) TAGS cscope.* *.pod *~ */*~ rm -f slirp/*.o slirp/*.d audio/*.o audio/*.d block/*.o block/*.d net/*.o net/*.d fsdev/*.o fsdev/*.d ui/*.o ui/*.d rm -f qemu-img-cmds.h + rm -f trace.c trace.h $(MAKE) -C tests clean for d in $(ALL_SUBDIRS) libhw32 libhw64 libuser libdis libdis-user; do \ if test -d $$d; then $(MAKE) -C $$d $@ || exit 1; fi; \
Makefile.objs +5 -0
@@ -265,6 +265,11 @@ libdis-$(CONFIG_S390_DIS) += s390-dis.o libdis-$(CONFIG_SH4_DIS) += sh4-dis.o libdis-$(CONFIG_SPARC_DIS) += sparc-dis.o +###################################################################### +# trace + +trace-obj-y = trace.o + vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS) vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
Makefile.target +1 -0
@@ -310,6 +310,7 @@ obj-y += $(addprefix $(HWDIR)/, $(hw-obj-y)) endif # CONFIG_SOFTMMU +obj-y += $(addprefix ../, $(trace-obj-y)) obj-$(CONFIG_GDBSTUB_XML) += gdbstub-xml.o $(QEMU_PROG): $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y)
configure +18 -0
@@ -317,6 +317,7 @@ pkgversion="" check_utests="no" user_pie="no" zero_malloc="" +trace_backend="nop" # OS specific if check_define __linux__ ; then
@@ -519,6 +520,8 @@ for opt do ;; --target-list=*) target_list="$optarg" ;; + --trace-backend=*) trace_backend="$optarg" + ;; --enable-gprof) gprof="yes" ;; --static)
@@ -897,6 +900,7 @@ echo " --enable-docs enable documentation build" echo " --disable-docs disable documentation build" echo " --disable-vhost-net disable vhost-net acceleration support" echo " --enable-vhost-net enable vhost-net acceleration support" +echo " --trace-backend=B Trace backend nop" echo "" echo "NOTE: The object files are built at the place where configure is launched" exit 1
@@ -2059,6 +2063,18 @@ if compile_prog "" "" ; then fdatasync=yes fi +########################################## +# check if trace backend exists + +sh "$source_path/tracetool" "--$trace_backend" --check-backend > /dev/null 2> /dev/null +if test "$?" -ne 0 ; then + echo + echo "Error: invalid trace backend" + echo "Please choose a supported trace backend." + echo + exit 1 +fi + # End of CC checks # After here, no more $cc or $ld runs
@@ -2189,6 +2205,7 @@ echo "preadv support $preadv" echo "fdatasync $fdatasync" echo "uuid support $uuid" echo "vhost-net support $vhost_net" +echo "Trace backend $trace_backend" if test $sdl_too_old = "yes"; then echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -2450,6 +2467,7 @@ bsd) ;; esac +echo "TRACE_BACKEND=$trace_backend" >> $config_host_mak echo "TOOLS=$tools" >> $config_host_mak echo "ROMS=$roms" >> $config_host_mak echo "MAKE=$make" >> $config_host_mak
trace-events new file +24 -0
@@ -0,0 +1,24 @@ +# Trace events for debugging and performance instrumentation +# +# This file is processed by the tracetool script during the build. +# +# To add a new trace event: +# +# 1. Choose a name for the trace event. Declare its arguments and format +# string. +# +# 2. Call the trace event from code using trace_##name, e.g. multiwrite_cb() -> +# trace_multiwrite_cb(). The source file must #include "trace.h". +# +# Format of a trace event: +# +# <name>(<type1> <arg1>[, <type2> <arg2>] ...) "<format-string>" +# +# Example: qemu_malloc(size_t size) "size %zu" +# +# The <name> must be a valid as a C function name. +# +# Types should be standard C types. Use void * for pointers because the trace +# system may not have the necessary headers included. +# +# The <format-string> should be a sprintf()-compatible format string.
tracetool new file +175 -0
175 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v2 5/14 trace: Specify trace file name
In reply to Stefan HajnocziFrom: Prerna Saxena <[email protected]>
Allow users to specify a file for trace-outputs at configuration. Also, allow trace files to be annotated by <pid> so each qemu instance has unique traces.
The trace file name can be passed as a config option:
--trace-file=/path/to/file
(Default : /tmp/trace )
At runtime, the pid of the qemu process is appended to the filename so that mutiple qemu instances do not have overlapping logs.
Eg : /tmp/trace-1234 for qemu launched with pid 1234.
I have yet to test this on windows. getpid() is used at many places in code(including vnc.c), so I'm hoping this would be okay too.
--- configure | 14 ++++++++++++++ simpletrace.c | 21 +++++++++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-)
configure +14 -0
@@ -318,6 +318,7 @@ check_utests="no" user_pie="no" zero_malloc="" trace_backend="nop" +trace_file="/tmp/trace" # OS specific if check_define __linux__ ; then
@@ -475,6 +476,7 @@ if test "$mingw32" = "yes" ; then bindir="\${prefix}" sysconfdir="\${prefix}" confsuffix="" + trace_file="trace" fi # find source path
@@ -522,6 +524,8 @@ for opt do ;; --trace-backend=*) trace_backend="$optarg" ;; + --trace-file=*) trace_file="$optarg" + ;; --enable-gprof) gprof="yes" ;; --static)
@@ -901,6 +905,9 @@ echo " --disable-docs disable documentation build" echo " --disable-vhost-net disable vhost-net acceleration support" echo " --enable-vhost-net enable vhost-net acceleration support" echo " --trace-backend=B Trace backend nop simple" +echo " --trace-file=NAME Full PATH,NAME of file to store traces" +echo " Default:/tmp/trace-<pid>" +echo " Default:trace-<pid> on Windows" echo "" echo "NOTE: The object files are built at the place where configure is launched" exit 1
@@ -2206,6 +2213,7 @@ echo "fdatasync $fdatasync" echo "uuid support $uuid" echo "vhost-net support $vhost_net" echo "Trace backend $trace_backend" +echo "Trace output file $trace_file-<pid>" if test $sdl_too_old = "yes"; then echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -2471,6 +2479,12 @@ echo "TRACE_BACKEND=$trace_backend" >> $config_host_mak if test "$trace_backend" = "simple"; then echo "CONFIG_SIMPLE_TRACE=y" >> $config_host_mak fi +# Set the appropriate trace file. +if test "$trace_backend" = "simple"; then + trace_file="\"$trace_file-%u\"" +fi +echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak + echo "TOOLS=$tools" >> $config_host_mak echo "ROMS=$roms" >> $config_host_mak echo "MAKE=$make" >> $config_host_mak
simpletrace.c +17 -4
@@ -54,13 +54,26 @@ static bool write_header(FILE *fp)return fwrite (&header,sizeof header,1 , fp) ==1 ; } +static bool open_trace_file (void ) +{ +char *filename; + +if (asprintf (&filename,CONFIG_TRACE_FILE ,getpid ()) <0 ) { +return false; + } + + trace_fp =fopen (filename,"w" ); +free (filename); +if (!trace_fp) { +return false; + } +return write_header (trace_fp); +} +static void flush_trace_buffer (void ) {if (!trace_fp) { - trace_fp =fopen ("/tmp/trace.log" ,"w" ); -if (trace_fp) { -write_header (trace_fp); - } +open_trace_file (); }if (trace_fp) {size_t unused;/* for when fwrite(3) is declared warn_unused_result */
Signature · 1 line
1.7.1
PATCH v2 8/14 trace: Add LTTng Userspace Tracer backend
In reply to Stefan HajnocziThis patch adds LTTng Userspace Tracer (UST) backend support. The UST system requires no kernel support but libust and liburcu must be installed.
$ ./configure --trace-backend ust $ make
Start the UST daemon:
$ ustd &
List available tracepoints and enable some:
$ ustctl --list-markers $(pgrep qemu)
[...]
{PID: 5458, channel/marker: ust/paio_submit, state: 0, fmt: "acb %p
opaque %p sector_num %lu nb_sectors %lu type %lu" 0x4b32ba}
$ ustctl --enable-marker "ust/paio_submit" $(pgrep qemu)Run the trace:
$ ustctl --create-trace $(pgrep qemu) $ ustctl --start-trace $(pgrep qemu) [...] $ ustctl --stop-trace $(pgrep qemu) $ ustctl --destroy-trace $(pgrep qemu)
Trace results can be viewed using lttv-gui.
More information about UST:
http://lttng.org/ust
trace: Check for LTTng Userspace Tracer headers
When using the 'ust' backend, check if the relevant headers are available at host.
--- configure | 22 +++++++++++++++- tracetool | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 104 insertions(+), 3 deletions(-)
configure +21 -1
@@ -904,7 +904,7 @@ echo " --enable-docs enable documentation build" echo " --disable-docs disable documentation build" echo " --disable-vhost-net disable vhost-net acceleration support" echo " --enable-vhost-net enable vhost-net acceleration support" -echo " --trace-backend=B Trace backend nop simple" +echo " --trace-backend=B Trace backend nop simple ust" echo " --trace-file=NAME Full PATH,NAME of file to store traces" echo " Default:/tmp/trace-<pid>" echo " Default:trace-<pid> on Windows"
@@ -2082,6 +2082,23 @@ if test "$?" -ne 0 ; then exit 1 fi +########################################## +# For 'ust' backend, test if ust headers are present +if test "$trace_backend" = "ust"; then + cat > $TMPC << EOF +#include <ust/tracepoint.h> +#include <ust/marker.h> +int main(void) { return 0; } +EOF + if compile_prog "" "" ; then + LIBS="-lust $LIBS" + else + echo "ERROR: Trace backend 'ust' does not have relevant headers available" + echo " on the host. Pls choose a different backend." + exit 1 + fi +fi +########################################## # End of CC checks # After here, no more $cc or $ld runs
@@ -2484,6 +2501,9 @@ if test "$trace_backend" = "simple"; then trace_file="\"$trace_file-%u\"" fi echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak +if test "$trace_backend" = "ust"; then + LIBS="-lust $LIBS" +fi echo "TOOLS=$tools" >> $config_host_mak echo "ROMS=$roms" >> $config_host_mak
tracetool +83 -2
108 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v2 4/14 trace: Support disabled events in trace-events
In reply to Stefan HajnocziSometimes it is useful to disable a trace event. Removing the event from trace-events is not enough since source code will call the trace_*() function for the event.
This patch makes it easy to build without specific trace events by marking them disabled in trace-events:
disable multiwrite_cb(void *mcb, int ret) "mcb %p ret %d"
This builds without the multiwrite_cb trace event.
trace: Allow bulk enabling/disabling of trace events at compile time
For 'simple' trace backend, allow bulk enabling/disabling of trace events at compile time. Trace events that are preceded by 'disable' keyword are compiled in, but turned off by default. These can individually be turned on using the monitor. All other trace events are enabled by default.
TODO :
This could be enhanced when the trace-event namespace is partitioned into a group and an ID within that group. In such a case, marking a group as enabled would automatically enable all trace-events listed under it.
--- trace-events | 7 ++++++- tracetool | 44 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 45 insertions(+), 6 deletions(-)
trace-events +6 -1
@@ -12,10 +12,15 @@ # # Format of a trace event: # -# <name>(<type1> <arg1>[, <type2> <arg2>] ...) "<format-string>" +# [disable] <name>(<type1> <arg1>[, <type2> <arg2>] ...) "<format-string>" # # Example: qemu_malloc(size_t size) "size %zu" # +# The "disable" keyword will build without the trace event. +# In case of 'simple' trace backend, it will allow the trace event to be +# compiled, but this would be turned off by default. It can be toggled on via +# the monitor. +# # The <name> must be a valid as a C function name. # # Types should be standard C types. Use void * for pointers because the trace
tracetool +39 -5
80 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v2 9/14 trace: Add user documentation
In reply to Stefan Hajnoczi--- docs/tracing.txt | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 177 insertions(+), 0 deletions(-) create mode 100644 docs/tracing.txt
docs/tracing.txt new file +177 -0
@@ -0,0 +1,177 @@ += Tracing = + +== Introduction == + +This document describes the tracing infrastructure in QEMU and how to use it +for debugging, profiling, and observing execution. + +== Quickstart == + +1. Build with the 'simple' trace backend: + + ./configure --trace-backend=simple + make + +2. Enable trace events you are interested in: + + $EDITOR trace-events # remove "disable" from events you want + +3. Run the virtual machine to produce a trace file: + + qemu ... # your normal QEMU invocation + +4. Pretty-print the binary trace file: + + ./simpletrace.py trace-events /tmp/trace-* + +== Trace events == + +There is a set of static trace events declared in the trace-events source +file. Each trace event declaration names the event, its arguments, and the +format string which can be used for pretty-printing: + + qemu_malloc(size_t size, void *ptr) "size %zu ptr %p" + qemu_free(void *ptr) "ptr %p" + +The trace-events file is processed by the tracetool script during build to +generate code for the trace events. Trace events are invoked directly from +source code like this: + + #include "trace.h" /* needed for trace event prototype */ + + void *qemu_malloc(size_t size) + { + void *ptr; + if (!size && !allow_zero_malloc()) { + abort(); + } + ptr = oom_check(malloc(size ? size : 1)); + trace_qemu_malloc(size, ptr); /* <-- trace event */ + return ptr; + } + +=== Declaring trace events === + +The tracetool script produces the trace.h header file which is included by +every source file that uses trace events. Since many source files include +trace.h, it uses a minimum of types and other header files included to keep +the namespace clean and compile times and dependencies down. + +Trace events should use types as follows: + + * Use stdint.h types for fixed-size types. Most offsets and guest memory + addresses are best represented with uint32_t or uint64_t. Use fixed-size + types over primitive types whose size may change depending on the host + (32-bit versus 64-bit) so trace events don't truncate values or break + the build. + + * Use void * for pointers to structs or for arrays. The trace.h header + cannot include all user-defined struct declarations and it is therefore + necessary to use void * for pointers to structs. + + * For everything else, use primitive scalar types (char, int, long) with the + appropriate signedness. + +=== Hints for adding new trace events === + +1. Trace state changes in the code. Interesting points in the code usually + involve a state change like starting, stopping, allocating, freeing. State + changes are good trace events because they can be used to understand the + execution of the system. + +2. Trace guest operations. Guest I/O accesses like reading device registers + are good trace events because they can be used to understand guest + interactions. + +3. Use correlator fields so the context of an individual line of trace output + can be understood. For example, trace the pointer returned by malloc and + used as an argument to free. This way mallocs and frees can be matched up. + Trace events with no context are not very useful. + +4. Name trace events after their function. If there are multiple trace events + in one function, append a unique distinguisher at the end of the name. + +5. Declare trace events with the "disable" keyword. Some trace events can + produce a lot of output and users are typically only interested in a subset + of trace events. Marking trace events disabled by default saves the user + from having to manually disable noisy trace events. + +== Trace backends == + +The tracetool script automates tedious trace event code generation and also +keeps the trace event declarations independent of the trace backend. The trace +events are not tightly coupled to a specific trace backend, such as LTTng or +SystemTap. Support for trace backends can be added by extending the tracetool +script. + +The trace backend is chosen at configure time and only one trace backend can +be built into the binary: + + ./configure --trace-backend=simple + +For a list of supported trace backends, try ./configure --help or see below. + +The following subsections describe the supported trace backends. + +=== Nop === + +The "nop" backend generates empty trace event functions so that the compiler +can optimize out trace events completely. This is the default and imposes no +performance penalty. + +=== Simpletrace === + +The "simple" backend supports common use cases and comes as part of the QEMU +source tree. It may not be as powerful as platform-specific or third-party +trace backends but it is portable. This is the recommended trace backend +unless you have specific needs for more advanced backends. + +==== Monitor commands ==== + +* info trace + Display the contents of trace buffer. This command dumps the trace buffer + with simple formatting. For full pretty-printing, use the simpletrace.py + script on a binary trace file. + + The trace buffer is written into until full. The full trace buffer is + flushed and emptied. This means the 'info trace' will display few or no + entries if the buffer has just been flushed. + +* info trace-events + View available trace events and their state. State 1 means enabled, state 0 + means disabled. + +* trace-event NAME on|off + Enable/disable a given trace event. + +* trace-file on|off|flush|set <path> + Enable/disable/flush the trace file or set the trace file name. + +==== Enabling/disabling trace events programmatically ==== + +The st_change_trace_event_state() function can be used to enable or disable trace +events at runtime inside QEMU: + + #include "trace.h" + + st_change_trace_event_state("virtio_irq", true); /* enable */ + [...] + st_change_trace_event_state("virtio_irq", false); /* disable */ + +==== Analyzing trace files ==== + +The "simple" backend produces binary trace files that can be formatted with the +simpletrace.py script. The script takes the trace-events file and the binary +trace: + + ./simpletrace.py trace-events /tmp/trace.log + +You must ensure that the same trace-events file was used to build QEMU, +otherwise trace event declarations may have changed and output will not be +consistent. + +=== LTTng Userspace Tracer === + +The "ust" backend uses the LTTng Userspace Tracer library. There are no +monitor commands built into QEMU, instead UST utilities should be used to list, +enable/disable, and dump traces.
Signature · 1 line
1.7.1
PATCH v2 11/14 trace: Trace virtio-blk, multiwrite, and paio_submit
In reply to Stefan HajnocziThis patch adds trace events that make it possible to observe virtio-blk.
--- block.c | 8 ++++++++ hw/virtio-blk.c | 7 +++++++ posix-aio-compat.c | 2 ++ trace-events | 14 ++++++++++++++ 4 files changed, 31 insertions(+), 0 deletions(-)
block.c +8 -0
@@ -23,6 +23,7 @@*/ #include "config-host.h" #include "qemu-common.h" +#include "trace.h" #include "monitor.h" #include "block_int.h" #include "module.h"
@@ -2062,6 +2063,8 @@ static void multiwrite_cb(void *opaque, int ret) {MultiwriteCB *mcb = opaque; +trace_multiwrite_cb (mcb, ret); +if (ret <0 && !mcb->error) { mcb->error = ret; }
@@ -2202,6 +2205,8 @@ int bdrv_aio_multiwrite(BlockDriverState *bs, BlockRequest *reqs, int num_reqs)// Check for mergable requests num_reqs =multiwrite_merge (bs, reqs, num_reqs, mcb); +trace_bdrv_aio_multiwrite (mcb, mcb->num_callbacks, num_reqs); +/* * Run the aio requests. As soon as one request can't be submitted * successfully, fail all requests that are not yet submitted (we must
@@ -2223,6 +2228,7 @@ int bdrv_aio_multiwrite(BlockDriverState *bs, BlockRequest *reqs, int num_reqs)*/ mcb->num_requests =1 ; +// Run the aio requests for (i =0 ; i < num_reqs; i++) { mcb->num_requests++; acb = bdrv_aio_writev(bs, reqs[i].sector, reqs[i].qiov,
@@ -2233,8 +2239,10 @@ int bdrv_aio_multiwrite(BlockDriverState *bs, BlockRequest *reqs, int num_reqs)// submitted yet. Otherwise we'll wait for the submitted AIOs to // complete and report the error in the callback. if (i ==0 ) { +trace_bdrv_aio_multiwrite_earlyfail (mcb); goto fail; }else { +trace_bdrv_aio_multiwrite_latefail (mcb, i);multiwrite_cb (mcb, -EIO );break ; }
hw/virtio-blk.c +7 -0
@@ -13,6 +13,7 @@#include <qemu-common.h> #include "qemu-error.h" +#include "trace.h" #include "blockdev.h" #include "virtio-blk.h" #ifdef __linux__
@@ -52,6 +53,8 @@ static void virtio_blk_req_complete(VirtIOBlockReq *req, int status) {VirtIOBlock *s = req->dev; +trace_virtio_blk_req_complete (req, status); + req->in->status = status;virtqueue_push (s->vq, &req->elem, req->qiov.size +sizeof (*req->in));virtio_notify (&s->vdev, s->vq);
@@ -88,6 +91,8 @@ static void virtio_blk_rw_complete(void *opaque, int ret) {VirtIOBlockReq *req = opaque; +trace_virtio_blk_rw_complete (req, ret); +if (ret) {int is_read = !(req->out->type &VIRTIO_BLK_T_OUT );if (virtio_blk_handle_rw_error (req, -ret, is_read))
@@ -270,6 +275,8 @@ static void virtio_blk_handle_write(VirtIOBlockReq *req, MultiReqBuffer *mrb) {BlockRequest *blkreq; +trace_virtio_blk_handle_write (req, req->out->sector, req->qiov.size /512 ); +if (req->out->sector & req->dev->sector_mask) {virtio_blk_rw_complete (req, -EIO );return ;
posix-aio-compat.c +2 -0
@@ -25,6 +25,7 @@#include "qemu-queue.h" #include "osdep.h" #include "qemu-common.h" +#include "trace.h" #include "block_int.h" #include "block/raw-posix-aio.h"
@@ -583,6 +584,7 @@ BlockDriverAIOCB *paio_submit(BlockDriverState *bs, int fd, acb->next = posix_aio_state->first_aio; posix_aio_state->first_aio = acb; +trace_paio_submit (acb, opaque, sector_num, nb_sectors, type);qemu_paio_submit (acb);return &acb->common; }
trace-events +14 -0
@@ -37,3 +37,17 @@ disable qemu_free(void *ptr) "ptr %p" disable qemu_memalign(size_t alignment, size_t size, void *ptr) "alignment %zu size %zu ptr %p" disable qemu_valloc(size_t size, void *ptr) "size %zu ptr %p" disable qemu_vfree(void *ptr) "ptr %p" + +# block.c +disable multiwrite_cb(void *mcb, int ret) "mcb %p ret %d" +disable bdrv_aio_multiwrite(void *mcb, int num_callbacks, int num_reqs) "mcb %p num_callbacks %d num_reqs %d" +disable bdrv_aio_multiwrite_earlyfail(void *mcb) "mcb %p" +disable bdrv_aio_multiwrite_latefail(void *mcb, int i) "mcb %p i %d" + +# hw/virtio-blk.c +disable virtio_blk_req_complete(void *req, int status) "req %p status %d" +disable virtio_blk_rw_complete(void *req, int ret) "req %p ret %d" +disable virtio_blk_handle_write(void *req, unsigned long sector, unsigned long nsectors) "req %p sector %lu nsectors %lu" + +# posix-aio-compat.c +disable paio_submit(void *acb, void *opaque, unsigned long sector_num, unsigned long nb_sectors, unsigned long type) "acb %p opaque %p sector_num %lu nb_sectors %lu type %lu"
Signature · 1 line
1.7.1
PATCH v2 6/14 trace: Add trace-file command to open/close/flush trace file
In reply to Stefan HajnocziThis patch adds the trace-file command:
trace-file [on|off|flush]
Open, close, or flush the trace file. If no argument is given, the status of the trace file is displayed.
The trace file is turned on by default but is only written out when the trace buffer becomes full. The flush operation can be used to force write out at any time.
Turning off the trace file does not change the state of trace events; tracing will continue to the trace buffer. When the trace file is off, use "info trace" to display the contents of the trace buffer in memory.
This commit also contains the trace-file sub-command from the following commit:
commit 5ce8d1a957afae2c52ad748944ce72848ccf57bd
Author: Prerna Saxena <[email protected]> Date: Wed Aug 4 16:23:54 2010 +0530
trace: Add options to specify trace file name at startup and runtime
This patch adds an optional command line switch '-trace' to specify the filename to write traces to, when qemu starts.
Eg, If compiled with the 'simple' trace backend, [temp@system]$ qemu -trace FILENAME IMAGE
Allows the binary traces to be written to FILENAME instead of the option set at config-time.
Also, this adds monitor sub-command 'set' to trace-file commands to dynamically change trace log file at runtime.
Eg,
(qemu)trace-file set FILENAME
This allows one to set trace outputs to FILENAME from the default specified at startup.
--- monitor.c | 23 ++++++++++++++++++++ qemu-monitor.hx | 14 ++++++++++++ simpletrace.c | 62 ++++++++++++++++++++++++++++++++++++++++++------------ simpletrace.h | 4 +++ 4 files changed, 89 insertions(+), 14 deletions(-)
monitor.c +23 -0
@@ -549,6 +549,29 @@ static void do_change_trace_event_state(Monitor *mon, const QDict *qdict)bool new_state =qdict_get_bool (qdict,"option" );st_change_trace_event_state (tp_name, new_state); } + +static void do_trace_file (Monitor *mon,const QDict *qdict) +{ +const char *op =qdict_get_try_str (qdict,"op" ); +const char *arg =qdict_get_try_str (qdict,"arg" ); + +if (!op) { +st_print_trace_file_status ((FILE *)mon, &monitor_fprintf); + }else if (!strcmp (op,"on" )) { +st_set_trace_file_enabled (true); + }else if (!strcmp (op,"off" )) { +st_set_trace_file_enabled (false); + }else if (!strcmp (op,"flush" )) { +st_flush_trace_buffer (); + }else if (!strcmp (op,"set" )) { +if (arg) { +st_set_trace_file (arg); + } + }else { +monitor_printf (mon,"unexpected argument \"%s\"\n" , op); +help_cmd (mon,"trace-file" ); + } +}#endif static void user_monitor_complete (void *opaque,QObject *ret_data)
qemu-monitor.hx +14 -0
@@ -295,6 +295,20 @@ STEXI @findex trace-event changes status of a trace event ETEXI + + { + .name = "trace-file", + .args_type = "op:s?,arg:F?", + .params = "on|off|flush|set [arg]", + .help = "open, close, or flush trace file, or set a new file name", + .mhandler.cmd = do_trace_file, + }, + +STEXI +@item trace-file on|off|flush +@findex trace-file +Open, close, or flush the trace file. If no argument is given, the status of the trace file is displayed. +ETEXI #endif {
simpletrace.c +47 -13
91 lines not on this page · raw message
simpletrace.h +4 -0
@@ -32,5 +32,9 @@ void trace6(TraceEventID event, uint64_t x1, uint64_t x2, uint64_t x3, uint64_tvoid st_print_trace (FILE *stream,int (*stream_printf)(FILE *stream,const char *fmt, ...));void st_print_trace_events (FILE *stream,int (*stream_printf)(FILE *stream,const char *fmt, ...));void st_change_trace_event_state (const char *tname,bool tstate); +void st_print_trace_file_status (FILE *stream,int (*stream_printf)(FILE *stream,const char *fmt, ...)); +void st_set_trace_file_enabled (bool enable); +bool st_set_trace_file (const char *file); +void st_flush_trace_buffer (void );#endif /* SIMPLETRACE_H */
Signature · 1 line
1.7.1
PATCH v2 12/14 trace: Trace virtqueue operations
In reply to Stefan HajnocziThis patch adds trace events for virtqueue operations including adding/removing buffers, notifying the guest, and receiving a notify from the guest.
--- hw/virtio.c | 8 ++++++++ trace-events | 8 ++++++++ 2 files changed, 16 insertions(+), 0 deletions(-)
hw/virtio.c +8 -0
@@ -13,6 +13,7 @@#include <inttypes.h> +#include "trace.h" #include "virtio.h" #include "sysemu.h"
@@ -205,6 +206,8 @@ void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,unsigned int offset;int i; +trace_virtqueue_fill (vq, elem, len, idx); + offset =0 ;for (i =0 ; i < elem->in_num; i++) {size_t size =MIN (len - offset, elem->in_sg[i].iov_len);
@@ -232,6 +235,7 @@ void virtqueue_flush(VirtQueue *vq, unsigned int count) {/* Make sure buffer is written before we update index. */ wmb (); +trace_virtqueue_flush (vq, count);vring_used_idx_increment (vq, count); vq->inuse -= count; }
@@ -422,6 +426,7 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem) vq->inuse++; +trace_virtqueue_pop (vq, elem, elem->in_num, elem->out_num);return elem->in_num + elem->out_num; }
@@ -560,6 +565,7 @@ int virtio_queue_get_num(VirtIODevice *vdev, int n)void virtio_queue_notify (VirtIODevice *vdev,int n) {if (n <VIRTIO_PCI_QUEUE_MAX && vdev->vq[n].vring.desc) { +trace_virtio_queue_notify (vdev, n, &vdev->vq[n]); vdev->vq[n].handle_output (vdev, &vdev->vq[n]); } }
@@ -597,6 +603,7 @@ VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,void virtio_irq (VirtQueue *vq) { +trace_virtio_irq (vq); vq->vdev->isr |=0x01 ;virtio_notify_vector (vq->vdev, vq->vector); }
@@ -609,6 +616,7 @@ void virtio_notify(VirtIODevice *vdev, VirtQueue *vq) (vq->inuse || vring_avail_idx(vq) != vq->last_avail_idx))) return; +trace_virtio_notify (vdev, vq); vdev->isr |=0x01 ;virtio_notify_vector (vdev, vq->vector); }
trace-events +8 -0
@@ -38,6 +38,14 @@ disable qemu_memalign(size_t alignment, size_t size, void *ptr) "alignment %zu s disable qemu_valloc(size_t size, void *ptr) "size %zu ptr %p" disable qemu_vfree(void *ptr) "ptr %p" +# hw/virtio.c +disable virtqueue_fill(void *vq, const void *elem, unsigned int len, unsigned int idx) "vq %p elem %p len %u idx %u" +disable virtqueue_flush(void *vq, unsigned int count) "vq %p count %u" +disable virtqueue_pop(void *vq, void *elem, unsigned int in_num, unsigned int out_num) "vq %p elem %p in_num %u out_num %u" +disable virtio_queue_notify(void *vdev, int n, void *vq) "vdev %p n %d vq %p" +disable virtio_irq(void *vq) "vq %p" +disable virtio_notify(void *vdev, void *vq) "vdev %p vq %p" + # block.c disable multiwrite_cb(void *mcb, int ret) "mcb %p ret %d" disable bdrv_aio_multiwrite(void *mcb, int num_callbacks, int num_reqs) "mcb %p num_callbacks %d num_reqs %d"
Signature · 1 line
1.7.1
PATCH v2 13/14 trace: Trace port IO
In reply to Stefan HajnocziFrom: Prerna Saxena <[email protected]>
--- ioport.c | 7 +++++++ trace-events | 4 ++++ 2 files changed, 11 insertions(+), 0 deletions(-)
ioport.c +7 -0
@@ -26,6 +26,7 @@*/ #include "ioport.h" +#include "trace.h" /***********************************************************/ /* IO Port */
@@ -195,18 +196,21 @@ void isa_unassign_ioport(pio_addr_t start, int length)void cpu_outb (pio_addr_t addr,uint8_t val) {LOG_IOPORT ("outb: %04" FMT_pioaddr" %02" PRIx8"\n" , addr, val); +trace_cpu_out (addr, val);ioport_write (0 , addr, val); }void cpu_outw (pio_addr_t addr,uint16_t val) {LOG_IOPORT ("outw: %04" FMT_pioaddr" %04" PRIx16"\n" , addr, val); +trace_cpu_out (addr, val);ioport_write (1 , addr, val); }void cpu_outl (pio_addr_t addr,uint32_t val) {LOG_IOPORT ("outl: %04" FMT_pioaddr" %08" PRIx32"\n" , addr, val); +trace_cpu_out (addr, val);ioport_write (2 , addr, val); }
@@ -214,6 +218,7 @@ uint8_t cpu_inb(pio_addr_t addr) {uint8_t val; val =ioport_read (0 , addr); +trace_cpu_in (addr, val);LOG_IOPORT ("inb : %04" FMT_pioaddr" %02" PRIx8"\n" , addr, val);return val; }
@@ -222,6 +227,7 @@ uint16_t cpu_inw(pio_addr_t addr) {uint16_t val; val =ioport_read (1 , addr); +trace_cpu_in (addr, val);LOG_IOPORT ("inw : %04" FMT_pioaddr" %04" PRIx16"\n" , addr, val);return val; }
@@ -230,6 +236,7 @@ uint32_t cpu_inl(pio_addr_t addr) {uint32_t val; val =ioport_read (2 , addr); +trace_cpu_in (addr, val);LOG_IOPORT ("inl : %04" FMT_pioaddr" %08" PRIx32"\n" , addr, val);return val; }
trace-events +4 -0
@@ -59,3 +59,7 @@ disable virtio_blk_handle_write(void *req, unsigned long sector, unsigned long n # posix-aio-compat.c disable paio_submit(void *acb, void *opaque, unsigned long sector_num, unsigned long nb_sectors, unsigned long type) "acb %p opaque %p sector_num %lu nb_sectors %lu type %lu" + +# ioport.c +disable cpu_in(unsigned int addr, unsigned int val) "addr %#x value %u" +disable cpu_out(unsigned int addr, unsigned int val) "addr %#x value %u"
Signature · 1 line
1.7.1
PATCH v2 14/14 trace: Trace entry point of balloon request handler
In reply to Stefan HajnocziFrom: Prerna Saxena <[email protected]>
--- balloon.c | 2 ++ trace-events | 4 ++++ 2 files changed, 6 insertions(+), 0 deletions(-)
balloon.c +2 -0
@@ -29,6 +29,7 @@#include "cpu-common.h" #include "kvm.h" #include "balloon.h" +#include "trace.h" static QEMUBalloonEvent *qemu_balloon_event;
@@ -43,6 +44,7 @@ void qemu_add_balloon_handler(QEMUBalloonEvent *func, void *opaque)int qemu_balloon (ram_addr_t target,MonitorCompletion cb,void *opaque) {if (qemu_balloon_event) { +trace_balloon_event (qemu_balloon_event_opaque, target);qemu_balloon_event (qemu_balloon_event_opaque, target, cb, opaque);return 1 ; }else {
trace-events +4 -0
@@ -63,3 +63,7 @@ disable paio_submit(void *acb, void *opaque, unsigned long sector_num, unsigned # ioport.c disable cpu_in(unsigned int addr, unsigned int val) "addr %#x value %u" disable cpu_out(unsigned int addr, unsigned int val) "addr %#x value %u" + +# balloon.c +# Since requests are raised via monitor, not many tracepoints are needed. +disable balloon_event(void *opaque, unsigned long addr) "opaque %p addr %lu"
Signature · 1 line
1.7.1
PATCH v2 10/14 trace: Trace qemu_malloc() and qemu_vmalloc()
In reply to Stefan HajnocziIt is often useful to instrument memory management functions in order to find leaks or performance problems. This patch adds trace events for the memory allocation primitives.
--- osdep.c | 24 ++++++++++++++++++------ qemu-malloc.c | 12 ++++++++++-- trace-events | 10 ++++++++++ 3 files changed, 38 insertions(+), 8 deletions(-)
osdep.c +18 -6
@@ -50,6 +50,7 @@#endif #include "qemu-common.h" +#include "trace.h" #include "sysemu.h" #include "qemu_socket.h"
@@ -71,25 +72,34 @@ static void *oom_check(void *ptr)#if defined(_WIN32)void *qemu_memalign (size_t alignment,size_t size) { +void *ptr; +if (!size) {abort (); } -return oom_check (VirtualAlloc (NULL , size,MEM_COMMIT ,PAGE_READWRITE )); + ptr =oom_check (VirtualAlloc (NULL , size,MEM_COMMIT ,PAGE_READWRITE )); +trace_qemu_memalign (alignment, size, ptr); +return ptr; }void *qemu_vmalloc (size_t size) { +void *ptr; +/* FIXME: this is not exactly optimal solution since VirtualAlloc has 64Kb granularity, but at least it guarantees us that the memory is page aligned. */ if (!size) {abort (); } -return oom_check (VirtualAlloc (NULL , size,MEM_COMMIT ,PAGE_READWRITE )); + ptr =oom_check (VirtualAlloc (NULL , size,MEM_COMMIT ,PAGE_READWRITE )); +trace_qemu_vmalloc (size, ptr); +return ptr; }void qemu_vfree (void *ptr) { +trace_qemu_vfree (ptr);VirtualFree (ptr,0 ,MEM_RELEASE ); }
@@ -97,21 +107,22 @@ void qemu_vfree(void *ptr)void *qemu_memalign (size_t alignment,size_t size) { +void *ptr;#if defined(_POSIX_C_SOURCE) && !defined(__sun__)int ret; -void *ptr; ret =posix_memalign (&ptr, alignment, size);if (ret !=0 ) {fprintf (stderr,"Failed to allocate %zu B: %s\n" , size,strerror (ret));abort (); } -return ptr;#elif defined(CONFIG_BSD ) -return oom_check (valloc (size)); + ptr =oom_check (valloc (size));#else -return oom_check (memalign (alignment, size)); + ptr =oom_check (memalign (alignment, size));#endif +trace_qemu_memalign (alignment, size, ptr); +return ptr; }/* alloc shared memory pages */
@@ -122,6 +133,7 @@ void *qemu_vmalloc(size_t size)void qemu_vfree (void *ptr) { +trace_qemu_vfree (ptr);free (ptr); }
qemu-malloc.c +10 -2
@@ -22,6 +22,7 @@* THE SOFTWARE. */ #include "qemu-common.h" +#include "trace.h" #include <stdlib.h> static void *oom_check (void *ptr)
@@ -34,6 +35,7 @@ static void *oom_check(void *ptr)void qemu_free (void *ptr) { +trace_qemu_free (ptr);free (ptr); }
@@ -48,18 +50,24 @@ static int allow_zero_malloc(void)void *qemu_malloc (size_t size) { +void *ptr;if (!size && !allow_zero_malloc ()) {abort (); } -return oom_check (malloc (size ? size :1 )); + ptr =oom_check (malloc (size ? size :1 )); +trace_qemu_malloc (size, ptr); +return ptr; }void *qemu_realloc (void *ptr,size_t size) { +void *newptr;if (!size && !allow_zero_malloc ()) {abort (); } -return oom_check (realloc (ptr, size ? size :1 )); + newptr =oom_check (realloc (ptr, size ? size :1 )); +trace_qemu_realloc (ptr, size, newptr); +return newptr; }void *qemu_mallocz (size_t size)
trace-events +10 -0
@@ -27,3 +27,13 @@ # system may not have the necessary headers included. # # The <format-string> should be a sprintf()-compatible format string. + +# qemu-malloc.c +disable qemu_malloc(size_t size, void *ptr) "size %zu ptr %p" +disable qemu_realloc(void *ptr, size_t size, void *newptr) "ptr %p size %zu newptr %p" +disable qemu_free(void *ptr) "ptr %p" + +# osdep.c +disable qemu_memalign(size_t alignment, size_t size, void *ptr) "alignment %zu size %zu ptr %p" +disable qemu_valloc(size_t size, void *ptr) "size %zu ptr %p" +disable qemu_vfree(void *ptr) "ptr %p"
Signature · 1 line
1.7.1
[Qemu-devel] Re: [PATCH 01/14] trace: Add trace-events file for declaring trace events
In reply to Stefan HajnocziQuoted 10 lines · Stefan Hajnoczi
This patch introduces the trace-events file where trace events can be declared like so:
qemu_malloc(size_t size)"size %zu"qemu_free(void *ptr)"ptr %p"These trace event declarations are processed by a new tool called tracetool to generate code for the trace events. Trace event declarations are independent of the backend tracing system (LTTng User Space Tracing, ftrace markers, DTrace).
I think the tool does not work if 'sh' is not 'bash'. For example, on OpenBSD I got:
config-host.mak is out-of-date, running configure
Error: invalid trace backend
Please choose a supported trace backend.
GEN trace.h
/src/qemu/tracetool[176]: no closing quote
This shows the problem:
sh -x ../tracetool --nop --check-backend
+ set -f
../tracetool[176]: no closing quote
[Qemu-devel] Re: [PATCH 01/14] trace: Add trace-events file for declaring trace events
Quoted 8 lines · Blue Swirl
Quoted 6 lines · Stefan Hajnoczi
This patch introduces the trace-events file where trace events can be declared like so:
qemu_malloc(size_t size)"size %zu"qemu_free(void *ptr)"ptr %p"
Quoted 7 lines
Quoted 4 lines
These trace event declarations are processed by a new tool called tracetool to generate code for the trace events. Trace event declarations are independent of the backend tracing system (LTTng User Space Tracing, ftrace markers, DTrace).
I think the tool does not work if 'sh' is not 'bash'. For example, on OpenBSD I got:
Well, it does work with ash.
Quoted 6 lines
config-host.mak is out-of-date, running configure
Error: invalid trace backend
Please choose a supported trace backend.
Quoted 7 lines
GEN
trace.h
/src/qemu/tracetool[176]: no closing quoteThis shows the problem:
sh -x ../tracetool --nop --check-backend
+ set -f
../tracetool[176]: no closing quote
`set -f' is a valid construct according to:
http://www.opengroup.org/onlinepubs/009695399/utilities/set.html
The problem is likely elsewhere.
Signature · 1 line
mailto:[email protected]
[Qemu-devel] Re: [PATCH 01/14] trace: Add trace-events file for declaring trace events
Quoted 34 lines · malc
Quoted 8 lines · Blue Swirl
Quoted 6 lines · Stefan Hajnoczi
This patch introduces the trace-events file where trace events can be declared like so:
qemu_malloc(size_t size)"size %zu"qemu_free(void *ptr)"ptr %p"Quoted 7 lines
Quoted 4 lines
These trace event declarations are processed by a new tool called tracetool to generate code for the trace events. Trace event declarations are independent of the backend tracing system (LTTng User Space Tracing, ftrace markers, DTrace).
I think the tool does not work if 'sh' is not 'bash'. For example, on OpenBSD I got:
Well, it does work with ash.
Quoted 6 lines
config-host.mak is out-of-date, running configure
Error: invalid trace backend
Please choose a supported trace backend.Quoted 7 lines
GEN
trace.h
/src/qemu/tracetool[176]: no closing quoteThis shows the problem:
sh -x ../tracetool --nop --check-backend
+ set -f
../tracetool[176]: no closing quote
Quoted 4 lines
`set -f' is a valid construct according to:
http://www.opengroup.org/onlinepubs/009695399/utilities/set.htmlThe problem is likely elsewhere.
Right, the offending lines are:
echo ${1%%(*}
and
args=${1#*(}If I remove both of those, the errors are gone.
[Qemu-devel] Re: [PATCH 01/14] trace: Add trace-events file for declaring trace events
Quoted 38 lines · Blue Swirl
Quoted 37 lines · malc
Quoted 8 lines · Blue Swirl
Quoted 6 lines · Stefan Hajnoczi
This patch introduces the trace-events file where trace events can be declared like so:
qemu_malloc(size_t size)"size %zu"qemu_free(void *ptr)"ptr %p"Quoted 7 lines
Quoted 4 lines
These trace event declarations are processed by a new tool called tracetool to generate code for the trace events. Trace event declarations are independent of the backend tracing system (LTTng User Space Tracing, ftrace markers, DTrace).
I think the tool does not work if 'sh' is not 'bash'. For example, on OpenBSD I got:
Well, it does work with ash.
Quoted 6 lines
config-host.mak is out-of-date, running configure
Error: invalid trace backend
Please choose a supported trace backend.Quoted 7 lines
GEN
trace.h
/src/qemu/tracetool[176]: no closing quoteThis shows the problem:
sh -x ../tracetool --nop --check-backend
+ set -f
../tracetool[176]: no closing quote`set -f' is a valid construct according to:
http://www.opengroup.org/onlinepubs/009695399/utilities/set.html
Quoted 9 lines
Quoted 1 line
The problem is likely elsewhere.
Right, the offending lines are:
echo ${1%%(*}
and
args=${1#*(}If I remove both of those, the errors are gone.
This patch fixes the problem. Double quotes do not help.
tracetool +2 -2
@@ -29,14 +29,14 @@ EOF # Get the name of a trace event get_name() { - echo ${1%%(*} + echo ${1%%\(*} } # Get the argument list of a trace event, including types and names get_args() { local args - args=${1#*(} + args=${1#*\(} args=${args%)*} echo "$args" }
Re: [Qemu-devel] Re: [PATCH 01/14] trace: Add trace-events file for declaring trace events
Quoted 66 lines · Blue Swirl
Quoted 38 lines · Blue Swirl
Quoted 37 lines · malc
Quoted 8 lines · Blue Swirl
Quoted 6 lines · Stefan Hajnoczi
This patch introduces the trace-events file where trace events can be declared like so:
qemu_malloc(size_t size)"size %zu"qemu_free(void *ptr)"ptr %p"Quoted 7 lines
Quoted 4 lines
These trace event declarations are processed by a new tool called tracetool to generate code for the trace events. Trace event declarations are independent of the backend tracing system (LTTng User Space Tracing, ftrace markers, DTrace).
I think the tool does not work if 'sh' is not 'bash'. For example, on OpenBSD I got:
Well, it does work with ash.
Quoted 6 lines
config-host.mak is out-of-date, running configure
Error: invalid trace backend
Please choose a supported trace backend.Quoted 7 lines
GEN
trace.h
/src/qemu/tracetool[176]: no closing quoteThis shows the problem:
sh -x ../tracetool --nop --check-backend
+ set -f
../tracetool[176]: no closing quote`set -f' is a valid construct according to:
http://www.opengroup.org/onlinepubs/009695399/utilities/set.htmlQuoted 9 lines
Quoted 1 line
The problem is likely elsewhere.
Right, the offending lines are:
echo ${1%%(*}
and
args=${1#*(}If I remove both of those, the errors are gone.
This patch fixes the problem. Double quotes do not help.
tracetool +1
-1@@ -29,14 +29,14 @@ EOF # Get the name of a trace event get_name() { - echo ${1%%(*} + echo ${1%%\(*} } # Get the argument list of a trace event, including types and names get_args() {
Quoted 6 lines
local args
- args=${1#*(}
+ args=${1#*\(}
args=${args%)*}
echo "$args"
}
Thanks for finding and fixing this! I have been testing with dash in addition to bash.
I'd like to write tracetool in Python (or Perl, if needed) to eliminate issues like this. I chose shell though to avoid the dependency on Python. QEMU currently uses Perl for texi2pod.pl and Python for QMP scripts but both are optional. Tracetool isn't optional because it runs even when tracing is disabled ("nop" backend generates empty stub functions). How do you feel about tracetool in Python?
Stefan
Re: [Qemu-devel] Re: [PATCH 01/14] trace: Add trace-events file for declaring trace events
Quoted 77 lines · Stefan Hajnoczi
Quoted 66 lines · Blue Swirl
Quoted 38 lines · Blue Swirl
Quoted 37 lines · malc
Quoted 8 lines · Blue Swirl
Quoted 6 lines · Stefan Hajnoczi
This patch introduces the trace-events file where trace events can be declared like so:
qemu_malloc(size_t size)"size %zu"qemu_free(void *ptr)"ptr %p"Quoted 7 lines
Quoted 4 lines
These trace event declarations are processed by a new tool called tracetool to generate code for the trace events. Trace event declarations are independent of the backend tracing system (LTTng User Space Tracing, ftrace markers, DTrace).
I think the tool does not work if 'sh' is not 'bash'. For example, on OpenBSD I got:
Well, it does work with ash.
Quoted 6 lines
config-host.mak is out-of-date, running configure
Error: invalid trace backend
Please choose a supported trace backend.Quoted 7 lines
GEN
trace.h
/src/qemu/tracetool[176]: no closing quoteThis shows the problem:
sh -x ../tracetool --nop --check-backend
+ set -f
../tracetool[176]: no closing quote`set -f' is a valid construct according to:
http://www.opengroup.org/onlinepubs/009695399/utilities/set.htmlQuoted 9 lines
Quoted 1 line
The problem is likely elsewhere.
Right, the offending lines are:
echo ${1%%(*}
and
args=${1#*(}If I remove both of those, the errors are gone.
This patch fixes the problem. Double quotes do not help.
tracetool +1
-1@@ -29,14 +29,14 @@ EOF # Get the name of a trace event get_name() { - echo ${1%%(*} + echo ${1%%\(*} } # Get the argument list of a trace event, including types and names get_args() {Quoted 6 lines
local args
- args=${1#*(}
+ args=${1#*\(}
args=${args%)*}
echo "$args"
}Thanks for finding and fixing this! I have been testing with dash in addition to bash.
Quoted 7 lines
I'd like to write tracetool in Python (or Perl, if needed) to eliminate issues like this. I chose shell though to avoid the dependency on Python. QEMU currently uses Perl for texi2pod.pl and Python for QMP scripts but both are optional. Tracetool isn't optional because it runs even when tracing is disabled ("nop" backend generates empty stub functions). How do you feel about tracetool in Python?
I'd like to avoid additional dependencies. One way to solve this could be to ship QEMU with default-trace.[ch] which are used for the nop case, then tracetool implementation would not matter much. But these files would need to be updated, in synch, whenever new trace points are added which is fragile.
Maybe a bit of CPP magic added to trace-events could simplify (or even eliminate) the script, something like we do with .hx files.
Re: [Qemu-devel] Re: [PATCH 01/14] trace: Add trace-events file for declaring trace events
Quoted 86 lines · Blue Swirl
Quoted 77 lines · Stefan Hajnoczi
Quoted 66 lines · Blue Swirl
Quoted 38 lines · Blue Swirl
Quoted 37 lines · malc
Quoted 8 lines · Blue Swirl
Quoted 6 lines · Stefan Hajnoczi
This patch introduces the trace-events file where trace events can be declared like so:
qemu_malloc(size_t size)"size %zu"qemu_free(void *ptr)"ptr %p"Quoted 7 lines
Quoted 4 lines
These trace event declarations are processed by a new tool called tracetool to generate code for the trace events. Trace event declarations are independent of the backend tracing system (LTTng User Space Tracing, ftrace markers, DTrace).
I think the tool does not work if 'sh' is not 'bash'. For example, on OpenBSD I got:
Well, it does work with ash.
Quoted 6 lines
config-host.mak is out-of-date, running configure
Error: invalid trace backend
Please choose a supported trace backend.Quoted 7 lines
GEN
trace.h
/src/qemu/tracetool[176]: no closing quoteThis shows the problem:
sh -x ../tracetool --nop --check-backend
+ set -f
../tracetool[176]: no closing quote`set -f' is a valid construct according to:
http://www.opengroup.org/onlinepubs/009695399/utilities/set.htmlQuoted 9 lines
Quoted 1 line
The problem is likely elsewhere.
Right, the offending lines are:
echo ${1%%(*}
and
args=${1#*(}If I remove both of those, the errors are gone.
This patch fixes the problem. Double quotes do not help.
tracetool +1
-1@@ -29,14 +29,14 @@ EOF # Get the name of a trace event get_name() { - echo ${1%%(*} + echo ${1%%\(*} } # Get the argument list of a trace event, including types and names get_args() {Quoted 6 lines
local args
- args=${1#*(}
+ args=${1#*\(}
args=${args%)*}
echo "$args"
}Thanks for finding and fixing this! I have been testing with dash in addition to bash.
Quoted 7 lines
I'd like to write tracetool in Python (or Perl, if needed) to eliminate issues like this. I chose shell though to avoid the dependency on Python. QEMU currently uses Perl for texi2pod.pl and Python for QMP scripts but both are optional. Tracetool isn't optional because it runs even when tracing is disabled ("nop" backend generates empty stub functions). How do you feel about tracetool in Python?
Quoted 8 lines
I'd like to avoid additional dependencies. One way to solve this could be to ship QEMU with default-trace.[ch] which are used for the nop case, then tracetool implementation would not matter much. But these files would need to be updated, in synch, whenever new trace points are added which is fragile.
Maybe a bit of CPP magic added to trace-events could simplify (or even eliminate) the script, something like we do with .hx files.
Okay, let's stick to tracetool in POSIX shell. I'll resend this patch with your fix included.
Stefan
PATCH v3 1/1 trace: Add trace-events file for declaring trace events
This patch introduces the trace-events file where trace events can be declared like so:
qemu_malloc(size_t size) "size %zu"qemu_free(void *ptr) "ptr %p"
These trace event declarations are processed by a new tool called tracetool to generate code for the trace events. Trace event declarations are independent of the backend tracing system (LTTng User Space Tracing, ftrace markers, DTrace).
The default "nop" backend generates empty trace event functions. Therefore trace events are disabled by default.
The trace-events file serves two purposes:
1. Adding trace events is easy. It is not necessary to understand the details of a backend tracing system. The trace-events file is a single location where trace events can be declared without code duplication.
2. QEMU is not tightly coupled to one particular backend tracing system. In order to support tracing across QEMU host platforms and to anticipate new backend tracing systems that are currently maturing, it is important to be flexible and not tied to one system.
This commit includes fixes from Prerna Saxena <[email protected]> and Blue Swirl <[email protected]>.
---
This patch includes the tracetool parenthesis fix from Blue Swirl to build on OpenBSD.
.gitignore | 2 + Makefile | 17 ++++- Makefile.objs | 5 ++ Makefile.target | 1 + configure | 18 ++++++ trace-events | 24 ++++++++ tracetool | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 238 insertions(+), 4 deletions(-) create mode 100644 trace-events create mode 100755 tracetool
.gitignore +2 -0
@@ -2,6 +2,8 @@ config-devices.* config-all-devices.* config-host.* config-target.* +trace.h +trace.c *-softmmu *-darwin-user *-linux-user
Makefile +13 -4
@@ -1,6 +1,6 @@ # Makefile for QEMU. -GENERATED_HEADERS = config-host.h +GENERATED_HEADERS = config-host.h trace.h ifneq ($(wildcard config-host.mak),) # Put the all: rule here so that config-host.mak can contain dependencies.
@@ -104,16 +104,24 @@ ui/vnc.o: QEMU_CFLAGS += $(VNC_TLS_CFLAGS) bt-host.o: QEMU_CFLAGS += $(BLUEZ_CFLAGS) +trace.h: $(SRC_PATH)/trace-events config-host.mak + $(call quiet-command,sh $(SRC_PATH)/tracetool --$(TRACE_BACKEND) -h < $< > $@," GEN $@") + +trace.c: $(SRC_PATH)/trace-events config-host.mak + $(call quiet-command,sh $(SRC_PATH)/tracetool --$(TRACE_BACKEND) -c < $< > $@," GEN $@") + +trace.o: trace.c $(GENERATED_HEADERS) + ###################################################################### qemu-img.o: qemu-img-cmds.h qemu-img.o qemu-tool.o qemu-nbd.o qemu-io.o: $(GENERATED_HEADERS) -qemu-img$(EXESUF): qemu-img.o qemu-tool.o qemu-error.o $(block-obj-y) $(qobject-obj-y) +qemu-img$(EXESUF): qemu-img.o qemu-tool.o qemu-error.o $(trace-obj-y) $(block-obj-y) $(qobject-obj-y) -qemu-nbd$(EXESUF): qemu-nbd.o qemu-tool.o qemu-error.o $(block-obj-y) $(qobject-obj-y) +qemu-nbd$(EXESUF): qemu-nbd.o qemu-tool.o qemu-error.o $(trace-obj-y) $(block-obj-y) $(qobject-obj-y) -qemu-io$(EXESUF): qemu-io.o cmd.o qemu-tool.o qemu-error.o $(block-obj-y) $(qobject-obj-y) +qemu-io$(EXESUF): qemu-io.o cmd.o qemu-tool.o qemu-error.o $(trace-obj-y) $(block-obj-y) $(qobject-obj-y) qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx $(call quiet-command,sh $(SRC_PATH)/hxtool -h < $< > $@," GEN $@")
@@ -133,6 +141,7 @@ clean: rm -f *.o *.d *.a $(TOOLS) TAGS cscope.* *.pod *~ */*~ rm -f slirp/*.o slirp/*.d audio/*.o audio/*.d block/*.o block/*.d net/*.o net/*.d fsdev/*.o fsdev/*.d ui/*.o ui/*.d rm -f qemu-img-cmds.h + rm -f trace.c trace.h $(MAKE) -C tests clean for d in $(ALL_SUBDIRS) libhw32 libhw64 libuser libdis libdis-user; do \ if test -d $$d; then $(MAKE) -C $$d $@ || exit 1; fi; \
Makefile.objs +5 -0
@@ -265,6 +265,11 @@ libdis-$(CONFIG_S390_DIS) += s390-dis.o libdis-$(CONFIG_SH4_DIS) += sh4-dis.o libdis-$(CONFIG_SPARC_DIS) += sparc-dis.o +###################################################################### +# trace + +trace-obj-y = trace.o + vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS) vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
Makefile.target +1 -0
@@ -310,6 +310,7 @@ obj-y += $(addprefix $(HWDIR)/, $(hw-obj-y)) endif # CONFIG_SOFTMMU +obj-y += $(addprefix ../, $(trace-obj-y)) obj-$(CONFIG_GDBSTUB_XML) += gdbstub-xml.o $(QEMU_PROG): $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y)
configure +18 -0
@@ -317,6 +317,7 @@ pkgversion="" check_utests="no" user_pie="no" zero_malloc="" +trace_backend="nop" # OS specific if check_define __linux__ ; then
@@ -519,6 +520,8 @@ for opt do ;; --target-list=*) target_list="$optarg" ;; + --trace-backend=*) trace_backend="$optarg" + ;; --enable-gprof) gprof="yes" ;; --static)
@@ -897,6 +900,7 @@ echo " --enable-docs enable documentation build" echo " --disable-docs disable documentation build" echo " --disable-vhost-net disable vhost-net acceleration support" echo " --enable-vhost-net enable vhost-net acceleration support" +echo " --trace-backend=B Trace backend nop" echo "" echo "NOTE: The object files are built at the place where configure is launched" exit 1
@@ -2059,6 +2063,18 @@ if compile_prog "" "" ; then fdatasync=yes fi +########################################## +# check if trace backend exists + +sh "$source_path/tracetool" "--$trace_backend" --check-backend > /dev/null 2> /dev/null +if test "$?" -ne 0 ; then + echo + echo "Error: invalid trace backend" + echo "Please choose a supported trace backend." + echo + exit 1 +fi + # End of CC checks # After here, no more $cc or $ld runs
@@ -2189,6 +2205,7 @@ echo "preadv support $preadv" echo "fdatasync $fdatasync" echo "uuid support $uuid" echo "vhost-net support $vhost_net" +echo "Trace backend $trace_backend" if test $sdl_too_old = "yes"; then echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -2450,6 +2467,7 @@ bsd) ;; esac +echo "TRACE_BACKEND=$trace_backend" >> $config_host_mak echo "TOOLS=$tools" >> $config_host_mak echo "ROMS=$roms" >> $config_host_mak echo "MAKE=$make" >> $config_host_mak
trace-events new file +24 -0
@@ -0,0 +1,24 @@ +# Trace events for debugging and performance instrumentation +# +# This file is processed by the tracetool script during the build. +# +# To add a new trace event: +# +# 1. Choose a name for the trace event. Declare its arguments and format +# string. +# +# 2. Call the trace event from code using trace_##name, e.g. multiwrite_cb() -> +# trace_multiwrite_cb(). The source file must #include "trace.h". +# +# Format of a trace event: +# +# <name>(<type1> <arg1>[, <type2> <arg2>] ...) "<format-string>" +# +# Example: qemu_malloc(size_t size) "size %zu" +# +# The <name> must be a valid as a C function name. +# +# Types should be standard C types. Use void * for pointers because the trace +# system may not have the necessary headers included. +# +# The <format-string> should be a sprintf()-compatible format string.
tracetool new file +175 -0
175 lines not on this page · raw message
Signature · 1 line
1.7.1