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 -s Generate .stp file (DTrace with SystemTAP only)
32 --bindir [bindir] QEMU binary install location
33 --target [arch] QEMU target architecture
39 # Get the name of a trace event
45 # Get the argument list of a trace event, including types and names
54 # Get the argument name list of a trace event
57 local nfields field name sep
60 for field
in $
(get_args
"$1"); do
61 nfields
=$
((nfields
+ 1))
66 # Only argument names have commas at the end
68 test "$field" = "$name" && continue
70 printf "%s%s " $name $sep
74 if [ "$nfields" -gt 1 ]
80 # Get the number of arguments to a trace event
85 for name
in $
(get_argnames
"$1", ","); do
91 # Get the format string for a trace event
100 # Get the state of a trace event
103 local str disable state
105 disable
=${str##disable }
106 if [ "$disable" = "$str" ] ; then
122 name
=$
(get_name
"$1")
123 args
=$
(get_args
"$1")
125 # Define an empty function for the trace event
127 static inline void trace_$name($args)
145 # No need for function definitions in nop backend
154 linetoh_begin_simple
()
157 #include "simpletrace.h"
163 cast_args_to_uint64_t
()
166 for arg
in $
(get_argnames
"$1", ","); do
167 printf "%s" "(uint64_t)(uintptr_t)$arg"
173 local name args argc trace_args state
174 name
=$
(get_name
"$1")
175 args
=$
(get_args
"$1")
176 argc
=$
(get_argc
"$1")
177 state
=$
(get_state
"$1")
178 if [ "$state" = "0" ]; then
179 name
=${name##disable }
182 trace_args
="$simple_event_num"
185 trace_args
="$trace_args, $(cast_args_to_uint64_t "$1")"
189 static inline void trace_$name($args)
191 trace$argc($trace_args);
195 simple_event_num
=$
((simple_event_num
+ 1))
201 #define NR_TRACE_EVENTS $simple_event_num
202 extern TraceEvent trace_list[NR_TRACE_EVENTS];
206 linetoc_begin_simple
()
211 TraceEvent trace_list[] = {
220 name
=$
(get_name
"$1")
221 state
=$
(get_state
"$1")
222 if [ "$state" = "0" ] ; then
223 name
=${name##disable }
226 {.tp_name = "$name", .state=$state},
228 simple_event_num
=$
((simple_event_num
+ 1))
238 # Clean up after UST headers which pollute the namespace
239 ust_clean_namespace
() {
250 echo "#include <ust/tracepoint.h>"
256 local name args argnames
257 name
=$
(get_name
"$1")
258 args
=$
(get_args
"$1")
259 argnames
=$
(get_argnames
"$1", ",")
262 DECLARE_TRACE(ust_$name, TP_PROTO($args), TP_ARGS($argnames));
263 #define trace_$name trace_ust_$name
275 #include <ust/marker.h>
276 $(ust_clean_namespace)
283 local name args argnames
fmt
284 name
=$
(get_name
"$1")
285 args
=$
(get_args
"$1")
286 argnames
=$
(get_argnames
"$1", ",")
290 DEFINE_TRACE(ust_$name);
292 static void ust_${name}_probe($args)
294 trace_mark(ust, $name, "$fmt", $argnames);
298 # Collect names for later
305 static void __attribute__((constructor)) trace_init(void)
309 for name
in $names; do
311 register_trace_ust_$name(ust_${name}_probe);
318 linetoh_begin_dtrace
()
321 #include "trace-dtrace.h"
327 local name args argnames state nameupper
328 name
=$
(get_name
"$1")
329 args
=$
(get_args
"$1")
330 argnames
=$
(get_argnames
"$1", ",")
331 state
=$
(get_state
"$1")
332 if [ "$state" = "0" ] ; then
333 name
=${name##disable }
336 nameupper
=`echo $name | tr '[:lower:]' '[:upper:]'`
338 # Define an empty function for the trace event
340 static inline void trace_$name($args) {
341 if (QEMU_${nameupper}_ENABLED()) {
342 QEMU_${nameupper}($argnames);
353 linetoc_begin_dtrace
()
360 # No need for function definitions in dtrace backend
369 linetod_begin_dtrace
()
378 local name args state
379 name
=$
(get_name
"$1")
380 args
=$
(get_args
"$1")
381 state
=$
(get_state
"$1")
382 if [ "$state" = "0" ] ; then
383 name
=${name##disable }
386 # Define prototype for probe arguments
399 linetos_begin_dtrace
()
406 local name args arglist state
407 name
=$
(get_name
"$1")
408 args
=$
(get_args
"$1")
409 arglist
=$
(get_argnames
"$1", "")
410 state
=$
(get_state
"$1")
411 if [ "$state" = "0" ] ; then
412 name
=${name##disable }
415 if [ "$target" = "i386" ]
419 binary
="qemu-system-$target"
422 # Define prototype for probe arguments
424 probe qemu.system.$target.$name = process("$bindir/$binary").mark("$name")
447 # Process stdin by calling begin, line, and end functions for the backend
450 local begin process_line end str disable
451 begin
="lineto$1_begin_$backend"
452 process_line
="lineto$1_$backend"
453 end
="lineto$1_end_$backend"
457 while read -r str
; do
458 # Skip comments and empty lines
459 test -z "${str%%#*}" && continue
461 # Process the line. The nop backend handles disabled lines.
462 disable
=${str%%disable *}
464 if test -z "$disable"; then
465 # Pass the disabled state as an arg for the simple
466 # or DTrace backends which handle it dynamically.
467 # For all other backends, call lineto$1_nop()
468 if [ $backend = "simple" -o "$backend" = "dtrace" ]; then
469 "$process_line" "$str"
471 "lineto$1_nop" "${str##disable }"
474 "$process_line" "$str"
488 /* This file is autogenerated by tracetool, do not edit. */
490 #include "qemu-common.h"
493 echo "#endif /* TRACE_H */"
498 echo "/* This file is autogenerated by tracetool, do not edit. */"
504 if [ $backend != "dtrace" ]; then
505 echo "DTrace probe generator not applicable to $backend backend"
508 echo "/* This file is autogenerated by tracetool, do not edit. */"
514 if [ $backend != "dtrace" ]; then
515 echo "SystemTAP tapset generator not applicable to $backend backend"
518 if [ -z "$target" ]; then
519 echo "--target is required for SystemTAP tapset generator"
522 if [ -z "$bindir" ]; then
523 echo "--bindir is required for SystemTAP tapset generator"
526 echo "/* This file is autogenerated by tracetool, do not edit. */"
532 "--nop" |
"--simple" |
"--ust" |
"--dtrace") backend
="${1#--}" ;;
561 "--check-backend") exit 0 ;; # used by ./configure to test for backend