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
49 # Get the argument list of a trace event, including types and names
58 # Get the argument name list of a trace event
61 local nfields field name sep
64 for field
in $
(get_args
"$1"); do
65 nfields
=$
((nfields
+ 1))
70 # Only argument names have commas at the end
72 test "$field" = "$name" && continue
74 printf "%s%s " $name $sep
78 if [ "$nfields" -gt 1 ]
84 # Get the number of arguments to a trace event
89 for name
in $
(get_argnames
"$1", ","); do
95 # Get the format string for a trace event
104 # Get the state of a trace event
107 local str disable state
109 disable
=${str##disable }
110 if [ "$disable" = "$str" ] ; then
126 name
=$
(get_name
"$1")
127 args
=$
(get_args
"$1")
129 # Define an empty function for the trace event
131 static inline void trace_$name($args)
149 # No need for function definitions in nop backend
158 linetoh_begin_simple
()
161 #include "simpletrace.h"
167 cast_args_to_uint64_t
()
170 for arg
in $
(get_argnames
"$1", ","); do
171 printf "%s" "(uint64_t)(uintptr_t)$arg"
177 local name args argc trace_args state
178 name
=$
(get_name
"$1")
179 args
=$
(get_args
"$1")
180 argc
=$
(get_argc
"$1")
181 state
=$
(get_state
"$1")
182 if [ "$state" = "0" ]; then
183 name
=${name##disable }
186 trace_args
="$simple_event_num"
189 trace_args
="$trace_args, $(cast_args_to_uint64_t "$1")"
193 static inline void trace_$name($args)
195 trace$argc($trace_args);
199 simple_event_num
=$
((simple_event_num
+ 1))
205 #define NR_TRACE_EVENTS $simple_event_num
206 extern TraceEvent trace_list[NR_TRACE_EVENTS];
210 linetoc_begin_simple
()
215 TraceEvent trace_list[] = {
224 name
=$
(get_name
"$1")
225 state
=$
(get_state
"$1")
226 if [ "$state" = "0" ] ; then
227 name
=${name##disable }
230 {.tp_name = "$name", .state=$state},
232 simple_event_num
=$
((simple_event_num
+ 1))
243 linetoh_begin_stderr
()
252 local name args argnames argc
fmt
253 name
=$
(get_name
"$1")
254 args
=$
(get_args
"$1")
255 argnames
=$
(get_argnames
"$1" ",")
256 argc
=$
(get_argc
"$1")
259 if [ "$argc" -gt 0 ]; then
260 argnames
=", $argnames"
264 static inline void trace_$name($args)
266 fprintf(stderr, "$name $fmt\n" $argnames);
276 linetoc_begin_stderr
()
292 # Clean up after UST headers which pollute the namespace
293 ust_clean_namespace
() {
304 echo "#include <ust/tracepoint.h>"
310 local name args argnames
311 name
=$
(get_name
"$1")
312 args
=$
(get_args
"$1")
313 argnames
=$
(get_argnames
"$1", ",")
316 DECLARE_TRACE(ust_$name, TP_PROTO($args), TP_ARGS($argnames));
317 #define trace_$name trace_ust_$name
329 #include <ust/marker.h>
330 $(ust_clean_namespace)
337 local name args argnames
fmt
338 name
=$
(get_name
"$1")
339 args
=$
(get_args
"$1")
340 argnames
=$
(get_argnames
"$1", ",")
344 DEFINE_TRACE(ust_$name);
346 static void ust_${name}_probe($args)
348 trace_mark(ust, $name, "$fmt", $argnames);
352 # Collect names for later
359 static void __attribute__((constructor)) trace_init(void)
363 for name
in $names; do
365 register_trace_ust_$name(ust_${name}_probe);
372 linetoh_begin_dtrace
()
375 #include "trace-dtrace.h"
381 local name args argnames state nameupper
382 name
=$
(get_name
"$1")
383 args
=$
(get_args
"$1")
384 argnames
=$
(get_argnames
"$1", ",")
385 state
=$
(get_state
"$1")
386 if [ "$state" = "0" ] ; then
387 name
=${name##disable }
390 nameupper
=`echo $name | tr '[:lower:]' '[:upper:]'`
392 # Define an empty function for the trace event
394 static inline void trace_$name($args) {
395 if (QEMU_${nameupper}_ENABLED()) {
396 QEMU_${nameupper}($argnames);
407 linetoc_begin_dtrace
()
414 # No need for function definitions in dtrace backend
423 linetod_begin_dtrace
()
432 local name args state
433 name
=$
(get_name
"$1")
434 args
=$
(get_args
"$1")
435 state
=$
(get_state
"$1")
436 if [ "$state" = "0" ] ; then
437 name
=${name##disable }
440 # DTrace provider syntax expects foo() for empty
441 # params, not foo(void)
442 if [ "$args" = "void" ]; then
446 # Define prototype for probe arguments
459 linetostap_begin_dtrace
()
466 local i arg name args arglist state
467 name
=$
(get_name
"$1")
468 args
=$
(get_args
"$1")
469 arglist
=$
(get_argnames
"$1", "")
470 state
=$
(get_state
"$1")
471 if [ "$state" = "0" ] ; then
472 name
=${name##disable }
475 # Define prototype for probe arguments
477 probe $probeprefix.$name = process("$binary").mark("$name")
484 # 'limit' is a reserved keyword
485 if [ "$arg" = "limit" ]; then
499 linetostap_end_dtrace
()
504 # Process stdin by calling begin, line, and end functions for the backend
507 local begin process_line end str disable
508 begin
="lineto$1_begin_$backend"
509 process_line
="lineto$1_$backend"
510 end
="lineto$1_end_$backend"
514 while read -r str
; do
515 # Skip comments and empty lines
516 test -z "${str%%#*}" && continue
518 # Process the line. The nop backend handles disabled lines.
519 disable
=${str%%disable *}
521 if test -z "$disable"; then
522 # Pass the disabled state as an arg for the simple
523 # or DTrace backends which handle it dynamically.
524 # For all other backends, call lineto$1_nop()
525 if [ $backend = "simple" -o "$backend" = "dtrace" ]; then
526 "$process_line" "$str"
528 "lineto$1_nop" "${str##disable }"
531 "$process_line" "$str"
545 /* This file is autogenerated by tracetool, do not edit. */
547 #include "qemu-common.h"
550 echo "#endif /* TRACE_H */"
555 echo "/* This file is autogenerated by tracetool, do not edit. */"
561 if [ $backend != "dtrace" ]; then
562 echo "DTrace probe generator not applicable to $backend backend"
565 echo "/* This file is autogenerated by tracetool, do not edit. */"
571 if [ $backend != "dtrace" ]; then
572 echo "SystemTAP tapset generator not applicable to $backend backend"
575 if [ -z "$binary" ]; then
576 echo "--binary is required for SystemTAP tapset generator"
579 if [ -z "$probeprefix" -a -z "$targettype" ]; then
580 echo "--target-type is required for SystemTAP tapset generator"
583 if [ -z "$probeprefix" -a -z "$targetarch" ]; then
584 echo "--target-arch is required for SystemTAP tapset generator"
587 if [ -z "$probeprefix" ]; then
588 probeprefix
="qemu.$targettype.$targetarch";
590 echo "/* This file is autogenerated by tracetool, do not edit. */"
606 "--nop" |
"--simple" |
"--stderr" |
"--ust" |
"--dtrace") backend
="${1#--}" ;;
608 "--binary") shift ; binary
="$1" ;;
609 "--target-arch") shift ; targetarch
="$1" ;;
610 "--target-type") shift ; targettype
="$1" ;;
611 "--probe-prefix") shift ; probeprefix
="$1" ;;
613 "-h" |
"-c" |
"-d") output
="${1#-}" ;;
614 "--stap") output
="${1#--}" ;;
616 "--check-backend") exit 0 ;; # used by ./configure to test for backend
618 "--list-backends") # used by ./configure to list available backends
619 echo "nop simple stderr ust dtrace"
629 if [ "$backend" = "" -o "$output" = "" ]; then