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 # Print a line without interpreting backslash escapes
45 # The built-in echo command may interpret backslash escapes without an option
46 # to disable this behavior.
52 # Get the name of a trace event
60 # Get the given property of a trace event
61 # 1: trace-events line
63 # -> return 0 if property is present, or 1 otherwise
69 for prop
in $props; do
70 if [ "$prop" = "$2" ]; then
77 # Get the argument list of a trace event, including types and names
86 # Get the argument name list of a trace event
89 local nfields field name sep
92 for field
in $
(get_args
"$1"); do
93 nfields
=$
((nfields
+ 1))
98 # Only argument names have commas at the end
100 test "$field" = "$name" && continue
102 printf "%s%s " $name $sep
106 if [ "$nfields" -gt 1 ]
112 # Get the number of arguments to a trace event
117 for name
in $
(get_argnames
"$1", ","); do
123 # Get the format string including double quotes for a trace event
137 name
=$
(get_name
"$1")
138 args
=$
(get_args
"$1")
140 # Define an empty function for the trace event
142 static inline void trace_$name($args)
160 # No need for function definitions in nop backend
166 # Used when "disabled" events are processed
172 # Used when "disabled" events are processed
181 linetoh_begin_simple
()
184 #include "trace/simple.h"
190 cast_args_to_uint64_t
()
193 for arg
in $
(get_argnames
"$1", ","); do
194 printf "%s" "(uint64_t)(uintptr_t)$arg"
200 local name args argc trace_args
201 name
=$
(get_name
"$1")
202 args
=$
(get_args
"$1")
203 argc
=$
(get_argc
"$1")
205 trace_args
="$simple_event_num"
208 trace_args
="$trace_args, $(cast_args_to_uint64_t "$1")"
212 static inline void trace_$name($args)
214 trace$argc($trace_args);
218 simple_event_num
=$
((simple_event_num
+ 1))
224 #define NR_TRACE_EVENTS $simple_event_num
225 extern TraceEvent trace_list[NR_TRACE_EVENTS];
229 linetoc_begin_simple
()
234 TraceEvent trace_list[] = {
243 name
=$
(get_name
"$1")
245 {.tp_name = "$name", .state=0},
247 simple_event_num
=$
((simple_event_num
+ 1))
258 linetoh_begin_stderr
()
262 #include "trace/stderr.h"
264 extern TraceEvent trace_list[];
272 local name args argnames argc
fmt
273 name
=$
(get_name
"$1")
274 args
=$
(get_args
"$1")
275 argnames
=$
(get_argnames
"$1" ",")
276 argc
=$
(get_argc
"$1")
279 if [ "$argc" -gt 0 ]; then
280 argnames
=", $argnames"
284 static inline void trace_$name($args)
286 if (trace_list[$stderr_event_num].state != 0) {
287 fprintf(stderr, "$name " $fmt "\n" $argnames);
291 stderr_event_num
=$
((stderr_event_num
+ 1))
298 #define NR_TRACE_EVENTS $stderr_event_num
302 linetoc_begin_stderr
()
307 TraceEvent trace_list[] = {
315 name
=$
(get_name
"$1")
317 {.tp_name = "$name", .state=0},
319 stderr_event_num
=$
(($stderr_event_num + 1))
330 # Clean up after UST headers which pollute the namespace
331 ust_clean_namespace
() {
342 echo "#include <ust/tracepoint.h>"
348 local name args argnames
349 name
=$
(get_name
"$1")
350 args
=$
(get_args
"$1")
351 argnames
=$
(get_argnames
"$1", ",")
354 DECLARE_TRACE(ust_$name, TP_PROTO($args), TP_ARGS($argnames));
355 #define trace_$name trace_ust_$name
367 #include <ust/marker.h>
368 $(ust_clean_namespace)
375 local name args argnames
fmt
376 name
=$
(get_name
"$1")
377 args
=$
(get_args
"$1")
378 argnames
=$
(get_argnames
"$1", ",")
379 [ -z "$argnames" ] || argnames
=", $argnames"
383 DEFINE_TRACE(ust_$name);
385 static void ust_${name}_probe($args)
387 trace_mark(ust, $name, $fmt$argnames);
391 # Collect names for later
398 static void __attribute__((constructor)) trace_init(void)
402 for name
in $names; do
404 register_trace_ust_$name(ust_${name}_probe);
411 linetoh_begin_dtrace
()
414 #include "trace-dtrace.h"
420 local name args argnames nameupper
421 name
=$
(get_name
"$1")
422 args
=$
(get_args
"$1")
423 argnames
=$
(get_argnames
"$1", ",")
425 nameupper
=`echo $name | tr '[:lower:]' '[:upper:]'`
427 # Define an empty function for the trace event
429 static inline void trace_$name($args) {
430 QEMU_${nameupper}($argnames);
440 linetoc_begin_dtrace
()
447 # No need for function definitions in dtrace backend
456 linetod_begin_dtrace
()
466 name
=$
(get_name
"$1")
467 args
=$
(get_args
"$1")
469 # DTrace provider syntax expects foo() for empty
470 # params, not foo(void)
471 if [ "$args" = "void" ]; then
475 # Define prototype for probe arguments
488 linetostap_begin_dtrace
()
495 local i arg name args arglist
496 name
=$
(get_name
"$1")
497 args
=$
(get_args
"$1")
498 arglist
=$
(get_argnames
"$1", "")
500 # Define prototype for probe arguments
502 probe $probeprefix.$name = process("$binary").mark("$name")
509 # postfix reserved words with '_'
526 linetostap_end_dtrace
()
531 # Process stdin by calling begin, line, and end functions for the backend
534 local begin process_line end str name NAME enabled
535 begin
="lineto$1_begin_$backend"
536 process_line
="lineto$1_$backend"
537 end
="lineto$1_end_$backend"
541 while read -r str
; do
542 # Skip comments and empty lines
543 test -z "${str%%#*}" && continue
546 # Process the line. The nop backend handles disabled lines.
547 if has_property
"$str" "disable"; then
548 "lineto$1_nop" "$str"
551 "$process_line" "$str"
554 if [ "$1" = "h" ]; then
555 name
=$
(get_name
"$str")
556 NAME
=$
(echo $name |
tr '[:lower:]' '[:upper:]')
557 echo "#define TRACE_${NAME}_ENABLED ${enabled}"
571 /* This file is autogenerated by tracetool, do not edit. */
573 #include "qemu-common.h"
576 echo "#endif /* TRACE_H */"
581 echo "/* This file is autogenerated by tracetool, do not edit. */"
587 if [ $backend != "dtrace" ]; then
588 echo "DTrace probe generator not applicable to $backend backend"
591 echo "/* This file is autogenerated by tracetool, do not edit. */"
597 if [ $backend != "dtrace" ]; then
598 echo "SystemTAP tapset generator not applicable to $backend backend"
601 if [ -z "$binary" ]; then
602 echo "--binary is required for SystemTAP tapset generator"
605 if [ -z "$probeprefix" -a -z "$targettype" ]; then
606 echo "--target-type is required for SystemTAP tapset generator"
609 if [ -z "$probeprefix" -a -z "$targetarch" ]; then
610 echo "--target-arch is required for SystemTAP tapset generator"
613 if [ -z "$probeprefix" ]; then
614 probeprefix
="qemu.$targettype.$targetarch";
616 echo "/* This file is autogenerated by tracetool, do not edit. */"
632 "--nop" |
"--simple" |
"--stderr" |
"--ust" |
"--dtrace") backend
="${1#--}" ;;
634 "--binary") shift ; binary
="$1" ;;
635 "--target-arch") shift ; targetarch
="$1" ;;
636 "--target-type") shift ; targettype
="$1" ;;
637 "--probe-prefix") shift ; probeprefix
="$1" ;;
639 "-h" |
"-c" |
"-d") output
="${1#-}" ;;
640 "--stap") output
="${1#--}" ;;
642 "--check-backend") exit 0 ;; # used by ./configure to test for backend
644 "--list-backends") # used by ./configure to list available backends
645 echo "nop simple stderr ust dtrace"
655 if [ "$backend" = "" -o "$output" = "" ]; then