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")
227 {.tp_name = "$name", .state=0},
229 simple_event_num
=$
((simple_event_num
+ 1))
240 linetoh_begin_stderr
()
244 #include "trace/stderr.h"
246 extern TraceEvent trace_list[];
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 if (trace_list[$stderr_event_num].state != 0) {
269 fprintf(stderr, "$name $fmt\n" $argnames);
273 stderr_event_num
=$
((stderr_event_num
+ 1))
280 #define NR_TRACE_EVENTS $stderr_event_num
284 linetoc_begin_stderr
()
289 TraceEvent trace_list[] = {
297 name
=$
(get_name
"$1")
299 {.tp_name = "$name", .state=0},
301 stderr_event_num
=$
(($stderr_event_num + 1))
312 # Clean up after UST headers which pollute the namespace
313 ust_clean_namespace
() {
324 echo "#include <ust/tracepoint.h>"
330 local name args argnames
331 name
=$
(get_name
"$1")
332 args
=$
(get_args
"$1")
333 argnames
=$
(get_argnames
"$1", ",")
336 DECLARE_TRACE(ust_$name, TP_PROTO($args), TP_ARGS($argnames));
337 #define trace_$name trace_ust_$name
349 #include <ust/marker.h>
350 $(ust_clean_namespace)
357 local name args argnames
fmt
358 name
=$
(get_name
"$1")
359 args
=$
(get_args
"$1")
360 argnames
=$
(get_argnames
"$1", ",")
361 [ -z "$argnames" ] || argnames
=", $argnames"
365 DEFINE_TRACE(ust_$name);
367 static void ust_${name}_probe($args)
369 trace_mark(ust, $name, "$fmt"$argnames);
373 # Collect names for later
380 static void __attribute__((constructor)) trace_init(void)
384 for name
in $names; do
386 register_trace_ust_$name(ust_${name}_probe);
393 linetoh_begin_dtrace
()
396 #include "trace-dtrace.h"
402 local name args argnames nameupper
403 name
=$
(get_name
"$1")
404 args
=$
(get_args
"$1")
405 argnames
=$
(get_argnames
"$1", ",")
407 nameupper
=`echo $name | tr '[:lower:]' '[:upper:]'`
409 # Define an empty function for the trace event
411 static inline void trace_$name($args) {
412 if (QEMU_${nameupper}_ENABLED()) {
413 QEMU_${nameupper}($argnames);
424 linetoc_begin_dtrace
()
431 # No need for function definitions in dtrace backend
440 linetod_begin_dtrace
()
450 name
=$
(get_name
"$1")
451 args
=$
(get_args
"$1")
453 # DTrace provider syntax expects foo() for empty
454 # params, not foo(void)
455 if [ "$args" = "void" ]; then
459 # Define prototype for probe arguments
472 linetostap_begin_dtrace
()
479 local i arg name args arglist
480 name
=$
(get_name
"$1")
481 args
=$
(get_args
"$1")
482 arglist
=$
(get_argnames
"$1", "")
484 # Define prototype for probe arguments
486 probe $probeprefix.$name = process("$binary").mark("$name")
493 # 'limit' is a reserved keyword
494 if [ "$arg" = "limit" ]; then
508 linetostap_end_dtrace
()
513 # Process stdin by calling begin, line, and end functions for the backend
516 local begin process_line end str disable
517 begin
="lineto$1_begin_$backend"
518 process_line
="lineto$1_$backend"
519 end
="lineto$1_end_$backend"
523 while read -r str
; do
524 # Skip comments and empty lines
525 test -z "${str%%#*}" && continue
528 # Process the line. The nop backend handles disabled lines.
529 if has_property
"$str" "disable"; then
530 "lineto$1_nop" "$str"
532 "$process_line" "$str"
546 /* This file is autogenerated by tracetool, do not edit. */
548 #include "qemu-common.h"
551 echo "#endif /* TRACE_H */"
556 echo "/* This file is autogenerated by tracetool, do not edit. */"
562 if [ $backend != "dtrace" ]; then
563 echo "DTrace probe generator not applicable to $backend backend"
566 echo "/* This file is autogenerated by tracetool, do not edit. */"
572 if [ $backend != "dtrace" ]; then
573 echo "SystemTAP tapset generator not applicable to $backend backend"
576 if [ -z "$binary" ]; then
577 echo "--binary is required for SystemTAP tapset generator"
580 if [ -z "$probeprefix" -a -z "$targettype" ]; then
581 echo "--target-type is required for SystemTAP tapset generator"
584 if [ -z "$probeprefix" -a -z "$targetarch" ]; then
585 echo "--target-arch is required for SystemTAP tapset generator"
588 if [ -z "$probeprefix" ]; then
589 probeprefix
="qemu.$targettype.$targetarch";
591 echo "/* This file is autogenerated by tracetool, do not edit. */"
607 "--nop" |
"--simple" |
"--stderr" |
"--ust" |
"--dtrace") backend
="${1#--}" ;;
609 "--binary") shift ; binary
="$1" ;;
610 "--target-arch") shift ; targetarch
="$1" ;;
611 "--target-type") shift ; targettype
="$1" ;;
612 "--probe-prefix") shift ; probeprefix
="$1" ;;
614 "-h" |
"-c" |
"-d") output
="${1#-}" ;;
615 "--stap") output
="${1#--}" ;;
617 "--check-backend") exit 0 ;; # used by ./configure to test for backend
619 "--list-backends") # used by ./configure to list available backends
620 echo "nop simple stderr ust dtrace"
630 if [ "$backend" = "" -o "$output" = "" ]; then