From 49926043c1319ce99481d45c87c602c20b9dbb79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs?= Date: Wed, 31 Aug 2011 20:31:10 +0200 Subject: trace: generalize the "property" concept in the trace-events file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds/modifies the following functions: * get_name: Get _only_ the event name * has_property: Return whether an event has a property (keyword before the event name) Signed-off-by: Lluís Vilanova --- docs/tracing.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs') 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. -- cgit v1.2.1 From 31965ae27bc11e90674be12584bb201b83df5aef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs?= Date: Wed, 31 Aug 2011 20:31:24 +0200 Subject: trace: always compile support for controlling and querying trace event states MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current interface is generic for this small set of operations, and thus other backends can easily modify the "trace/control.c" file to add their own implementation. Signed-off-by: Lluís Vilanova --- docs/tracing.txt | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) (limited to 'docs') diff --git a/docs/tracing.txt b/docs/tracing.txt index 1ad106a5d7..41eb8e6fec 100644 --- a/docs/tracing.txt +++ b/docs/tracing.txt @@ -108,6 +108,36 @@ portability macros, ensure they are preceded and followed by double quotes: of trace events. Marking trace events disabled by default saves the user from having to manually disable noisy trace events. +== Generic interface and monitor commands == + +You can programmatically query and control the dynamic state of trace events +through a backend-agnostic interface: + +* trace_print_events + +* trace_event_set_state + Enables or disables trace events at runtime inside QEMU. + The function returns "true" if the state of the event has been successfully + changed, or "false" otherwise: + + #include "trace/control.h" + + trace_event_set_state("virtio_irq", true); /* enable */ + [...] + trace_event_set_state("virtio_irq", false); /* disable */ + +Note that some of the backends do not provide an implementation for this +interface, in which case QEMU will just print a warning. + +This functionality is also provided through monitor commands: + +* 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 backends == The "tracetool" script automates tedious trace event code generation and also @@ -157,27 +187,9 @@ unless you have specific needs for more advanced backends. 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 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 -- cgit v1.2.1 From 23d15e860b33819ad76092fbb32577542fe0c44d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs?= Date: Wed, 31 Aug 2011 20:31:31 +0200 Subject: trace: add "-trace events" argument to control initial state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "-trace events" argument can be used to provide a file with a list of trace event names that will be enabled prior to starting execution, thus providing early tracing. This saves the user from manually toggling event states through the monitor interface or whichever backend-specific interface. Signed-off-by: Lluís Vilanova --- docs/tracing.txt | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'docs') diff --git a/docs/tracing.txt b/docs/tracing.txt index 41eb8e6fec..455da37969 100644 --- a/docs/tracing.txt +++ b/docs/tracing.txt @@ -138,6 +138,10 @@ This functionality is also provided through monitor commands: * trace-event NAME on|off Enable/disable a given trace event. +The "-trace events=" command line argument can be used to enable the +events listed in from the very beginning of the program. This file must +contain one event name per line. + == Trace backends == The "tracetool" script automates tedious trace event code generation and also -- cgit v1.2.1 From dd215f646c72b4cf680097b13aeb8b0c589dceb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs?= Date: Wed, 31 Aug 2011 20:31:38 +0200 Subject: trace: always use the "nop" backend on events with the "disable" keyword MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Any event with the keyword/property "disable" generates an empty trace event using the "nop" backend, regardless of the current backend. Signed-off-by: Lluís Vilanova --- docs/tracing.txt | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'docs') 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 -- cgit v1.2.1 From 03727e6a06087dc8f46d5674b4b29262bf7377a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs?= Date: Wed, 31 Aug 2011 20:31:45 +0200 Subject: trace: [simple] disable all trace points by default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'docs') 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-* -- cgit v1.2.1 From 9a82b6a590bd7c845ab9754b34b33ffee982ccb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs?= Date: Wed, 31 Aug 2011 20:31:51 +0200 Subject: trace: [stderr] add support for dynamically enabling/disabling events MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- docs/tracing.txt | 5 ----- 1 file changed, 5 deletions(-) (limited to 'docs') 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 -- cgit v1.2.1