Skip to content

trace: Add static tracing to QEMU

Stefan Hajnoczi qemu-devel 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest posting 2/214 patches 6 repliesIn review
  2. v3 posting 1/21 patch 0 repliesSuperseded
  3. v214 patches 7 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v114 patches20 repliesSuperseded

Changes in v3 from the cover letter

* write trace files to current working directory by default
* avoid adding -lust to LIBS twice

Patches in v3 posting 2/2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/14trace: Add trace-events file for declaring trace events.gitignore Makefile Makefile.objs +4 more+238 -42 replies
2/14trace: Add simple built-in tracing backend.gitignore Makefile Makefile.objs +5 more+360 -40 replies
3/14trace: Support for dynamically enabling/disabling trace eventsconfigure monitor.c qemu-monitor.hx +3 more+149 -40 replies
4/14trace: Support disabled events in trace-eventstrace-events tracetool+45 -60 replies
5/14trace: Specify trace file nameconfigure simpletrace.c+29 -40 replies
6/14trace: Add trace-file command to open/close/flush trace filemonitor.c qemu-monitor.hx simpletrace.c +1 more+88 -130 replies
7/14trace: Add trace file name command-line optionqemu-config.c qemu-options.hx vl.c+50 -00 replies
8/14trace: Add LTTng Userspace Tracer backendconfigure tracetool+102 -30 replies
9/14trace: Add user documentationdocs/tracing.txt+177 -00 replies
10/14trace: Trace qemu_malloc() and qemu_vmalloc()osdep.c qemu-malloc.c trace-events+38 -80 replies
11/14trace: Trace virtio-blk, multiwrite, and paio_submitblock.c hw/virtio-blk.c posix-aio-compat.c +1 more+31 -00 replies
12/14trace: Trace virtqueue operationshw/virtio.c trace-events+16 -00 replies
13/14trace: Trace port IOioport.c trace-events+11 -00 replies
14/14trace: Trace entry point of balloon request handlerballoon.c trace-events+6 -00 replies

Reviews trailers per patch

None of the 14 patches has a Reviewed-by or Acked-by.

PatchStefan Hajnoczi
1/14
2/14
3/14
4/14
5/14Edited-by
6/14
7/14
8/14
9/14
10/14
11/14
12/14
13/14
14/14

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [Qemu-devel] [PATCH v3 00/14] 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 trace-<pid>. They can be pretty-printed like this:

./simpletrace.py trace-events 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/refs/heads/tracing_v3:/docs/tracing.txt

The git branch is here:
http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/tracing_v3

Changes in v3:
* write trace files to current working directory by default
* avoid adding -lust to LIBS twice

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