From edb47ec498a5c00607e8d428668d5141822a9eac Mon Sep 17 00:00:00 2001 From: Lluís Date: Wed, 31 Aug 2011 20:30:57 +0200 Subject: trace: move backend-specific code into the trace/ directory Signed-off-by: Lluís Vilanova --- scripts/tracetool | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/tracetool b/scripts/tracetool index 2155a57df2..9ed4fae70f 100755 --- a/scripts/tracetool +++ b/scripts/tracetool @@ -158,7 +158,7 @@ linetoc_end_nop() linetoh_begin_simple() { cat < --- docs/tracing.txt | 4 +-- scripts/tracetool | 73 +++++++++++++++++++++++++------------------------------ 2 files changed, 35 insertions(+), 42 deletions(-) (limited to 'scripts') diff --git a/docs/tracing.txt b/docs/tracing.txt index c99a0f27cf..1ad106a5d7 100644 --- a/docs/tracing.txt +++ b/docs/tracing.txt @@ -38,7 +38,7 @@ 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; @@ -103,7 +103,7 @@ portability macros, ensure they are preceded and followed by double quotes: 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 +5. Declare trace events with the "disable" property. 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. diff --git a/scripts/tracetool b/scripts/tracetool index 9ed4fae70f..e649a5b807 100755 --- a/scripts/tracetool +++ b/scripts/tracetool @@ -43,7 +43,26 @@ EOF # Get the name of a trace event get_name() { - echo ${1%%\(*} + local name + name=${1%%\(*} + echo "${name##* }" +} + +# Get the given property of a trace event +# 1: trace-events line +# 2: property name +# -> return 0 if property is present, or 1 otherwise +has_property() +{ + local props prop + props=${1%%\(*} + props=${props% *} + for prop in $props; do + if [ "$prop" = "$2" ]; then + return 0 + fi + done + return 1 } # Get the argument list of a trace event, including types and names @@ -101,20 +120,6 @@ get_fmt() echo "$fmt" } -# Get the state of a trace event -get_state() -{ - local str disable state - str=$(get_name "$1") - disable=${str##disable } - if [ "$disable" = "$str" ] ; then - state=1 - else - state=0 - fi - echo "$state" -} - linetoh_begin_nop() { return @@ -174,14 +179,10 @@ cast_args_to_uint64_t() linetoh_simple() { - local name args argc trace_args state + local name args argc trace_args name=$(get_name "$1") args=$(get_args "$1") argc=$(get_argc "$1") - state=$(get_state "$1") - if [ "$state" = "0" ]; then - name=${name##disable } - fi trace_args="$simple_event_num" if [ "$argc" -gt 0 ] @@ -222,9 +223,10 @@ linetoc_simple() { local name state name=$(get_name "$1") - state=$(get_state "$1") - if [ "$state" = "0" ] ; then - name=${name##disable } + if has_property "$1" "disable"; then + state="0" + else + state="1" fi cat < --- docs/tracing.txt | 25 +++++++++++++++---------- scripts/tracetool | 15 ++------------- 2 files changed, 17 insertions(+), 23 deletions(-) (limited to 'scripts') diff --git a/docs/tracing.txt b/docs/tracing.txt index 455da37969..85793cf173 100644 --- a/docs/tracing.txt +++ b/docs/tracing.txt @@ -12,15 +12,11 @@ for debugging, profiling, and observing execution. ./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: +2. Run the virtual machine to produce a trace file: qemu ... # your normal QEMU invocation -4. Pretty-print the binary trace file: +3. Pretty-print the binary trace file: ./simpletrace.py trace-events trace-* @@ -103,10 +99,11 @@ portability macros, ensure they are preceded and followed by double quotes: 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" property. 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. +5. If specific trace events are going to be called a huge number of times, this + might have a noticeable performance impact even when the trace events are + programmatically disabled. In this case you should declare the trace event + with the "disable" property, which will effectively disable it at compile + time (using the "nop" backend). == Generic interface and monitor commands == @@ -165,6 +162,9 @@ 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. +Note that regardless of the selected trace backend, events with the "disable" +property will be generated with the "nop" backend. + === Stderr === The "stderr" backend sends trace events directly to standard error. This @@ -173,6 +173,11 @@ effectively turns trace events into debug printfs. This is the simplest backend and can be used together with existing code that uses DPRINTF(). +Note that with this backend trace events cannot be programmatically +enabled/disabled. Thus, in order to trim down the amount of output and the +performance impact of tracing, you might want to add the "disable" property in +the "trace-events" file for those events you are not interested in. + === Simpletrace === The "simple" backend supports common use cases and comes as part of the QEMU diff --git a/scripts/tracetool b/scripts/tracetool index e649a5b807..e2cf11784b 100755 --- a/scripts/tracetool +++ b/scripts/tracetool @@ -506,21 +506,10 @@ convert() # Skip comments and empty lines test -z "${str%%#*}" && continue + echo # Process the line. The nop backend handles disabled lines. - disable="0" if has_property "$str" "disable"; then - disable="1" - fi - echo - if [ "$disable" = "1" ]; then - # Pass the disabled state as an arg for the simple - # or DTrace backends which handle it dynamically. - # For all other backends, call lineto$1_nop() - if [ $backend = "simple" -o "$backend" = "dtrace" ]; then - "$process_line" "$str" - else - "lineto$1_nop" "${str##disable }" - fi + "lineto$1_nop" "$str" else "$process_line" "$str" fi -- cgit v1.2.3-55-g7522 From 03727e6a06087dc8f46d5674b4b29262bf7377a4 Mon Sep 17 00:00:00 2001 From: Lluís Date: Wed, 31 Aug 2011 20:31:45 +0200 Subject: trace: [simple] disable all trace points by default Note that this refers to the backend-specific state (whether the output must be generated), not the event "disabled" property (which always uses the "nop" backend). Signed-off-by: Lluís Vilanova --- docs/tracing.txt | 11 ++++++++--- scripts/tracetool | 9 ++------- trace-events | 3 --- 3 files changed, 10 insertions(+), 13 deletions(-) (limited to 'scripts') diff --git a/docs/tracing.txt b/docs/tracing.txt index 85793cf173..d1d4e8cba2 100644 --- a/docs/tracing.txt +++ b/docs/tracing.txt @@ -12,11 +12,16 @@ for debugging, profiling, and observing execution. ./configure --trace-backend=simple make -2. Run the virtual machine to produce a trace file: +2. Create a file with the events you want to trace: - qemu ... # your normal QEMU invocation + echo bdrv_aio_readv > /tmp/events + echo bdrv_aio_writev >> /tmp/events -3. Pretty-print the binary trace file: +3. Run the virtual machine to produce a trace file: + + qemu -trace events=/tmp/events ... # your normal QEMU invocation + +4. Pretty-print the binary trace file: ./simpletrace.py trace-events trace-* diff --git a/scripts/tracetool b/scripts/tracetool index e2cf11784b..c740080ebb 100755 --- a/scripts/tracetool +++ b/scripts/tracetool @@ -221,15 +221,10 @@ EOF linetoc_simple() { - local name state + local name name=$(get_name "$1") - if has_property "$1" "disable"; then - state="0" - else - state="1" - fi cat < must be a valid as a C function name. # -- cgit v1.2.3-55-g7522 From 9a82b6a590bd7c845ab9754b34b33ffee982ccb2 Mon Sep 17 00:00:00 2001 From: Lluís Date: Wed, 31 Aug 2011 20:31:51 +0200 Subject: trace: [stderr] add support for dynamically enabling/disabling events Uses the generic interface provided in "trace/control.h" in order to provide a programmatic interface as well as command line and monitor controls. Signed-off-by: Fabien Chouteau Signed-off-by: Lluís Vilanova --- Makefile.objs | 2 ++ configure | 1 + docs/tracing.txt | 5 ----- qemu-options.hx | 3 ++- scripts/tracetool | 33 ++++++++++++++++++++++++++++----- trace/stderr.c | 37 +++++++++++++++++++++++++++++++++++++ trace/stderr.h | 11 +++++++++++ 7 files changed, 81 insertions(+), 11 deletions(-) create mode 100644 trace/stderr.c create mode 100644 trace/stderr.h (limited to 'scripts') diff --git a/Makefile.objs b/Makefile.objs index 036a4eb6ab..26b885bfeb 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -384,6 +384,8 @@ trace-nested-$(CONFIG_TRACE_DEFAULT) += default.o trace-nested-$(CONFIG_TRACE_SIMPLE) += simple.o trace-obj-$(CONFIG_TRACE_SIMPLE) += qemu-timer-common.o +trace-nested-$(CONFIG_TRACE_STDERR) += stderr.o + trace-nested-y += control.o trace-obj-y += $(addprefix trace/, $(trace-nested-y)) diff --git a/configure b/configure index 4f9b27ced4..300d34bd32 100755 --- a/configure +++ b/configure @@ -3078,6 +3078,7 @@ if test "$trace_backend" = "simple"; then fi if test "$trace_backend" = "stderr"; then echo "CONFIG_TRACE_STDERR=y" >> $config_host_mak + trace_default=no fi if test "$trace_backend" = "ust"; then echo "CONFIG_TRACE_UST=y" >> $config_host_mak diff --git a/docs/tracing.txt b/docs/tracing.txt index d1d4e8cba2..4b27ab0c2a 100644 --- a/docs/tracing.txt +++ b/docs/tracing.txt @@ -178,11 +178,6 @@ effectively turns trace events into debug printfs. This is the simplest backend and can be used together with existing code that uses DPRINTF(). -Note that with this backend trace events cannot be programmatically -enabled/disabled. Thus, in order to trim down the amount of output and the -performance impact of tracing, you might want to add the "disable" property in -the "trace-events" file for those events you are not interested in. - === Simpletrace === The "simple" backend supports common use cases and comes as part of the QEMU diff --git a/qemu-options.hx b/qemu-options.hx index edd181bb8e..f672365e42 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2454,7 +2454,8 @@ Immediately enable events listed in @var{file}. The file must contain one event name (as listed in the @var{trace-events} file) per line. -This option is only available when using the @var{simple} tracing backend. +This option is only available when using the @var{simple} and @var{stderr} +tracing backends. @item file=@var{file} Log output traces to @var{file}. diff --git a/scripts/tracetool b/scripts/tracetool index c740080ebb..743d246289 100755 --- a/scripts/tracetool +++ b/scripts/tracetool @@ -241,7 +241,12 @@ linetoh_begin_stderr() { cat < +#include "trace/stderr.h" + +extern TraceEvent trace_list[]; EOF + + stderr_event_num=0 } linetoh_stderr() @@ -260,29 +265,47 @@ linetoh_stderr() cat < --- scripts/simpletrace.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py index 2ad56998ee..f55e5e63f9 100755 --- a/scripts/simpletrace.py +++ b/scripts/simpletrace.py @@ -102,10 +102,10 @@ def process(events, log, analyzer): fn_argcount = len(inspect.getargspec(fn)[0]) - 1 if fn_argcount == event_argcount + 1: # Include timestamp as first argument - return lambda _, rec: fn(*rec[1:2 + fn_argcount]) + return lambda _, rec: fn(*rec[1:2 + event_argcount]) else: # Just arguments, no timestamp - return lambda _, rec: fn(*rec[2:2 + fn_argcount]) + return lambda _, rec: fn(*rec[2:2 + event_argcount]) analyzer.begin() fn_cache = {} -- cgit v1.2.3-55-g7522