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 | --ust] [-h | -c]
17 Generate tracing code for a file on stdin.
20 --nop Tracing disabled
21 --simple Simple built-in backend
22 --ust LTTng User Space Tracing backend
23 --dtrace DTrace/SystemTAP backend
28 -d Generate .d file (DTrace only)
29 --stap Generate .stp file (DTrace with SystemTAP only)
32 --binary [path] Full path to QEMU binary
33 --target-arch [arch] QEMU emulator target arch
34 --target-type [type] QEMU emulator target type ('system' or 'user')
40 # Get the name of a trace event
46 # Get the argument list of a trace event, including types and names
55 # Get the argument name list of a trace event
58 local nfields field name sep
61 for field
in $
(get_args
"$1"); do
62 nfields
=$
((nfields
+ 1))
67 # Only argument names have commas at the end
69 test "$field" = "$name" && continue
71 printf "%s%s " $name $sep
75 if [ "$nfields" -gt 1 ]
81 # Get the number of arguments to a trace event
86 for name
in $
(get_argnames
"$1", ","); do
92 # Get the format string for a trace event
101 # Get the state of a trace event
104 local str disable state
106 disable
=${str##disable }
107 if [ "$disable" = "$str" ] ; then
123 name
=$
(get_name
"$1")
124 args
=$
(get_args
"$1")
126 # Define an empty function for the trace event
128 static inline void trace_$name($args)
146 # No need for function definitions in nop backend
155 linetoh_begin_simple
()
158 #include "simpletrace.h"
164 cast_args_to_uint64_t
()
167 for arg
in $
(get_argnames
"$1", ","); do
168 printf "%s" "(uint64_t)(uintptr_t)$arg"
174 local name args argc trace_args state
175 name
=$
(get_name
"$1")
176 args
=$
(get_args
"$1")
177 argc
=$
(get_argc
"$1")
178 state
=$
(get_state
"$1")
179 if [ "$state" = "0" ]; then
180 name
=${name##disable }
183 trace_args
="$simple_event_num"
186 trace_args
="$trace_args, $(cast_args_to_uint64_t "$1")"
190 static inline void trace_$name($args)
192 trace$argc($trace_args);
196 simple_event_num
=$
((simple_event_num
+ 1))
202 #define NR_TRACE_EVENTS $simple_event_num
203 extern TraceEvent trace_list[NR_TRACE_EVENTS];
207 linetoc_begin_simple
()
212 TraceEvent trace_list[] = {
221 name
=$
(get_name
"$1")
222 state
=$
(get_state
"$1")
223 if [ "$state" = "0" ] ; then
224 name
=${name##disable }
227 {.tp_name = "$name", .state=$state},
229 simple_event_num
=$
((simple_event_num
+ 1))
239 # Clean up after UST headers which pollute the namespace
240 ust_clean_namespace
() {
251 echo "#include <ust/tracepoint.h>"
257 local name args argnames
258 name
=$
(get_name
"$1")
259 args
=$
(get_args
"$1")
260 argnames
=$
(get_argnames
"$1", ",")
263 DECLARE_TRACE(ust_$name, TP_PROTO($args), TP_ARGS($argnames));
264 #define trace_$name trace_ust_$name
276 #include <ust/marker.h>
277 $(ust_clean_namespace)
284 local name args argnames
fmt
285 name
=$
(get_name
"$1")
286 args
=$
(get_args
"$1")
287 argnames
=$
(get_argnames
"$1", ",")
291 DEFINE_TRACE(ust_$name);
293 static void ust_${name}_probe($args)
295 trace_mark(ust, $name, "$fmt", $argnames);
299 # Collect names for later
306 static void __attribute__((constructor)) trace_init(void)
310 for name
in $names; do
312 register_trace_ust_$name(ust_${name}_probe);
319 linetoh_begin_dtrace
()
322 #include "trace-dtrace.h"
328 local name args argnames state nameupper
329 name
=$
(get_name
"$1")
330 args
=$
(get_args
"$1")
331 argnames
=$
(get_argnames
"$1", ",")
332 state
=$
(get_state
"$1")
333 if [ "$state" = "0" ] ; then
334 name
=${name##disable }
337 nameupper
=`echo $name | tr '[:lower:]' '[:upper:]'`
339 # Define an empty function for the trace event
341 static inline void trace_$name($args) {
342 if (QEMU_${nameupper}_ENABLED()) {
343 QEMU_${nameupper}($argnames);
354 linetoc_begin_dtrace
()
361 # No need for function definitions in dtrace backend
370 linetod_begin_dtrace
()
379 local name args state
380 name
=$
(get_name
"$1")
381 args
=$
(get_args
"$1")
382 state
=$
(get_state
"$1")
383 if [ "$state" = "0" ] ; then
384 name
=${name##disable }
387 # DTrace provider syntax expects foo() for empty
388 # params, not foo(void)
389 if [ "$args" = "void" ]; then
393 # Define prototype for probe arguments
406 linetostap_begin_dtrace
()
413 local i arg name args arglist state
414 name
=$
(get_name
"$1")
415 args
=$
(get_args
"$1")
416 arglist
=$
(get_argnames
"$1", "")
417 state
=$
(get_state
"$1")
418 if [ "$state" = "0" ] ; then
419 name
=${name##disable }
422 # Define prototype for probe arguments
424 probe qemu.$targettype.$targetarch.$name = process("$binary").mark("$name")
431 # 'limit' is a reserved keyword
432 if [ "$arg" = "limit" ]; then
446 linetostap_end_dtrace
()
451 # Process stdin by calling begin, line, and end functions for the backend
454 local begin process_line end str disable
455 begin
="lineto$1_begin_$backend"
456 process_line
="lineto$1_$backend"
457 end
="lineto$1_end_$backend"
461 while read -r str
; do
462 # Skip comments and empty lines
463 test -z "${str%%#*}" && continue
465 # Process the line. The nop backend handles disabled lines.
466 disable
=${str%%disable *}
468 if test -z "$disable"; then
469 # Pass the disabled state as an arg for the simple
470 # or DTrace backends which handle it dynamically.
471 # For all other backends, call lineto$1_nop()
472 if [ $backend = "simple" -o "$backend" = "dtrace" ]; then
473 "$process_line" "$str"
475 "lineto$1_nop" "${str##disable }"
478 "$process_line" "$str"
492 /* This file is autogenerated by tracetool, do not edit. */
494 #include "qemu-common.h"
497 echo "#endif /* TRACE_H */"
502 echo "/* This file is autogenerated by tracetool, do not edit. */"
508 if [ $backend != "dtrace" ]; then
509 echo "DTrace probe generator not applicable to $backend backend"
512 echo "/* This file is autogenerated by tracetool, do not edit. */"
518 if [ $backend != "dtrace" ]; then
519 echo "SystemTAP tapset generator not applicable to $backend backend"
522 if [ -z "$binary" ]; then
523 echo "--binary is required for SystemTAP tapset generator"
526 if [ -z "$targettype" ]; then
527 echo "--target-type is required for SystemTAP tapset generator"
530 if [ -z "$targetarch" ]; then
531 echo "--target-arch is required for SystemTAP tapset generator"
534 echo "/* This file is autogenerated by tracetool, do not edit. */"
549 "--nop" |
"--simple" |
"--ust" |
"--dtrace") backend
="${1#--}" ;;
551 "--binary") shift ; binary
="$1" ;;
552 "--target-arch") shift ; targetarch
="$1" ;;
553 "--target-type") shift ; targettype
="$1" ;;
555 "-h" |
"-c" |
"-d") output
="${1#-}" ;;
556 "--stap") output
="${1#--}" ;;
558 "--check-backend") exit 0 ;; # used by ./configure to test for backend
566 if [ "$backend" = "" -o "$output" = "" ]; then