3 # Code generator for trace events
5 # Copyright IBM, Corp. 2010
7 # This work is licensed under the terms of the GNU GPL, version 2. See
8 # the COPYING file in the top-level directory.
10 # Disable pathname expansion, makes processing text with '*' characters simpler
16 usage: $0 [--nop | --simple | --stderr | --ust | --dtrace] [-h | -c]
17 Generate tracing code for a file on stdin.
20 --nop Tracing disabled
21 --simple Simple built-in backend
22 --stderr Stderr built-in backend
23 --ust LTTng User Space Tracing backend
24 --dtrace DTrace/SystemTAP backend
29 -d Generate .d file (DTrace only)
30 --stap Generate .stp file (DTrace with SystemTAP only)
33 --binary [path] Full path to QEMU binary
34 --target-arch [arch] QEMU emulator target arch
35 --target-type [type] QEMU emulator target type ('system' or 'user')
36 --probe-prefix [prefix] Prefix for dtrace probe names
37 (default: qemu-\$targettype-\$targetarch)
43 # Get the name of a trace event
51 # Get the given property of a trace event
52 # 1: trace-events line
54 # -> return 0 if property is present, or 1 otherwise
60 for prop in $props; do
61 if [ "$prop" = "$2" ]; then
68 # Get the argument list of a trace event, including types and names
77 # Get the argument name list of a trace event
80 local nfields field name sep
83 for field in $(get_args "$1"); do
84 nfields=$((nfields + 1))
89 # Only argument names have commas at the end
91 test "$field" = "$name" && continue
93 printf "%s%s " $name $sep
97 if [ "$nfields" -gt 1 ]
103 # Get the number of arguments to a trace event
108 for name in $(get_argnames "$1", ","); do
114 # Get the format string for a trace event
131 name=$(get_name "$1")
132 args=$(get_args "$1")
134 # Define an empty function for the trace event
136 static inline void trace_$name($args)
154 # No need for function definitions in nop backend
163 linetoh_begin_simple()
166 #include "trace/simple.h"
172 cast_args_to_uint64_t()
175 for arg in $(get_argnames "$1", ","); do
176 printf "%s" "(uint64_t)(uintptr_t)$arg"
182 local name args argc trace_args
183 name=$(get_name "$1")
184 args=$(get_args "$1")
185 argc=$(get_argc "$1")
187 trace_args="$simple_event_num"
190 trace_args="$trace_args, $(cast_args_to_uint64_t "$1")"
194 static inline void trace_$name($args)
196 trace$argc($trace_args);
200 simple_event_num=$((simple_event_num + 1))
206 #define NR_TRACE_EVENTS $simple_event_num
207 extern TraceEvent trace_list[NR_TRACE_EVENTS];
211 linetoc_begin_simple()
216 TraceEvent trace_list[] = {
225 name=$(get_name "$1")
226 if has_property "$1" "disable"; then
232 {.tp_name = "$name", .state=$state},
234 simple_event_num=$((simple_event_num + 1))
245 linetoh_begin_stderr()
254 local name args argnames argc fmt
255 name=$(get_name "$1")
256 args=$(get_args "$1")
257 argnames=$(get_argnames "$1" ",")
258 argc=$(get_argc "$1")
261 if [ "$argc" -gt 0 ]; then
262 argnames=", $argnames"
266 static inline void trace_$name($args)
268 fprintf(stderr, "$name $fmt\n" $argnames);
278 linetoc_begin_stderr()
294 # Clean up after UST headers which pollute the namespace
295 ust_clean_namespace() {
306 echo "#include <ust/tracepoint.h>"
312 local name args argnames
313 name=$(get_name "$1")
314 args=$(get_args "$1")
315 argnames=$(get_argnames "$1", ",")
318 DECLARE_TRACE(ust_$name, TP_PROTO($args), TP_ARGS($argnames));
319 #define trace_$name trace_ust_$name
331 #include <ust/marker.h>
332 $(ust_clean_namespace)
339 local name args argnames fmt
340 name=$(get_name "$1")
341 args=$(get_args "$1")
342 argnames=$(get_argnames "$1", ",")
343 [ -z "$argnames" ] || argnames=", $argnames"
347 DEFINE_TRACE(ust_$name);
349 static void ust_${name}_probe($args)
351 trace_mark(ust, $name, "$fmt"$argnames);
355 # Collect names for later
362 static void __attribute__((constructor)) trace_init(void)
366 for name in $names; do
368 register_trace_ust_$name(ust_${name}_probe);
375 linetoh_begin_dtrace()
378 #include "trace-dtrace.h"
384 local name args argnames nameupper
385 name=$(get_name "$1")
386 args=$(get_args "$1")
387 argnames=$(get_argnames "$1", ",")
389 nameupper=`echo $name | tr '[:lower:]' '[:upper:]'`
391 # Define an empty function for the trace event
393 static inline void trace_$name($args) {
394 if (QEMU_${nameupper}_ENABLED()) {
395 QEMU_${nameupper}($argnames);
406 linetoc_begin_dtrace()
413 # No need for function definitions in dtrace backend
422 linetod_begin_dtrace()
432 name=$(get_name "$1")
433 args=$(get_args "$1")
435 # DTrace provider syntax expects foo() for empty
436 # params, not foo(void)
437 if [ "$args" = "void" ]; then
441 # Define prototype for probe arguments
454 linetostap_begin_dtrace()
461 local i arg name args arglist
462 name=$(get_name "$1")
463 args=$(get_args "$1")
464 arglist=$(get_argnames "$1", "")
466 # Define prototype for probe arguments
468 probe $probeprefix.$name = process("$binary").mark("$name")
475 # 'limit' is a reserved keyword
476 if [ "$arg" = "limit" ]; then
490 linetostap_end_dtrace()
495 # Process stdin by calling begin, line, and end functions for the backend
498 local begin process_line end str disable
499 begin="lineto$1_begin_$backend"
500 process_line="lineto$1_$backend"
501 end="lineto$1_end_$backend"
505 while read -r str; do
506 # Skip comments and empty lines
507 test -z "${str%%#*}" && continue
510 # Process the line. The nop backend handles disabled lines.
511 if has_property "$str" "disable"; then
512 "lineto$1_nop" "$str"
514 "$process_line" "$str"
528 /* This file is autogenerated by tracetool, do not edit. */
530 #include "qemu-common.h"
533 echo "#endif /* TRACE_H */"
538 echo "/* This file is autogenerated by tracetool, do not edit. */"
544 if [ $backend != "dtrace" ]; then
545 echo "DTrace probe generator not applicable to $backend backend"
548 echo "/* This file is autogenerated by tracetool, do not edit. */"
554 if [ $backend != "dtrace" ]; then
555 echo "SystemTAP tapset generator not applicable to $backend backend"
558 if [ -z "$binary" ]; then
559 echo "--binary is required for SystemTAP tapset generator"
562 if [ -z "$probeprefix" -a -z "$targettype" ]; then
563 echo "--target-type is required for SystemTAP tapset generator"
566 if [ -z "$probeprefix" -a -z "$targetarch" ]; then
567 echo "--target-arch is required for SystemTAP tapset generator"
570 if [ -z "$probeprefix" ]; then
571 probeprefix="qemu.$targettype.$targetarch";
573 echo "/* This file is autogenerated by tracetool, do not edit. */"
589 "--nop" | "--simple" | "--stderr" | "--ust" | "--dtrace") backend="${1#--}" ;;
591 "--binary") shift ; binary="$1" ;;
592 "--target-arch") shift ; targetarch="$1" ;;
593 "--target-type") shift ; targettype="$1" ;;
594 "--probe-prefix") shift ; probeprefix="$1" ;;
596 "-h" | "-c" | "-d") output="${1#-}" ;;
597 "--stap") output="${1#--}" ;;
599 "--check-backend") exit 0 ;; # used by ./configure to test for backend
601 "--list-backends") # used by ./configure to list available backends
602 echo "nop simple stderr ust dtrace"
612 if [ "$backend" = "" -o "$output" = "" ]; then