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)
33 # Get the name of a trace event
39 # Get the argument list of a trace event, including types and names
48 # Get the argument name list of a trace event
51 local nfields field name sep
54 for field
in $
(get_args
"$1"); do
55 nfields
=$
((nfields
+ 1))
60 # Only argument names have commas at the end
62 test "$field" = "$name" && continue
64 printf "%s%s " $name $sep
68 if [ "$nfields" -gt 1 ]
74 # Get the number of arguments to a trace event
79 for name
in $
(get_argnames
"$1", ","); do
85 # Get the format string for a trace event
94 # Get the state of a trace event
97 local str disable state
99 disable
=${str##disable }
100 if [ "$disable" = "$str" ] ; then
116 name
=$
(get_name
"$1")
117 args
=$
(get_args
"$1")
119 # Define an empty function for the trace event
121 static inline void trace_$name($args)
139 # No need for function definitions in nop backend
148 linetoh_begin_simple
()
151 #include "simpletrace.h"
157 cast_args_to_uint64_t
()
160 for arg
in $
(get_argnames
"$1", ","); do
161 printf "%s" "(uint64_t)(uintptr_t)$arg"
167 local name args argc trace_args state
168 name
=$
(get_name
"$1")
169 args
=$
(get_args
"$1")
170 argc
=$
(get_argc
"$1")
171 state
=$
(get_state
"$1")
172 if [ "$state" = "0" ]; then
173 name
=${name##disable }
176 trace_args
="$simple_event_num"
179 trace_args
="$trace_args, $(cast_args_to_uint64_t "$1")"
183 static inline void trace_$name($args)
185 trace$argc($trace_args);
189 simple_event_num
=$
((simple_event_num
+ 1))
195 #define NR_TRACE_EVENTS $simple_event_num
196 extern TraceEvent trace_list[NR_TRACE_EVENTS];
200 linetoc_begin_simple
()
205 TraceEvent trace_list[] = {
214 name
=$
(get_name
"$1")
215 state
=$
(get_state
"$1")
216 if [ "$state" = "0" ] ; then
217 name
=${name##disable }
220 {.tp_name = "$name", .state=$state},
222 simple_event_num
=$
((simple_event_num
+ 1))
232 # Clean up after UST headers which pollute the namespace
233 ust_clean_namespace
() {
244 echo "#include <ust/tracepoint.h>"
250 local name args argnames
251 name
=$
(get_name
"$1")
252 args
=$
(get_args
"$1")
253 argnames
=$
(get_argnames
"$1", ",")
256 DECLARE_TRACE(ust_$name, TP_PROTO($args), TP_ARGS($argnames));
257 #define trace_$name trace_ust_$name
269 #include <ust/marker.h>
270 $(ust_clean_namespace)
277 local name args argnames
fmt
278 name
=$
(get_name
"$1")
279 args
=$
(get_args
"$1")
280 argnames
=$
(get_argnames
"$1", ",")
284 DEFINE_TRACE(ust_$name);
286 static void ust_${name}_probe($args)
288 trace_mark(ust, $name, "$fmt", $argnames);
292 # Collect names for later
299 static void __attribute__((constructor)) trace_init(void)
303 for name
in $names; do
305 register_trace_ust_$name(ust_${name}_probe);
312 linetoh_begin_dtrace
()
315 #include "trace-dtrace.h"
321 local name args argnames state nameupper
322 name
=$
(get_name
"$1")
323 args
=$
(get_args
"$1")
324 argnames
=$
(get_argnames
"$1", ",")
325 state
=$
(get_state
"$1")
326 if [ "$state" = "0" ] ; then
327 name
=${name##disable }
330 nameupper
=`echo $name | tr '[:lower:]' '[:upper:]'`
332 # Define an empty function for the trace event
334 static inline void trace_$name($args) {
335 if (QEMU_${nameupper}_ENABLED()) {
336 QEMU_${nameupper}($argnames);
347 linetoc_begin_dtrace
()
354 # No need for function definitions in dtrace backend
363 linetod_begin_dtrace
()
372 local name args state
373 name
=$
(get_name
"$1")
374 args
=$
(get_args
"$1")
375 state
=$
(get_state
"$1")
376 if [ "$state" = "0" ] ; then
377 name
=${name##disable }
380 # Define prototype for probe arguments
393 # Process stdin by calling begin, line, and end functions for the backend
396 local begin process_line end str disable
397 begin
="lineto$1_begin_$backend"
398 process_line
="lineto$1_$backend"
399 end
="lineto$1_end_$backend"
403 while read -r str
; do
404 # Skip comments and empty lines
405 test -z "${str%%#*}" && continue
407 # Process the line. The nop backend handles disabled lines.
408 disable
=${str%%disable *}
410 if test -z "$disable"; then
411 # Pass the disabled state as an arg for the simple
412 # or DTrace backends which handle it dynamically.
413 # For all other backends, call lineto$1_nop()
414 if [ $backend = "simple" -o "$backend" = "dtrace" ]; then
415 "$process_line" "$str"
417 "lineto$1_nop" "${str##disable }"
420 "$process_line" "$str"
434 /* This file is autogenerated by tracetool, do not edit. */
436 #include "qemu-common.h"
439 echo "#endif /* TRACE_H */"
444 echo "/* This file is autogenerated by tracetool, do not edit. */"
450 if [ $backend != "dtrace" ]; then
451 echo "DTrace probe generator not applicable to $backend backend"
454 echo "/* This file is autogenerated by tracetool, do not edit. */"
460 "--nop" |
"--simple" |
"--ust" |
"--dtrace") backend
="${1#--}" ;;
469 "--check-backend") exit 0 ;; # used by ./configure to test for backend