diff mbox

[2/6] hypertrace: Add tracing event "guest_hypertrace"

Message ID 147041637432.2523.7105228834091669652.stgit@fimbulvetr.bsc.es
State New
Headers show

Commit Message

Lluís Vilanova Aug. 5, 2016, 4:59 p.m. UTC
Generates the "guest_hypertrace" event with a user-configurable number
of arguments.

Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
 Makefile.objs       |    2 ++
 configure           |   36 ++++++++++++++++++++++++++++++++++++
 trace/Makefile.objs |    2 +-
 3 files changed, 39 insertions(+), 1 deletion(-)

Comments

Stefan Hajnoczi Aug. 18, 2016, 9:59 a.m. UTC | #1
On Fri, Aug 05, 2016 at 06:59:34PM +0200, Lluís Vilanova wrote:
> +# hypertrace
> +hyperargs=$hypertrace
> +if test $hypertrace = "disabled"; then
> +    hyperargs=0
> +fi
> +echo "CONFIG_HYPERTRACE_ARGS=$hyperargs" >> $config_host_mak
> +hypertrace_events=hypertrace/trace-events
> +mkdir -p $(dirname $hypertrace_events)
> +echo "# See docs/trace-events.txt for syntax documentation." >$hypertrace_events
> +echo -n 'vcpu guest_hypertrace(' >>$hypertrace_events
> +for i in `seq $hypertrace`; do
> +    if test $i != 1; then
> +        echo -n ", " >>$hypertrace_events
> +    fi
> +    echo -n "uint64_t arg$i" >>$hypertrace_events
> +done
> +echo -n ') ' >>$hypertrace_events
> +for i in `seq $hypertrace`; do
> +    echo -n "\" arg$i=0x%016\"PRIx64" >>$hypertrace_events
> +done
> +echo >>$hypertrace_events

This reminds me of the first versions of "simpletrace" where the number
of arguments was fixed and argument size was fixed.

This meant strings cannot be traced, number of arguments is limited, and
you pay an space overhead for unused arguments.

Later on the format was changed to header (including .length field) and
binary data payload.  This reduced the space overhead, elminated the
argument count limit, and allowed strings to be traced.

I think these are desirable qualities for any tracing mechanism and
would reconsider a fixed number of uint64_t arguments.

Stefan
Lluís Vilanova Aug. 18, 2016, 10:32 a.m. UTC | #2
Stefan Hajnoczi writes:

> On Fri, Aug 05, 2016 at 06:59:34PM +0200, Lluís Vilanova wrote:
>> +# hypertrace
>> +hyperargs=$hypertrace
>> +if test $hypertrace = "disabled"; then
>> +    hyperargs=0
>> +fi
>> +echo "CONFIG_HYPERTRACE_ARGS=$hyperargs" >> $config_host_mak
>> +hypertrace_events=hypertrace/trace-events
>> +mkdir -p $(dirname $hypertrace_events)
>> +echo "# See docs/trace-events.txt for syntax documentation." >$hypertrace_events
>> +echo -n 'vcpu guest_hypertrace(' >>$hypertrace_events
>> +for i in `seq $hypertrace`; do
>> +    if test $i != 1; then
>> +        echo -n ", " >>$hypertrace_events
>> +    fi
>> +    echo -n "uint64_t arg$i" >>$hypertrace_events
>> +done
>> +echo -n ') ' >>$hypertrace_events
>> +for i in `seq $hypertrace`; do
>> +    echo -n "\" arg$i=0x%016\"PRIx64" >>$hypertrace_events
>> +done
>> +echo >>$hypertrace_events

> This reminds me of the first versions of "simpletrace" where the number
> of arguments was fixed and argument size was fixed.

> This meant strings cannot be traced, number of arguments is limited, and
> you pay an space overhead for unused arguments.

> Later on the format was changed to header (including .length field) and
> binary data payload.  This reduced the space overhead, elminated the
> argument count limit, and allowed strings to be traced.

> I think these are desirable qualities for any tracing mechanism and
> would reconsider a fixed number of uint64_t arguments.

The number of arguments is fixed at *compilation time*. What is not supported
out of the box is multiplexing multiple guest events over the hypertrace
event. That is, you need to do it yourself when post-processing the traces, but
I don't think that's too bad.


Cheers,
  Lluis
diff mbox

Patch

diff --git a/Makefile.objs b/Makefile.objs
index 7f1f0a3..1c1b03c 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -158,3 +158,5 @@  trace-events-y += target-s390x/trace-events
 trace-events-y += target-ppc/trace-events
 trace-events-y += qom/trace-events
 trace-events-y += linux-user/trace-events
+
+trace-events-gen-y = hypertrace/trace-events
diff --git a/configure b/configure
index 5ada56d..e80fde4 100755
--- a/configure
+++ b/configure
@@ -273,6 +273,7 @@  pie=""
 qom_cast_debug="yes"
 trace_backends="log"
 trace_file="trace"
+hypertrace="disabled"
 spice=""
 rbd=""
 smartcard=""
@@ -782,6 +783,8 @@  for opt do
   ;;
   --with-trace-file=*) trace_file="$optarg"
   ;;
+  --with-hypertrace-args=*) hypertrace="$optarg"
+  ;;
   --enable-gprof) gprof="yes"
   ;;
   --enable-gcov) gcov="yes"
@@ -1300,6 +1303,8 @@  Advanced options (experts only):
                            Available backends: $($python $source_path/scripts/tracetool.py --list-backends)
   --with-trace-file=NAME   Full PATH,NAME of file to store traces
                            Default:trace-<pid>
+  --with-hypertrace-args=NUMBER
+                           number of hypertrace arguments (default: disabled)
   --disable-slirp          disable SLIRP userspace network connectivity
   --enable-tcg-interpreter enable TCG with bytecode interpreter (TCI)
   --oss-lib                path to OSS library
@@ -4197,6 +4202,14 @@  if test "$?" -ne 0 ; then
 fi
 
 ##########################################
+# check hypertrace arguments
+case "$hypertrace" in
+    disabled) ;;
+    ''|*[!0-9]*) error_exit "invalid number of hypertrace arguments" ;;
+    *) ;;
+esac
+
+##########################################
 # For 'ust' backend, test if ust headers are present
 if have_backend "ust"; then
   cat > $TMPC << EOF
@@ -4862,6 +4875,7 @@  echo "Trace backends    $trace_backends"
 if have_backend "simple"; then
 echo "Trace output file $trace_file-<pid>"
 fi
+echo "Hypertrace arguments  $hypertrace"
 echo "spice support     $spice $(echo_version $spice $spice_protocol_version/$spice_server_version)"
 echo "rbd support       $rbd"
 echo "xfsctl support    $xfs"
@@ -5490,6 +5504,28 @@  else
 fi
 QEMU_INCLUDES="-I\$(SRC_PATH)/tcg $QEMU_INCLUDES"
 
+# hypertrace
+hyperargs=$hypertrace
+if test $hypertrace = "disabled"; then
+    hyperargs=0
+fi
+echo "CONFIG_HYPERTRACE_ARGS=$hyperargs" >> $config_host_mak
+hypertrace_events=hypertrace/trace-events
+mkdir -p $(dirname $hypertrace_events)
+echo "# See docs/trace-events.txt for syntax documentation." >$hypertrace_events
+echo -n 'vcpu guest_hypertrace(' >>$hypertrace_events
+for i in `seq $hypertrace`; do
+    if test $i != 1; then
+        echo -n ", " >>$hypertrace_events
+    fi
+    echo -n "uint64_t arg$i" >>$hypertrace_events
+done
+echo -n ') ' >>$hypertrace_events
+for i in `seq $hypertrace`; do
+    echo -n "\" arg$i=0x%016\"PRIx64" >>$hypertrace_events
+done
+echo >>$hypertrace_events
+
 echo "TOOLS=$tools" >> $config_host_mak
 echo "ROMS=$roms" >> $config_host_mak
 echo "MAKE=$make" >> $config_host_mak
diff --git a/trace/Makefile.objs b/trace/Makefile.objs
index 4d91b3b..b71ec54 100644
--- a/trace/Makefile.objs
+++ b/trace/Makefile.objs
@@ -8,7 +8,7 @@ 
 tracetool-y = $(SRC_PATH)/scripts/tracetool.py
 tracetool-y += $(shell find $(SRC_PATH)/scripts/tracetool -name "*.py")
 
-$(BUILD_DIR)/trace-events-all: $(trace-events-y:%=$(SRC_PATH)/%)
+$(BUILD_DIR)/trace-events-all: $(trace-events-y:%=$(SRC_PATH)/%) $(trace-events-gen-y:%=$(BUILD_DIR)/%)
 	$(call quiet-command,cat $^ > $@)
 
 ######################################################################