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
31 # Get the name of a trace event
37 # Get the argument list of a trace event, including types and names
46 # Get the argument name list of a trace event
49 local nfields field name
51 for field
in $
(get_args
"$1"); do
52 nfields
=$
((nfields
+ 1))
57 # Only argument names have commas at the end
59 test "$field" = "$name" && continue
65 if [ "$nfields" -gt 1 ]
71 # Get the number of arguments to a trace event
76 for name
in $
(get_argnames
"$1"); do
82 # Get the format string for a trace event
91 # Get the state of a trace event
94 local str disable state
96 disable
=${str##disable }
97 if [ "$disable" = "$str" ] ; then
113 name
=$
(get_name
"$1")
114 args
=$
(get_args
"$1")
116 # Define an empty function for the trace event
118 static inline void trace_$name($args)
136 # No need for function definitions in nop backend
145 linetoh_begin_simple
()
148 #include "simpletrace.h"
154 cast_args_to_uint64_t
()
157 for arg
in $
(get_argnames
"$1"); do
158 printf "%s" "(uint64_t)(uintptr_t)$arg"
164 local name args argc trace_args state
165 name
=$
(get_name
"$1")
166 args
=$
(get_args
"$1")
167 argc
=$
(get_argc
"$1")
168 state
=$
(get_state
"$1")
169 if [ "$state" = "0" ]; then
170 name
=${name##disable }
173 trace_args
="$simple_event_num"
176 trace_args
="$trace_args, $(cast_args_to_uint64_t "$1")"
180 static inline void trace_$name($args)
182 trace$argc($trace_args);
186 simple_event_num
=$
((simple_event_num
+ 1))
192 #define NR_TRACE_EVENTS $simple_event_num
193 extern TraceEvent trace_list[NR_TRACE_EVENTS];
197 linetoc_begin_simple
()
202 TraceEvent trace_list[] = {
211 name
=$
(get_name
"$1")
212 state
=$
(get_state
"$1")
213 if [ "$state" = "0" ] ; then
214 name
=${name##disable }
217 {.tp_name = "$name", .state=$state},
219 simple_event_num
=$
((simple_event_num
+ 1))
229 # Clean up after UST headers which pollute the namespace
230 ust_clean_namespace
() {
241 echo "#include <ust/tracepoint.h>"
247 local name args argnames
248 name
=$
(get_name
"$1")
249 args
=$
(get_args
"$1")
250 argnames
=$
(get_argnames
"$1")
253 DECLARE_TRACE(ust_$name, TPPROTO($args), TPARGS($argnames));
254 #define trace_$name trace_ust_$name
266 #include <ust/marker.h>
267 $(ust_clean_namespace)
274 local name args argnames
fmt
275 name
=$
(get_name
"$1")
276 args
=$
(get_args
"$1")
277 argnames
=$
(get_argnames
"$1")
281 DEFINE_TRACE(ust_$name);
283 static void ust_${name}_probe($args)
285 trace_mark(ust, $name, "$fmt", $argnames);
289 # Collect names for later
296 static void __attribute__((constructor)) trace_init(void)
300 for name
in $names; do
302 register_trace_ust_$name(ust_${name}_probe);
309 # Process stdin by calling begin, line, and end functions for the backend
312 local begin process_line end str disable
313 begin
="lineto$1_begin_$backend"
314 process_line
="lineto$1_$backend"
315 end
="lineto$1_end_$backend"
319 while read -r str
; do
320 # Skip comments and empty lines
322 test -z "$str" && continue
324 # Process the line. The nop backend handles disabled lines.
325 disable
=${str%%disable *}
327 if test -z "$disable"; then
328 # Pass the disabled state as an arg to lineto$1_simple().
329 # For all other cases, call lineto$1_nop()
330 if [ $backend = "simple" ]; then
331 "$process_line" "$str"
333 "lineto$1_nop" "${str##disable }"
336 "$process_line" "$str"
350 /* This file is autogenerated by tracetool, do not edit. */
352 #include "qemu-common.h"
355 echo "#endif /* TRACE_H */"
360 echo "/* This file is autogenerated by tracetool, do not edit. */"
366 "--nop" |
"--simple" |
"--ust") backend
="${1#--}" ;;
374 "--check-backend") exit 0 ;; # used by ./configure to test for backend