Commit Graph

188 Commits

Author SHA1 Message Date
Eiichi Tsukata 781e9545db trace: Add ftrace tracing backend
This patch adds a ftrace tracing backend which sends trace event to
ftrace marker file. You can effectively compare qemu trace data and
kernel(especially, kvm.ko when using KVM) trace data.
The ftrace backend is restricted to Linux only.

To try out the ftrace backend:

 $ ./configure --trace-backend=ftrace
 $ make

if you use KVM, enable kvm events in ftrace:

 # sudo echo 1 > /sys/kernel/debug/tracing/events/kvm/enable

After running qemu by root user, you can get the trace:

 # cat /sys/kernel/debug/tracing/trace

Signed-off-by: Eiichi Tsukata <eiichi.tsukata.xh@hitachi.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2013-05-03 13:58:09 +02:00
Stefan Hajnoczi a7373b1f61 trace: rebuild generated-events.o when configuration changes
Make sure to rebuild generated-events.o when ./configure options change.
This prevents linker errors when a stale generated-events.o gets linked
with code compiled against fresh headers.  For example, try building
with ./configure --enable-trace-backend=stderr followed by ./configure
--enable-trace-backend=dtrace.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2013-03-28 14:19:57 +01:00
Lluís Vilanova c6f18b9195 trace: [stderr] Port to generic event information and new control interface
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2013-03-28 14:19:57 +01:00
Lluís Vilanova 60481e210d trace: [simple] Port to generic event information and new control interface
The backend is forced to dump event numbers using 64 bits, as TraceEventID is
an enum.

Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2013-03-28 14:19:57 +01:00
Lluís Vilanova fd068a953c trace: [default] Port to generic event information and new control interface
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2013-03-28 14:19:57 +01:00
Lluís Vilanova b1bae816c4 trace: Provide a detailed event control interface
This interface decouples event obtaining from interaction.

Events can be obtained through three different methods:

* identifier
* name
* simple wildcard pattern

Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2013-03-28 14:19:57 +01:00
Lluís Vilanova 45be2f5d0d trace: Provide a generic tracing event descriptor
Uses tracetool to generate a backend-independent tracing event description
(struct TraceEvent).

The values for such structure are generated with the non-public "events"
backend ("events-c" frontend).

The generation of the defines to check if an event is statically enabled is also
moved to the "events" backend ("events-h" frontend).

Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2013-03-28 14:19:57 +01:00
Stefan Hajnoczi 4a0e6714b0 trace: deal with deprecated glib thread functions
g_thread_create() was deprecated in favor of g_thread_new() and
g_cond_new() was deprecated in favor of GCond initialization.  If the
host has glib 2.31 or newer, avoid using the deprecated functions.

This patch solves compiler warnings that are generated when glib's
deprecated functions are used.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-id: 1360676045-9204-3-git-send-email-stefanha@redhat.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2013-02-12 16:26:44 -06:00
Stefan Hajnoczi 30d940875d trace: use glib atomic int types
Juan reported that RHEL 6.4 hosts give compiler warnings because we use
unsigned int while glib prototypes use volatile gint in trace/simple.c.

  trace/simple.c:223: error: pointer targets in passing argument 1 of 'g_atomic_int_compare_and_exchange' differ in signedness

These variables are only accessed with glib atomic int functions so
let's play it by the book and use volatile gint.

Reported-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-id: 1360676045-9204-2-git-send-email-stefanha@redhat.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2013-02-12 16:26:43 -06:00
Markus Armbruster b6b2c96280 trace: Clean up the "try to update atomic until it worked" loops
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Harsh Prateek Bora <harsh@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2013-02-05 21:52:55 +01:00
Markus Armbruster e722d705ae trace: Direct access of atomics is verboten, use the API
The GLib Reference Manual says:

    It is very important that all accesses to a particular integer or
    pointer be performed using only this API and that different sizes
    of operation are not mixed or used on overlapping memory
    regions. Never read or assign directly from or to a value --
    always use this API.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Harsh Prateek Bora <harsh@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2013-02-05 21:52:55 +01:00
Markus Armbruster fb3a508531 trace: Fix simple trace dropped event record for big endian
We use atomic operations to keep track of dropped events.

Inconveniently, GLib supports only int and void * atomics, but the
counter dropped_events is uint64_t.  Can't stop commit 62bab732: a
quick (gint *)&dropped_events bludgeons the compiler into submission.

That cast is okay only when int is exactly 64 bits wide, which it
commonly isn't.

If int is even wider, we clobber whatever follows dropped_events.  Not
worth worrying about, as none of the machines that interest us have
such morbidly obese ints.

That leaves the common case: int narrower than 64 bits.

Harmless on little endian hosts: we just don't access the most
significant bits of dropped_events.  They remain zero.

On big endian hosts, we use only the most significant bits of
dropped_events as counter.  The least significant bits remain zero.
However, we write out the full value, which is the correct counter
shifted left a bunch of places.

Fix by changing the variables involved to int.

There's another, equally suspicious-looking (gint *)&trace_idx
argument to g_atomic_int_compare_and_exchange(), but that one casts
unsigned *, so it's okay.  But it's also superfluous, because GLib's
atomic int operations work just fine for unsigned.  Drop it.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2013-02-05 21:52:55 +01:00
Michael S. Tsirkin 6f329a5530 Makefile: clean timestamp generation rule
create timestamp by rule without sideeffects.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2013-01-30 01:31:08 +02:00
Paolo Bonzini ff667e2e9b build: fold trace-obj-y into libqemuutil.a
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2013-01-12 18:42:51 +01:00
Paolo Bonzini 0e848f482b build: some simplifications for "trace/Makefile.objs"
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2013-01-12 18:42:51 +01:00
Paolo Bonzini 2c13ec50e7 build: move dtrace rules to rules.mak
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2013-01-12 17:19:09 +01:00
Lluís Vilanova eac236ea7b build: Use separate makefile for "trace/"
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
--
Changes in v2:

* Do not depend on "qemu-timer-common.o".
* Use "$(obj)" in rules to refer to the build sub-directory.
* Remove dependencies against "$(GENERATED_HEADERS)".

Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-12-23 14:28:02 -06:00
Paolo Bonzini 1de7afc984 misc: move include files to include/qemu/
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-12-19 08:32:39 +01:00
Gerd Hoffmann ddde8acc98 trace: allow disabling events in events file
Disable trace events prefixed with a '-'.  Useful
to enable a group of tracepoints with exceptions,
like this:

  usb_xhci_port_*
  -usb_xhci_port_read

which will enable all xhci port tracepoints except reads.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2012-11-16 13:12:13 +01:00
Stefan Weil 4552e41025 trace/simple: Replace asprintf by g_strdup_printf
asprintf is not available for all hosts. g_strdup_printf is
more portable and simplifies the code because if does not
need error handling.

The static variable does not need an explicit assignment to be NULL.

Cc: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Signed-off-by: Stefan Weil <sw@weilnetz.de>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2012-08-14 13:19:57 +01:00
Harsh Prateek Bora db8894f209 trace: avoid pointer aliasing in trace_record_finish()
Declaring a TraceRecord on the stack works fine.  No need for a
uint8_t array and pointer aliasing.

Signed-off-by: Harsh Prateek Bora <harsh@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2012-08-14 10:40:39 +01:00
Harsh Prateek Bora fd82f015a1 trace: drop unused TraceBufferRecord->next_tbuf_idx field
Signed-off-by: Harsh Prateek Bora <harsh@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2012-08-14 10:40:39 +01:00
Harsh Prateek Bora 83d35d3e99 trace: remove unnecessary write_to_buffer() typecasting
The buffer argument is void* so it is not necessary to cast.

Signed-off-by: Harsh Prateek Bora <harsh@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2012-08-14 10:40:39 +01:00
Harsh Prateek Bora 8ae601e8fe trace: rename TraceRecordHeader to TraceLogHeader
The TraceRecordHeader is really the header for the entire trace log
file.  It's not per-record header so make this obvious by renaming it.

Signed-off-by: Harsh Prateek Bora <harsh@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2012-08-14 10:40:39 +01:00
Harsh Prateek Bora 62bab73213 Simpletrace v2: Support multiple arguments, strings.
Existing simpletrace backend allows to trace at max 6 args and does not
support strings. This newer tracelog format gets rid of fixed size records
and therefore allows to trace variable number of args including strings.

Sample trace with strings:
v9fs_version 0.000 tag=0xffff id=0x64 msize=0x2000 version=9P2000.L
v9fs_version_return 6.705 tag=0xffff id=0x64 msize=0x2000 version=9P2000.L

Signed-off-by: Harsh Prateek Bora <harsh@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2012-07-19 11:34:33 +01:00
Harsh Prateek Bora 88affa1c77 monitor: remove unused do_info_trace
Going forward with simpletrace v2 variable size trace records, we cannot
have a generic function to print trace event info and therefore this
interface becomes invalid.

As per Stefan Hajnoczi:

"This command is only available from the human monitor.  It's not very
useful because it historically hasn't been able to pretty-print events
or show them in the right order (we use a ringbuffer but it prints
them out from index 0).

Therefore, I don't think we're under any obligation to keep this
command around.  No one has complained about it's limitations - I
think this is a sign that no one has used it.  I'd be okay with a
patch that removes it."

Ref: http://lists.gnu.org/archive/html/qemu-devel/2012-01/msg01268.html

Signed-off-by: Harsh Prateek Bora <harsh@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2012-07-19 11:34:32 +01:00
Alexey Kardashevskiy 794b1f962e trace: added ability to comment out events in the list
It is convenient for debug to be able to switch on/off some events easily.
The only possibility now is to remove event name from the file completely
and type it again when we want it back.

The patch adds '#' symbol handling as a comment specifier.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2012-07-19 11:30:37 +01:00
Harsh Prateek Bora 0d665005c7 trace/simple.c: fix deprecated glib2 interface
Signed-off-by: Harsh Prateek Bora <harsh@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2012-06-08 09:32:40 +01:00
Jun Koi db3bf86963 trace: make trace_thread_create() use its function arg
This patch makes trace_thread_create() to use its function arg to
initialize thread.  The other choice is to make this a function to use
void arg, but i prefer this way.

Signed-off-by: Jun Koi <junkoi2004@gmail.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2012-03-12 10:12:34 +00:00
Alon Levy 42ed372753 g_thread_init users: don't call it if glib >= 2.31
since commit f9b29ca03 included in release 2.31 (docs below say 2.32 but
that is not correct) and onwards g_thread_init is deprecated and calling
it is not required:

 http://developer.gnome.org/glib/unstable/glib-Deprecated-Thread-APIs.html#g-thread-init

 g_thread_init has been deprecated since version 2.32 and should not be
 used in newly-written code. This function is no longer necessary. The
 GLib threading system is automatically initialized at the start of your
 program.

Fixes bulid failure when warnings are treated as errors on fedora 17.

I only tested the change to vl.c, and copy pasted to the two other
locations (couldn't decide if a wrapper for calling g_thread_init is
uglier).

Signed-off-by: Alon Levy <alevy@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-12-20 15:44:31 -06:00
Mark Wu 454e202d52 trace: Add wildcard trace event support
A basic wildcard matching is supported in both the monitor command
"trace-event" and the events list file. That means you can enable/disable
the events having a common prefix in a batch. For example, virtio-blk trace
events could be enabled using:
    trace-event virtio_blk_* on

Signed-off-by: Mark Wu <wudxw@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2011-11-01 14:12:15 +00:00
Stefan Hajnoczi 6c2a407426 trace: use binary file open mode in simpletrace
For Windows portability the simple trace backend must use the 'b' file
open mode.  This prevents the stdio library from mangling 0x0a/0x0d
newline characters.

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2011-09-21 11:30:10 +01:00
Stefan Hajnoczi 85aff1586f trace: portable simple trace backend using glib
Convert the simple trace backend to glib so that it works under Windows.
We cannot use pthread directly but glib provides portable abstractions.
Also use glib atomics instead of newish gcc builtins which may not be
supported on Windows toolchains.

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2011-09-21 11:30:07 +01:00
Lluís 9a82b6a590 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 <chouteau@adacore.com>
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
2011-09-01 10:34:54 +01:00
Lluís 23d15e860b trace: add "-trace events" argument to control initial state
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 <vilanova@ac.upc.edu>
2011-09-01 10:34:54 +01:00
Lluís fc76410539 trace: separate trace event control and query routines from the simple backend
Generalize the 'st_print_trace_events' and 'st_change_trace_event_state' into
backend-specific 'trace_print_events' and 'trace_event_set_state' (respectively)
in the "trace/control.h" file.

Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
2011-09-01 10:34:54 +01:00
Lluís e4858974ec trace: avoid conditional code compilation during option parsing
A default implementation for backend-specific routines is provided in
"trace/default.c", which backends can override by setting "trace_default=no" in
"configure".

Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
2011-09-01 10:34:53 +01:00
Lluís edb47ec498 trace: move backend-specific code into the trace/ directory
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
2011-09-01 10:34:53 +01:00