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')
41 # Get the name of a trace event
47 # Get the argument list of a trace event, including types and names
56 # Get the argument name list of a trace event
59 local nfields field name sep
62 for field
in $
(get_args
"$1"); do
63 nfields
=$
((nfields
+ 1))
68 # Only argument names have commas at the end
70 test "$field" = "$name" && continue
72 printf "%s%s " $name $sep
76 if [ "$nfields" -gt 1 ]
82 # Get the number of arguments to a trace event
87 for name
in $
(get_argnames
"$1", ","); do
93 # Get the format string for a trace event
102 # Get the state of a trace event
105 local str disable state
107 disable
=${str##disable }
108 if [ "$disable" = "$str" ] ; then
124 name
=$
(get_name
"$1")
125 args
=$
(get_args
"$1")
127 # Define an empty function for the trace event
129 static inline void trace_$name($args)
147 # No need for function definitions in nop backend
156 linetoh_begin_simple
()
159 #include "simpletrace.h"
165 cast_args_to_uint64_t
()
168 for arg
in $
(get_argnames
"$1", ","); do
169 printf "%s" "(uint64_t)(uintptr_t)$arg"
175 local name args argc trace_args state
176 name
=$
(get_name
"$1")
177 args
=$
(get_args
"$1")
178 argc
=$
(get_argc
"$1")
179 state
=$
(get_state
"$1")
180 if [ "$state" = "0" ]; then
181 name
=${name##disable }
184 trace_args
="$simple_event_num"
187 trace_args
="$trace_args, $(cast_args_to_uint64_t "$1")"
191 static inline void trace_$name($args)
193 trace$argc($trace_args);
197 simple_event_num
=$
((simple_event_num
+ 1))
203 #define NR_TRACE_EVENTS $simple_event_num
204 extern TraceEvent trace_list[NR_TRACE_EVENTS];
208 linetoc_begin_simple
()
213 TraceEvent trace_list[] = {
222 name
=$
(get_name
"$1")
223 state
=$
(get_state
"$1")
224 if [ "$state" = "0" ] ; then
225 name
=${name##disable }
228 {.tp_name = "$name", .state=$state},
230 simple_event_num
=$
((simple_event_num
+ 1))
241 linetoh_begin_stderr
()
250 local name args argnames argc
fmt
251 name
=$
(get_name
"$1")
252 args
=$
(get_args
"$1")
253 argnames
=$
(get_argnames
"$1" ",")
254 argc
=$
(get_argc
"$1")
257 if [ "$argc" -gt 0 ]; then
258 argnames
=", $argnames"
262 static inline void trace_$name($args)
264 fprintf(stderr, "$name $fmt\n" $argnames);
274 linetoc_begin_stderr
()
290 # Clean up after UST headers which pollute the namespace
291 ust_clean_namespace
() {
302 echo "#include <ust/tracepoint.h>"
308 local name args argnames
309 name
=$
(get_name
"$1")
310 args
=$
(get_args
"$1")
311 argnames
=$
(get_argnames
"$1", ",")
314 DECLARE_TRACE(ust_$name, TP_PROTO($args), TP_ARGS($argnames));
315 #define trace_$name trace_ust_$name
327 #include <ust/marker.h>
328 $(ust_clean_namespace)
335 local name args argnames
fmt
336 name
=$
(get_name
"$1")
337 args
=$
(get_args
"$1")
338 argnames
=$
(get_argnames
"$1", ",")
342 DEFINE_TRACE(ust_$name);
344 static void ust_${name}_probe($args)
346 trace_mark(ust, $name, "$fmt", $argnames);
350 # Collect names for later
357 static void __attribute__((constructor)) trace_init(void)
361 for name
in $names; do
363 register_trace_ust_$name(ust_${name}_probe);
370 linetoh_begin_dtrace
()
373 #include "trace-dtrace.h"
379 local name args argnames state nameupper
380 name
=$
(get_name
"$1")
381 args
=$
(get_args
"$1")
382 argnames
=$
(get_argnames
"$1", ",")
383 state
=$
(get_state
"$1")
384 if [ "$state" = "0" ] ; then
385 name
=${name##disable }
388 nameupper
=`echo $name | tr '[:lower:]' '[:upper:]'`
390 # Define an empty function for the trace event
392 static inline void trace_$name($args) {
393 if (QEMU_${nameupper}_ENABLED()) {
394 QEMU_${nameupper}($argnames);
405 linetoc_begin_dtrace
()
412 # No need for function definitions in dtrace backend
421 linetod_begin_dtrace
()
430 local name args state
431 name
=$
(get_name
"$1")
432 args
=$
(get_args
"$1")
433 state
=$
(get_state
"$1")
434 if [ "$state" = "0" ] ; then
435 name
=${name##disable }
438 # DTrace provider syntax expects foo() for empty
439 # params, not foo(void)
440 if [ "$args" = "void" ]; then
444 # Define prototype for probe arguments
457 linetostap_begin_dtrace
()
464 local i arg name args arglist state
465 name
=$
(get_name
"$1")
466 args
=$
(get_args
"$1")
467 arglist
=$
(get_argnames
"$1", "")
468 state
=$
(get_state
"$1")
469 if [ "$state" = "0" ] ; then
470 name
=${name##disable }
473 # Define prototype for probe arguments
475 probe qemu.$targettype.$targetarch.$name = process("$binary").mark("$name")
482 # 'limit' is a reserved keyword
483 if [ "$arg" = "limit" ]; then
497 linetostap_end_dtrace
()
502 # Process stdin by calling begin, line, and end functions for the backend
505 local begin process_line end str disable
506 begin
="lineto$1_begin_$backend"
507 process_line
="lineto$1_$backend"
508 end
="lineto$1_end_$backend"
512 while read -r str
; do
513 # Skip comments and empty lines
514 test -z "${str%%#*}" && continue
516 # Process the line. The nop backend handles disabled lines.
517 disable
=${str%%disable *}
519 if test -z "$disable"; then
520 # Pass the disabled state as an arg for the simple
521 # or DTrace backends which handle it dynamically.
522 # For all other backends, call lineto$1_nop()
523 if [ $backend = "simple" -o "$backend" = "dtrace" ]; then
524 "$process_line" "$str"
526 "lineto$1_nop" "${str##disable }"
529 "$process_line" "$str"
543 /* This file is autogenerated by tracetool, do not edit. */
545 #include "qemu-common.h"
548 echo "#endif /* TRACE_H */"
553 echo "/* This file is autogenerated by tracetool, do not edit. */"
559 if [ $backend != "dtrace" ]; then
560 echo "DTrace probe generator not applicable to $backend backend"
563 echo "/* This file is autogenerated by tracetool, do not edit. */"
569 if [ $backend != "dtrace" ]; then
570 echo "SystemTAP tapset generator not applicable to $backend backend"
573 if [ -z "$binary" ]; then
574 echo "--binary is required for SystemTAP tapset generator"
577 if [ -z "$targettype" ]; then
578 echo "--target-type is required for SystemTAP tapset generator"
581 if [ -z "$targetarch" ]; then
582 echo "--target-arch is required for SystemTAP tapset generator"
585 echo "/* This file is autogenerated by tracetool, do not edit. */"
600 "--nop" |
"--simple" |
"--stderr" |
"--ust" |
"--dtrace") backend
="${1#--}" ;;
602 "--binary") shift ; binary
="$1" ;;
603 "--target-arch") shift ; targetarch
="$1" ;;
604 "--target-type") shift ; targettype
="$1" ;;
606 "-h" |
"-c" |
"-d") output
="${1#-}" ;;
607 "--stap") output
="${1#--}" ;;
609 "--check-backend") exit 0 ;; # used by ./configure to test for backend
611 "--list-backends") # used by ./configure to list available backends
612 echo "nop simple stderr ust dtrace"
622 if [ "$backend" = "" -o "$output" = "" ]; then