blob: d288480db11f80e8d490f358a50956e4fbab2ae9 [file] [log] [blame]
Vladimir Sementsov-Ogievskiyff8e4822022-01-26 17:11:28 +01001.. _tracing:
2
Stefan Hajnoczie50caf42020-12-16 16:09:22 +00003=======
4Tracing
5=======
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +01006
Stefan Hajnoczie50caf42020-12-16 16:09:22 +00007Introduction
8============
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +01009
10This document describes the tracing infrastructure in QEMU and how to use it
11for debugging, profiling, and observing execution.
12
Stefan Hajnoczie50caf42020-12-16 16:09:22 +000013Quickstart
14==========
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +010015
Stefan Hajnoczi7e46d5f2020-12-16 16:09:23 +000016Enable tracing of ``memory_region_ops_read`` and ``memory_region_ops_write``
17events::
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +010018
Stefan Hajnoczi7e46d5f2020-12-16 16:09:23 +000019 $ qemu --trace "memory_region_ops_*" ...
20 ...
21 719585@1608130130.441188:memory_region_ops_read cpu 0 mr 0x562fdfbb3820 addr 0x3cc value 0x67 size 1
22 719585@1608130130.441190:memory_region_ops_write cpu 0 mr 0x562fdfbd2f00 addr 0x3d4 value 0x70e size 2
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +010023
Stefan Hajnoczi7e46d5f2020-12-16 16:09:23 +000024This output comes from the "log" trace backend that is enabled by default when
25``./configure --enable-trace-backends=BACKENDS`` was not explicitly specified.
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +010026
Stefan Hajnoczi3faf22e2021-01-12 16:58:58 +000027Multiple patterns can be specified by repeating the ``--trace`` option::
28
29 $ qemu --trace "kvm_*" --trace "virtio_*" ...
30
31When patterns are used frequently it is more convenient to store them in a
32file to avoid long command-line options::
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +010033
Stefan Hajnoczi7e46d5f2020-12-16 16:09:23 +000034 $ echo "memory_region_ops_*" >/tmp/events
Stefan Hajnoczi3faf22e2021-01-12 16:58:58 +000035 $ echo "kvm_*" >>/tmp/events
Stefan Hajnoczi7e46d5f2020-12-16 16:09:23 +000036 $ qemu --trace events=/tmp/events ...
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +010037
Stefan Hajnoczie50caf42020-12-16 16:09:22 +000038Trace events
39============
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +010040
Stefan Hajnoczie50caf42020-12-16 16:09:22 +000041Sub-directory setup
42-------------------
Daniel P. Berranged4fa8432017-01-25 16:14:16 +000043
Stefan Hajnoczi0dfb3ca2021-01-12 16:58:59 +000044Each directory in the source tree can declare a set of trace events in a local
45"trace-events" file. All directories which contain "trace-events" files must be
46listed in the "trace_events_subdirs" variable in the top level meson.build
47file. During build, the "trace-events" file in each listed subdirectory will be
48processed by the "tracetool" script to generate code for the trace events.
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +010049
Daniel P. Berranged4fa8432017-01-25 16:14:16 +000050The individual "trace-events" files are merged into a "trace-events-all" file,
Marc-André Lureau7a42e682022-04-20 17:25:55 +040051which is also installed into "/usr/share/qemu".
Daniel P. Berranged4fa8432017-01-25 16:14:16 +000052This merged file is to be used by the "simpletrace.py" script to later analyse
53traces in the simpletrace data format.
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +010054
Stefan Hajnoczi0dfb3ca2021-01-12 16:58:59 +000055The following files are automatically generated in <builddir>/trace/ during the
56build:
Daniel P. Berranged4fa8432017-01-25 16:14:16 +000057
Stefan Hajnoczi0dfb3ca2021-01-12 16:58:59 +000058 - trace-<subdir>.c - the trace event state declarations
59 - trace-<subdir>.h - the trace event enums and probe functions
60 - trace-dtrace-<subdir>.h - DTrace event probe specification
61 - trace-dtrace-<subdir>.dtrace - DTrace event probe helper declaration
62 - trace-dtrace-<subdir>.o - binary DTrace provider (generated by dtrace)
63 - trace-ust-<subdir>.h - UST event probe helper declarations
Daniel P. Berranged4fa8432017-01-25 16:14:16 +000064
Stefan Hajnoczi0dfb3ca2021-01-12 16:58:59 +000065Here <subdir> is the sub-directory path with '/' replaced by '_'. For example,
66"accel/kvm" becomes "accel_kvm" and the final filename for "trace-<subdir>.c"
67becomes "trace-accel_kvm.c".
68
69Source files in the source tree do not directly include generated files in
70"<builddir>/trace/". Instead they #include the local "trace.h" file, without
71any sub-directory path prefix. eg io/channel-buffer.c would do::
Daniel P. Berranged4fa8432017-01-25 16:14:16 +000072
73 #include "trace.h"
74
Stefan Hajnoczi0dfb3ca2021-01-12 16:58:59 +000075The "io/trace.h" file must be created manually with an #include of the
76corresponding "trace/trace-<subdir>.h" file that will be generated in the
77builddir::
78
79 $ echo '#include "trace/trace-io.h"' >io/trace.h
80
81While it is possible to include a trace.h file from outside a source file's own
82sub-directory, this is discouraged in general. It is strongly preferred that
83all events be declared directly in the sub-directory that uses them. The only
84exception is where there are some shared trace events defined in the top level
85directory trace-events file. The top level directory generates trace files
86with a filename prefix of "trace/trace-root" instead of just "trace". This is
87to avoid ambiguity between a trace.h in the current directory, vs the top level
88directory.
Daniel P. Berranged4fa8432017-01-25 16:14:16 +000089
Stefan Hajnoczie50caf42020-12-16 16:09:22 +000090Using trace events
91------------------
Daniel P. Berrange1412cf52016-06-16 09:39:47 +010092
Stefan Hajnoczie50caf42020-12-16 16:09:22 +000093Trace events are invoked directly from source code like this::
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +010094
95 #include "trace.h" /* needed for trace event prototype */
Lluís49926042011-08-31 20:31:10 +020096
Lluís Vilanova4b710a32011-09-20 21:03:48 +020097 void *qemu_vmalloc(size_t size)
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +010098 {
99 void *ptr;
Lluís Vilanova4b710a32011-09-20 21:03:48 +0200100 size_t align = QEMU_VMALLOC_ALIGN;
101
102 if (size < align) {
103 align = getpagesize();
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +0100104 }
Lluís Vilanova4b710a32011-09-20 21:03:48 +0200105 ptr = qemu_memalign(align, size);
106 trace_qemu_vmalloc(size, ptr);
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +0100107 return ptr;
108 }
109
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000110Declaring trace events
111----------------------
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +0100112
Lluís7b92e5b2011-04-06 20:33:56 +0200113The "tracetool" script produces the trace.h header file which is included by
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +0100114every source file that uses trace events. Since many source files include
Lluís7b92e5b2011-04-06 20:33:56 +0200115trace.h, it uses a minimum of types and other header files included to keep the
116namespace clean and compile times and dependencies down.
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +0100117
118Trace events should use types as follows:
119
120 * Use stdint.h types for fixed-size types. Most offsets and guest memory
121 addresses are best represented with uint32_t or uint64_t. Use fixed-size
122 types over primitive types whose size may change depending on the host
123 (32-bit versus 64-bit) so trace events don't truncate values or break
124 the build.
125
126 * Use void * for pointers to structs or for arrays. The trace.h header
127 cannot include all user-defined struct declarations and it is therefore
128 necessary to use void * for pointers to structs.
129
130 * For everything else, use primitive scalar types (char, int, long) with the
131 appropriate signedness.
132
Stefan Hajnocziec09f872018-06-21 16:02:54 +0100133 * Avoid floating point types (float and double) because SystemTap does not
134 support them. In most cases it is possible to round to an integer type
135 instead. This may require scaling the value first by multiplying it by 1000
136 or the like when digits after the decimal point need to be preserved.
137
Stefan Hajnoczi9a85d392010-10-05 14:28:50 +0100138Format strings should reflect the types defined in the trace event. Take
139special care to use PRId64 and PRIu64 for int64_t and uint64_t types,
Stefan Hajnoczi913540a2011-09-13 13:34:35 +0100140respectively. This ensures portability between 32- and 64-bit platforms.
Philippe Mathieu-Daudé9f7ad792019-09-16 11:51:21 +0200141Format strings must not end with a newline character. It is the responsibility
142of backends to adapt line ending for proper logging.
Stefan Hajnoczi9a85d392010-10-05 14:28:50 +0100143
Daniel P. Berranged4fa8432017-01-25 16:14:16 +0000144Each event declaration will start with the event name, then its arguments,
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000145finally a format string for pretty-printing. For example::
Daniel P. Berranged4fa8432017-01-25 16:14:16 +0000146
147 qemu_vmalloc(size_t size, void *ptr) "size %zu ptr %p"
148 qemu_vfree(void *ptr) "ptr %p"
149
150
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000151Hints for adding new trace events
152---------------------------------
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +0100153
1541. Trace state changes in the code. Interesting points in the code usually
155 involve a state change like starting, stopping, allocating, freeing. State
156 changes are good trace events because they can be used to understand the
157 execution of the system.
158
1592. Trace guest operations. Guest I/O accesses like reading device registers
160 are good trace events because they can be used to understand guest
161 interactions.
162
1633. Use correlator fields so the context of an individual line of trace output
164 can be understood. For example, trace the pointer returned by malloc and
165 used as an argument to free. This way mallocs and frees can be matched up.
166 Trace events with no context are not very useful.
167
1684. Name trace events after their function. If there are multiple trace events
169 in one function, append a unique distinguisher at the end of the name.
170
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000171Generic interface and monitor commands
172======================================
Lluís31965ae2011-08-31 20:31:24 +0200173
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100174You can programmatically query and control the state of trace events through a
175backend-agnostic interface provided by the header "trace/control.h".
Lluís31965ae2011-08-31 20:31:24 +0200176
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100177Note that some of the backends do not provide an implementation for some parts
178of this interface, in which case QEMU will just print a warning (please refer to
179header "trace/control.h" to see which routines are backend-dependent).
Lluís31965ae2011-08-31 20:31:24 +0200180
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100181The state of events can also be queried and modified through monitor commands:
Lluís31965ae2011-08-31 20:31:24 +0200182
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000183* ``info trace-events``
Lluís31965ae2011-08-31 20:31:24 +0200184 View available trace events and their state. State 1 means enabled, state 0
185 means disabled.
186
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000187* ``trace-event NAME on|off``
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100188 Enable/disable a given trace event or a group of events (using wildcards).
Lluís31965ae2011-08-31 20:31:24 +0200189
Yaowei Baidb817b82018-07-04 11:17:27 +0800190The "--trace events=<file>" command line argument can be used to enable the
Lluís23d15e82011-08-31 20:31:31 +0200191events listed in <file> from the very beginning of the program. This file must
192contain one event name per line.
193
Yaowei Baidb817b82018-07-04 11:17:27 +0800194If a line in the "--trace events=<file>" file begins with a '-', the trace event
Stefan Hajnoczi8f5a0fb2012-11-05 08:48:29 +0100195will be disabled instead of enabled. This is useful when a wildcard was used
196to enable an entire family of events but one noisy event needs to be disabled.
197
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100198Wildcard matching is supported in both the monitor command "trace-event" and the
199events list file. That means you can enable/disable the events having a common
200prefix in a batch. For example, virtio-blk trace events could be enabled using
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000201the following monitor command::
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100202
203 trace-event virtio_blk_* on
204
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000205Trace backends
206==============
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +0100207
Lluís7b92e5b2011-04-06 20:33:56 +0200208The "tracetool" script automates tedious trace event code generation and also
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +0100209keeps the trace event declarations independent of the trace backend. The trace
210events are not tightly coupled to a specific trace backend, such as LTTng or
Lluís7b92e5b2011-04-06 20:33:56 +0200211SystemTap. Support for trace backends can be added by extending the "tracetool"
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +0100212script.
213
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000214The trace backends are chosen at configure time::
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +0100215
Stefan Hajnoczi7e46d5f2020-12-16 16:09:23 +0000216 ./configure --enable-trace-backends=simple,dtrace
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +0100217
218For a list of supported trace backends, try ./configure --help or see below.
Dr. David Alan Gilbertb73e8bd2014-10-07 15:12:41 +0100219If multiple backends are enabled, the trace is sent to them all.
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +0100220
Peter Maydell3b0fc802016-11-04 16:27:17 +0000221If no backends are explicitly selected, configure will default to the
222"log" backend.
223
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +0100224The following subsections describe the supported trace backends.
225
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000226Nop
227---
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +0100228
229The "nop" backend generates empty trace event functions so that the compiler
Peter Maydell3b0fc802016-11-04 16:27:17 +0000230can optimize out trace events completely. This imposes no performance
231penalty.
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +0100232
Lluísdd215f62011-08-31 20:31:38 +0200233Note that regardless of the selected trace backend, events with the "disable"
234property will be generated with the "nop" backend.
235
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000236Log
237---
Stefan Hajnoczib48c20f2011-02-23 14:00:21 +0000238
Richard W.M. Jonesab8eb292016-03-20 21:00:14 +0000239The "log" backend sends trace events directly to standard error. This
Stefan Hajnoczib48c20f2011-02-23 14:00:21 +0000240effectively turns trace events into debug printfs.
241
242This is the simplest backend and can be used together with existing code that
243uses DPRINTF().
244
Stefan Hajnoczi418ed142021-01-25 11:35:07 +0000245The -msg timestamp=on|off command-line option controls whether or not to print
246the tid/timestamp prefix for each trace event.
247
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000248Simpletrace
249-----------
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +0100250
Stefan Hajnoczi7e46d5f2020-12-16 16:09:23 +0000251The "simple" backend writes binary trace logs to a file from a thread, making
252it lower overhead than the "log" backend. A Python API is available for writing
253offline trace file analysis scripts. It may not be as powerful as
254platform-specific or third-party trace backends but it is portable and has no
255special library dependencies.
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +0100256
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000257Monitor commands
258~~~~~~~~~~~~~~~~
Stefan Hajnoczic72e3e42020-12-16 16:09:21 +0000259
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000260* ``trace-file on|off|flush|set <path>``
Stefan Hajnoczic72e3e42020-12-16 16:09:21 +0000261 Enable/disable/flush the trace file or set the trace file name.
262
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000263Analyzing trace files
264~~~~~~~~~~~~~~~~~~~~~
Stefan Hajnoczic72e3e42020-12-16 16:09:21 +0000265
266The "simple" backend produces binary trace files that can be formatted with the
267simpletrace.py script. The script takes the "trace-events-all" file and the
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000268binary trace::
Stefan Hajnoczic72e3e42020-12-16 16:09:21 +0000269
270 ./scripts/simpletrace.py trace-events-all trace-12345
271
272You must ensure that the same "trace-events-all" file was used to build QEMU,
273otherwise trace event declarations may have changed and output will not be
274consistent.
275
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000276Ftrace
277------
Eiichi Tsukatae64dd5e2013-04-11 20:25:16 +0900278
279The "ftrace" backend writes trace data to ftrace marker. This effectively
280sends trace events to ftrace ring buffer, and you can compare qemu trace
281data and kernel(especially kvm.ko when using KVM) trace data.
282
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000283if you use KVM, enable kvm events in ftrace::
Eiichi Tsukatae64dd5e2013-04-11 20:25:16 +0900284
285 # echo 1 > /sys/kernel/debug/tracing/events/kvm/enable
286
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000287After running qemu by root user, you can get the trace::
Eiichi Tsukatae64dd5e2013-04-11 20:25:16 +0900288
289 # cat /sys/kernel/debug/tracing/trace
290
291Restriction: "ftrace" backend is restricted to Linux only.
292
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000293Syslog
294------
Paul Durrant0a852412016-08-04 14:44:14 +0100295
296The "syslog" backend sends trace events using the POSIX syslog API. The log
297is opened specifying the LOG_DAEMON facility and LOG_PID option (so events
298are tagged with the pid of the particular QEMU process that generated
299them). All events are logged at LOG_INFO level.
300
301NOTE: syslog may squash duplicate consecutive trace events and apply rate
302 limiting.
303
304Restriction: "syslog" backend is restricted to POSIX compliant OS.
305
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000306LTTng Userspace Tracer
307----------------------
Stefan Hajnoczi81a97d92010-06-22 15:07:09 +0100308
309The "ust" backend uses the LTTng Userspace Tracer library. There are no
310monitor commands built into QEMU, instead UST utilities should be used to list,
311enable/disable, and dump traces.
Stefan Hajnoczib48c20f2011-02-23 14:00:21 +0000312
Mohamad Gebaief3ef4a2014-01-29 22:47:57 -0500313Package lttng-tools is required for userspace tracing. You must ensure that the
314current user belongs to the "tracing" group, or manually launch the
315lttng-sessiond daemon for the current user prior to running any instance of
316QEMU.
317
318While running an instrumented QEMU, LTTng should be able to list all available
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000319events::
Mohamad Gebaief3ef4a2014-01-29 22:47:57 -0500320
321 lttng list -u
322
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000323Create tracing session::
Mohamad Gebaief3ef4a2014-01-29 22:47:57 -0500324
325 lttng create mysession
326
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000327Enable events::
Mohamad Gebaief3ef4a2014-01-29 22:47:57 -0500328
329 lttng enable-event qemu:g_malloc -u
330
331Where the events can either be a comma-separated list of events, or "-a" to
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000332enable all tracepoint events. Start and stop tracing as needed::
Mohamad Gebaief3ef4a2014-01-29 22:47:57 -0500333
334 lttng start
335 lttng stop
336
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000337View the trace::
Mohamad Gebaief3ef4a2014-01-29 22:47:57 -0500338
339 lttng view
340
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000341Destroy tracing session::
Mohamad Gebaief3ef4a2014-01-29 22:47:57 -0500342
343 lttng destroy
344
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000345Babeltrace can be used at any later time to view the trace::
Mohamad Gebaief3ef4a2014-01-29 22:47:57 -0500346
347 babeltrace $HOME/lttng-traces/mysession-<date>-<time>
348
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000349SystemTap
350---------
Stefan Hajnoczib48c20f2011-02-23 14:00:21 +0000351
352The "dtrace" backend uses DTrace sdt probes but has only been tested with
353SystemTap. When SystemTap support is detected a .stp file with wrapper probes
354is generated to make use in scripts more convenient. This step can also be
355performed manually after a build in order to change the binary name in the .stp
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000356probes::
Stefan Hajnoczib48c20f2011-02-23 14:00:21 +0000357
Lin Ma2e4ccbb2015-09-11 14:58:50 +0800358 scripts/tracetool.py --backends=dtrace --format=stap \
359 --binary path/to/qemu-binary \
360 --target-type system \
361 --target-name x86_64 \
Stefan Hajnoczibd200382019-10-09 14:51:54 +0100362 --group=all \
Stefan Hajnoczic05012a2020-08-27 15:29:12 +0100363 trace-events-all \
364 qemu.stp
Lluís Vilanovab7d66a72011-12-06 17:38:15 +0100365
Daniel P. Berrangé62dd1042019-01-23 12:00:16 +0000366To facilitate simple usage of systemtap where there merely needs to be printf
367logging of certain probes, a helper script "qemu-trace-stap" is provided.
368Consult its manual page for guidance on its usage.
369
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000370Trace event properties
371======================
Lluís Vilanovab7d66a72011-12-06 17:38:15 +0100372
Daniel P. Berrange1412cf52016-06-16 09:39:47 +0100373Each event in the "trace-events-all" file can be prefixed with a space-separated
Lluís Vilanovab7d66a72011-12-06 17:38:15 +0100374list of zero or more of the following event properties.
375
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000376"disable"
377---------
Lluís Vilanovab7d66a72011-12-06 17:38:15 +0100378
379If a specific trace event is going to be invoked a huge number of times, this
380might have a noticeable performance impact even when the event is
381programmatically disabled.
382
383In this case you should declare such event with the "disable" property. This
384will effectively disable the event at compile time (by using the "nop" backend),
385thus having no performance impact at all on regular builds (i.e., unless you
Daniel P. Berrange1412cf52016-06-16 09:39:47 +0100386edit the "trace-events-all" file).
Lluís Vilanovab7d66a72011-12-06 17:38:15 +0100387
388In addition, there might be cases where relatively complex computations must be
389performed to generate values that are only used as arguments for a trace
Peter Maydell1aa64302020-01-20 15:11:40 +0000390function. In these cases you can use 'trace_event_get_state_backends()' to
391guard such computations, so they are skipped if the event has been either
392compile-time disabled or run-time disabled. If the event is compile-time
393disabled, this check will have no performance impact.
Lluís Vilanovab7d66a72011-12-06 17:38:15 +0100394
Stefan Hajnoczie50caf42020-12-16 16:09:22 +0000395::
396
Lluís Vilanovab7d66a72011-12-06 17:38:15 +0100397 #include "trace.h" /* needed for trace event prototype */
398
399 void *qemu_vmalloc(size_t size)
400 {
401 void *ptr;
402 size_t align = QEMU_VMALLOC_ALIGN;
403
404 if (size < align) {
405 align = getpagesize();
406 }
407 ptr = qemu_memalign(align, size);
Peter Maydell1aa64302020-01-20 15:11:40 +0000408 if (trace_event_get_state_backends(TRACE_QEMU_VMALLOC)) {
Lluís Vilanovab7d66a72011-12-06 17:38:15 +0100409 void *complex;
410 /* some complex computations to produce the 'complex' value */
411 trace_qemu_vmalloc(size, ptr, complex);
412 }
413 return ptr;
414 }
Lluís Vilanovab1bae812013-03-05 14:47:38 +0100415