Stefan Hajnoczi | 94a420b | 2010-05-22 17:52:39 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Code generator for trace events |
| 4 | # |
| 5 | # Copyright IBM, Corp. 2010 |
| 6 | # |
| 7 | # This work is licensed under the terms of the GNU GPL, version 2. See |
| 8 | # the COPYING file in the top-level directory. |
| 9 | |
| 10 | # Disable pathname expansion, makes processing text with '*' characters simpler |
| 11 | set -f |
| 12 | |
| 13 | usage() |
| 14 | { |
| 15 | cat >&2 <<EOF |
Fabien Chouteau | 320fba2 | 2011-01-27 10:24:41 +0100 | [diff] [blame] | 16 | usage: $0 [--nop | --simple | --stderr | --ust | --dtrace] [-h | -c] |
Stefan Hajnoczi | 94a420b | 2010-05-22 17:52:39 +0100 | [diff] [blame] | 17 | Generate tracing code for a file on stdin. |
| 18 | |
| 19 | Backends: |
Stefan Hajnoczi | 26f7227 | 2010-05-22 19:24:51 +0100 | [diff] [blame] | 20 | --nop Tracing disabled |
| 21 | --simple Simple built-in backend |
Fabien Chouteau | 320fba2 | 2011-01-27 10:24:41 +0100 | [diff] [blame] | 22 | --stderr Stderr built-in backend |
Stefan Hajnoczi | 7e24e92 | 2010-05-22 21:11:33 +0100 | [diff] [blame] | 23 | --ust LTTng User Space Tracing backend |
Daniel P. Berrange | b3d08c0 | 2010-11-12 13:20:24 +0000 | [diff] [blame] | 24 | --dtrace DTrace/SystemTAP backend |
Stefan Hajnoczi | 94a420b | 2010-05-22 17:52:39 +0100 | [diff] [blame] | 25 | |
| 26 | Output formats: |
Daniel P. Berrange | c276b17 | 2010-11-12 13:20:25 +0000 | [diff] [blame] | 27 | -h Generate .h file |
| 28 | -c Generate .c file |
| 29 | -d Generate .d file (DTrace only) |
| 30 | --stap Generate .stp file (DTrace with SystemTAP only) |
| 31 | |
| 32 | Options: |
Jes Sorensen | e323c93 | 2011-02-17 13:26:05 +0100 | [diff] [blame] | 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') |
| 36 | --probe-prefix [prefix] Prefix for dtrace probe names |
| 37 | (default: qemu-\$targettype-\$targetarch) |
Daniel P. Berrange | c276b17 | 2010-11-12 13:20:25 +0000 | [diff] [blame] | 38 | |
Stefan Hajnoczi | 94a420b | 2010-05-22 17:52:39 +0100 | [diff] [blame] | 39 | EOF |
| 40 | exit 1 |
| 41 | } |
| 42 | |
Stefan Hajnoczi | 913540a | 2011-09-13 13:34:35 +0100 | [diff] [blame] | 43 | # Print a line without interpreting backslash escapes |
| 44 | # |
| 45 | # The built-in echo command may interpret backslash escapes without an option |
| 46 | # to disable this behavior. |
| 47 | puts() |
| 48 | { |
| 49 | printf "%s\n" "$1" |
| 50 | } |
| 51 | |
Stefan Hajnoczi | 94a420b | 2010-05-22 17:52:39 +0100 | [diff] [blame] | 52 | # Get the name of a trace event |
| 53 | get_name() |
| 54 | { |
Lluís | 4992604 | 2011-08-31 20:31:10 +0200 | [diff] [blame] | 55 | local name |
| 56 | name=${1%%\(*} |
| 57 | echo "${name##* }" |
| 58 | } |
| 59 | |
| 60 | # Get the given property of a trace event |
| 61 | # 1: trace-events line |
| 62 | # 2: property name |
| 63 | # -> return 0 if property is present, or 1 otherwise |
| 64 | has_property() |
| 65 | { |
| 66 | local props prop |
| 67 | props=${1%%\(*} |
| 68 | props=${props% *} |
| 69 | for prop in $props; do |
| 70 | if [ "$prop" = "$2" ]; then |
| 71 | return 0 |
| 72 | fi |
| 73 | done |
| 74 | return 1 |
Stefan Hajnoczi | 94a420b | 2010-05-22 17:52:39 +0100 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | # Get the argument list of a trace event, including types and names |
| 78 | get_args() |
| 79 | { |
| 80 | local args |
| 81 | args=${1#*\(} |
Paolo Bonzini | 1a96dd4 | 2011-04-15 15:23:59 +0200 | [diff] [blame] | 82 | args=${args%%\)*} |
Stefan Hajnoczi | 94a420b | 2010-05-22 17:52:39 +0100 | [diff] [blame] | 83 | echo "$args" |
| 84 | } |
| 85 | |
| 86 | # Get the argument name list of a trace event |
| 87 | get_argnames() |
| 88 | { |
Daniel P. Berrange | b3d08c0 | 2010-11-12 13:20:24 +0000 | [diff] [blame] | 89 | local nfields field name sep |
Stefan Hajnoczi | 94a420b | 2010-05-22 17:52:39 +0100 | [diff] [blame] | 90 | nfields=0 |
Daniel P. Berrange | b3d08c0 | 2010-11-12 13:20:24 +0000 | [diff] [blame] | 91 | sep="$2" |
Stefan Hajnoczi | 94a420b | 2010-05-22 17:52:39 +0100 | [diff] [blame] | 92 | for field in $(get_args "$1"); do |
| 93 | nfields=$((nfields + 1)) |
| 94 | |
| 95 | # Drop pointer star |
| 96 | field=${field#\*} |
| 97 | |
| 98 | # Only argument names have commas at the end |
| 99 | name=${field%,} |
| 100 | test "$field" = "$name" && continue |
| 101 | |
Daniel P. Berrange | b3d08c0 | 2010-11-12 13:20:24 +0000 | [diff] [blame] | 102 | printf "%s%s " $name $sep |
Stefan Hajnoczi | 94a420b | 2010-05-22 17:52:39 +0100 | [diff] [blame] | 103 | done |
| 104 | |
| 105 | # Last argument name |
| 106 | if [ "$nfields" -gt 1 ] |
| 107 | then |
| 108 | printf "%s" "$name" |
| 109 | fi |
| 110 | } |
| 111 | |
Stefan Hajnoczi | 26f7227 | 2010-05-22 19:24:51 +0100 | [diff] [blame] | 112 | # Get the number of arguments to a trace event |
| 113 | get_argc() |
| 114 | { |
| 115 | local name argc |
| 116 | argc=0 |
Daniel P. Berrange | b3d08c0 | 2010-11-12 13:20:24 +0000 | [diff] [blame] | 117 | for name in $(get_argnames "$1", ","); do |
Stefan Hajnoczi | 26f7227 | 2010-05-22 19:24:51 +0100 | [diff] [blame] | 118 | argc=$((argc + 1)) |
| 119 | done |
| 120 | echo $argc |
| 121 | } |
| 122 | |
Stefan Hajnoczi | 913540a | 2011-09-13 13:34:35 +0100 | [diff] [blame] | 123 | # Get the format string including double quotes for a trace event |
Stefan Hajnoczi | 94a420b | 2010-05-22 17:52:39 +0100 | [diff] [blame] | 124 | get_fmt() |
| 125 | { |
Stefan Hajnoczi | 913540a | 2011-09-13 13:34:35 +0100 | [diff] [blame] | 126 | puts "${1#*)}" |
Stefan Hajnoczi | 94a420b | 2010-05-22 17:52:39 +0100 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | linetoh_begin_nop() |
| 130 | { |
| 131 | return |
| 132 | } |
| 133 | |
| 134 | linetoh_nop() |
| 135 | { |
| 136 | local name args |
| 137 | name=$(get_name "$1") |
| 138 | args=$(get_args "$1") |
| 139 | |
| 140 | # Define an empty function for the trace event |
| 141 | cat <<EOF |
| 142 | static inline void trace_$name($args) |
| 143 | { |
| 144 | } |
| 145 | EOF |
| 146 | } |
| 147 | |
| 148 | linetoh_end_nop() |
| 149 | { |
| 150 | return |
| 151 | } |
| 152 | |
| 153 | linetoc_begin_nop() |
| 154 | { |
| 155 | return |
| 156 | } |
| 157 | |
| 158 | linetoc_nop() |
| 159 | { |
| 160 | # No need for function definitions in nop backend |
| 161 | return |
| 162 | } |
| 163 | |
| 164 | linetoc_end_nop() |
| 165 | { |
| 166 | return |
| 167 | } |
| 168 | |
Stefan Hajnoczi | 26f7227 | 2010-05-22 19:24:51 +0100 | [diff] [blame] | 169 | linetoh_begin_simple() |
| 170 | { |
| 171 | cat <<EOF |
Lluís | edb47ec | 2011-08-31 20:30:57 +0200 | [diff] [blame] | 172 | #include "trace/simple.h" |
Stefan Hajnoczi | 26f7227 | 2010-05-22 19:24:51 +0100 | [diff] [blame] | 173 | EOF |
| 174 | |
| 175 | simple_event_num=0 |
| 176 | } |
| 177 | |
| 178 | cast_args_to_uint64_t() |
| 179 | { |
| 180 | local arg |
Daniel P. Berrange | b3d08c0 | 2010-11-12 13:20:24 +0000 | [diff] [blame] | 181 | for arg in $(get_argnames "$1", ","); do |
Stefan Hajnoczi | 26f7227 | 2010-05-22 19:24:51 +0100 | [diff] [blame] | 182 | printf "%s" "(uint64_t)(uintptr_t)$arg" |
| 183 | done |
| 184 | } |
| 185 | |
| 186 | linetoh_simple() |
| 187 | { |
Lluís | 4992604 | 2011-08-31 20:31:10 +0200 | [diff] [blame] | 188 | local name args argc trace_args |
Stefan Hajnoczi | 26f7227 | 2010-05-22 19:24:51 +0100 | [diff] [blame] | 189 | name=$(get_name "$1") |
| 190 | args=$(get_args "$1") |
| 191 | argc=$(get_argc "$1") |
| 192 | |
| 193 | trace_args="$simple_event_num" |
| 194 | if [ "$argc" -gt 0 ] |
| 195 | then |
| 196 | trace_args="$trace_args, $(cast_args_to_uint64_t "$1")" |
| 197 | fi |
| 198 | |
| 199 | cat <<EOF |
| 200 | static inline void trace_$name($args) |
| 201 | { |
| 202 | trace$argc($trace_args); |
| 203 | } |
| 204 | EOF |
| 205 | |
| 206 | simple_event_num=$((simple_event_num + 1)) |
| 207 | } |
| 208 | |
| 209 | linetoh_end_simple() |
| 210 | { |
Prerna Saxena | 22890ab | 2010-06-24 17:04:53 +0530 | [diff] [blame] | 211 | cat <<EOF |
| 212 | #define NR_TRACE_EVENTS $simple_event_num |
| 213 | extern TraceEvent trace_list[NR_TRACE_EVENTS]; |
| 214 | EOF |
Stefan Hajnoczi | 26f7227 | 2010-05-22 19:24:51 +0100 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | linetoc_begin_simple() |
| 218 | { |
Prerna Saxena | 22890ab | 2010-06-24 17:04:53 +0530 | [diff] [blame] | 219 | cat <<EOF |
| 220 | #include "trace.h" |
| 221 | |
| 222 | TraceEvent trace_list[] = { |
| 223 | EOF |
| 224 | simple_event_num=0 |
| 225 | |
Stefan Hajnoczi | 26f7227 | 2010-05-22 19:24:51 +0100 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | linetoc_simple() |
| 229 | { |
Lluís | 03727e6 | 2011-08-31 20:31:45 +0200 | [diff] [blame] | 230 | local name |
Prerna Saxena | 22890ab | 2010-06-24 17:04:53 +0530 | [diff] [blame] | 231 | name=$(get_name "$1") |
| 232 | cat <<EOF |
Lluís | 03727e6 | 2011-08-31 20:31:45 +0200 | [diff] [blame] | 233 | {.tp_name = "$name", .state=0}, |
Prerna Saxena | 22890ab | 2010-06-24 17:04:53 +0530 | [diff] [blame] | 234 | EOF |
| 235 | simple_event_num=$((simple_event_num + 1)) |
Stefan Hajnoczi | 26f7227 | 2010-05-22 19:24:51 +0100 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | linetoc_end_simple() |
| 239 | { |
Prerna Saxena | 22890ab | 2010-06-24 17:04:53 +0530 | [diff] [blame] | 240 | cat <<EOF |
| 241 | }; |
| 242 | EOF |
Stefan Hajnoczi | 26f7227 | 2010-05-22 19:24:51 +0100 | [diff] [blame] | 243 | } |
| 244 | |
Fabien Chouteau | 320fba2 | 2011-01-27 10:24:41 +0100 | [diff] [blame] | 245 | #STDERR |
| 246 | linetoh_begin_stderr() |
| 247 | { |
| 248 | cat <<EOF |
| 249 | #include <stdio.h> |
Lluís | 9a82b6a | 2011-08-31 20:31:51 +0200 | [diff] [blame] | 250 | #include "trace/stderr.h" |
| 251 | |
| 252 | extern TraceEvent trace_list[]; |
Fabien Chouteau | 320fba2 | 2011-01-27 10:24:41 +0100 | [diff] [blame] | 253 | EOF |
Lluís | 9a82b6a | 2011-08-31 20:31:51 +0200 | [diff] [blame] | 254 | |
| 255 | stderr_event_num=0 |
Fabien Chouteau | 320fba2 | 2011-01-27 10:24:41 +0100 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | linetoh_stderr() |
| 259 | { |
| 260 | local name args argnames argc fmt |
| 261 | name=$(get_name "$1") |
| 262 | args=$(get_args "$1") |
| 263 | argnames=$(get_argnames "$1" ",") |
| 264 | argc=$(get_argc "$1") |
| 265 | fmt=$(get_fmt "$1") |
| 266 | |
| 267 | if [ "$argc" -gt 0 ]; then |
| 268 | argnames=", $argnames" |
| 269 | fi |
| 270 | |
| 271 | cat <<EOF |
| 272 | static inline void trace_$name($args) |
| 273 | { |
Lluís | 9a82b6a | 2011-08-31 20:31:51 +0200 | [diff] [blame] | 274 | if (trace_list[$stderr_event_num].state != 0) { |
Stefan Hajnoczi | 913540a | 2011-09-13 13:34:35 +0100 | [diff] [blame] | 275 | fprintf(stderr, "$name " $fmt "\n" $argnames); |
Lluís | 9a82b6a | 2011-08-31 20:31:51 +0200 | [diff] [blame] | 276 | } |
Fabien Chouteau | 320fba2 | 2011-01-27 10:24:41 +0100 | [diff] [blame] | 277 | } |
| 278 | EOF |
Lluís | 9a82b6a | 2011-08-31 20:31:51 +0200 | [diff] [blame] | 279 | stderr_event_num=$((stderr_event_num + 1)) |
| 280 | |
Fabien Chouteau | 320fba2 | 2011-01-27 10:24:41 +0100 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | linetoh_end_stderr() |
| 284 | { |
Lluís | 9a82b6a | 2011-08-31 20:31:51 +0200 | [diff] [blame] | 285 | cat <<EOF |
| 286 | #define NR_TRACE_EVENTS $stderr_event_num |
| 287 | EOF |
Fabien Chouteau | 320fba2 | 2011-01-27 10:24:41 +0100 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | linetoc_begin_stderr() |
| 291 | { |
Lluís | 9a82b6a | 2011-08-31 20:31:51 +0200 | [diff] [blame] | 292 | cat <<EOF |
| 293 | #include "trace.h" |
| 294 | |
| 295 | TraceEvent trace_list[] = { |
| 296 | EOF |
| 297 | stderr_event_num=0 |
Fabien Chouteau | 320fba2 | 2011-01-27 10:24:41 +0100 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | linetoc_stderr() |
| 301 | { |
Lluís | 9a82b6a | 2011-08-31 20:31:51 +0200 | [diff] [blame] | 302 | local name |
| 303 | name=$(get_name "$1") |
| 304 | cat <<EOF |
| 305 | {.tp_name = "$name", .state=0}, |
| 306 | EOF |
| 307 | stderr_event_num=$(($stderr_event_num + 1)) |
Fabien Chouteau | 320fba2 | 2011-01-27 10:24:41 +0100 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | linetoc_end_stderr() |
| 311 | { |
Lluís | 9a82b6a | 2011-08-31 20:31:51 +0200 | [diff] [blame] | 312 | cat <<EOF |
| 313 | }; |
| 314 | EOF |
Fabien Chouteau | 320fba2 | 2011-01-27 10:24:41 +0100 | [diff] [blame] | 315 | } |
| 316 | #END OF STDERR |
| 317 | |
Stefan Hajnoczi | 7e24e92 | 2010-05-22 21:11:33 +0100 | [diff] [blame] | 318 | # Clean up after UST headers which pollute the namespace |
| 319 | ust_clean_namespace() { |
| 320 | cat <<EOF |
| 321 | #undef mutex_lock |
| 322 | #undef mutex_unlock |
| 323 | #undef inline |
| 324 | #undef wmb |
| 325 | EOF |
| 326 | } |
| 327 | |
| 328 | linetoh_begin_ust() |
| 329 | { |
| 330 | echo "#include <ust/tracepoint.h>" |
| 331 | ust_clean_namespace |
| 332 | } |
| 333 | |
| 334 | linetoh_ust() |
| 335 | { |
| 336 | local name args argnames |
| 337 | name=$(get_name "$1") |
| 338 | args=$(get_args "$1") |
Daniel P. Berrange | b3d08c0 | 2010-11-12 13:20:24 +0000 | [diff] [blame] | 339 | argnames=$(get_argnames "$1", ",") |
Stefan Hajnoczi | 7e24e92 | 2010-05-22 21:11:33 +0100 | [diff] [blame] | 340 | |
| 341 | cat <<EOF |
Stefan Hajnoczi | ea9c169 | 2010-10-05 14:28:52 +0100 | [diff] [blame] | 342 | DECLARE_TRACE(ust_$name, TP_PROTO($args), TP_ARGS($argnames)); |
Stefan Hajnoczi | 7e24e92 | 2010-05-22 21:11:33 +0100 | [diff] [blame] | 343 | #define trace_$name trace_ust_$name |
| 344 | EOF |
| 345 | } |
| 346 | |
| 347 | linetoh_end_ust() |
| 348 | { |
| 349 | return |
| 350 | } |
| 351 | |
| 352 | linetoc_begin_ust() |
| 353 | { |
| 354 | cat <<EOF |
| 355 | #include <ust/marker.h> |
| 356 | $(ust_clean_namespace) |
| 357 | #include "trace.h" |
| 358 | EOF |
| 359 | } |
| 360 | |
| 361 | linetoc_ust() |
| 362 | { |
| 363 | local name args argnames fmt |
| 364 | name=$(get_name "$1") |
| 365 | args=$(get_args "$1") |
Daniel P. Berrange | b3d08c0 | 2010-11-12 13:20:24 +0000 | [diff] [blame] | 366 | argnames=$(get_argnames "$1", ",") |
Lluís | fa2d480 | 2011-04-06 20:34:03 +0200 | [diff] [blame] | 367 | [ -z "$argnames" ] || argnames=", $argnames" |
Stefan Hajnoczi | 7e24e92 | 2010-05-22 21:11:33 +0100 | [diff] [blame] | 368 | fmt=$(get_fmt "$1") |
| 369 | |
| 370 | cat <<EOF |
| 371 | DEFINE_TRACE(ust_$name); |
| 372 | |
| 373 | static void ust_${name}_probe($args) |
| 374 | { |
Stefan Hajnoczi | 913540a | 2011-09-13 13:34:35 +0100 | [diff] [blame] | 375 | trace_mark(ust, $name, $fmt$argnames); |
Stefan Hajnoczi | 7e24e92 | 2010-05-22 21:11:33 +0100 | [diff] [blame] | 376 | } |
| 377 | EOF |
| 378 | |
| 379 | # Collect names for later |
| 380 | names="$names $name" |
| 381 | } |
| 382 | |
| 383 | linetoc_end_ust() |
| 384 | { |
| 385 | cat <<EOF |
| 386 | static void __attribute__((constructor)) trace_init(void) |
| 387 | { |
| 388 | EOF |
| 389 | |
| 390 | for name in $names; do |
| 391 | cat <<EOF |
| 392 | register_trace_ust_$name(ust_${name}_probe); |
| 393 | EOF |
| 394 | done |
| 395 | |
| 396 | echo "}" |
| 397 | } |
| 398 | |
Daniel P. Berrange | b3d08c0 | 2010-11-12 13:20:24 +0000 | [diff] [blame] | 399 | linetoh_begin_dtrace() |
| 400 | { |
| 401 | cat <<EOF |
| 402 | #include "trace-dtrace.h" |
| 403 | EOF |
| 404 | } |
| 405 | |
| 406 | linetoh_dtrace() |
| 407 | { |
Lluís | 4992604 | 2011-08-31 20:31:10 +0200 | [diff] [blame] | 408 | local name args argnames nameupper |
Daniel P. Berrange | b3d08c0 | 2010-11-12 13:20:24 +0000 | [diff] [blame] | 409 | name=$(get_name "$1") |
| 410 | args=$(get_args "$1") |
| 411 | argnames=$(get_argnames "$1", ",") |
Daniel P. Berrange | b3d08c0 | 2010-11-12 13:20:24 +0000 | [diff] [blame] | 412 | |
| 413 | nameupper=`echo $name | tr '[:lower:]' '[:upper:]'` |
| 414 | |
| 415 | # Define an empty function for the trace event |
| 416 | cat <<EOF |
| 417 | static inline void trace_$name($args) { |
| 418 | if (QEMU_${nameupper}_ENABLED()) { |
| 419 | QEMU_${nameupper}($argnames); |
| 420 | } |
| 421 | } |
| 422 | EOF |
| 423 | } |
| 424 | |
| 425 | linetoh_end_dtrace() |
| 426 | { |
| 427 | return |
| 428 | } |
| 429 | |
| 430 | linetoc_begin_dtrace() |
| 431 | { |
| 432 | return |
| 433 | } |
| 434 | |
| 435 | linetoc_dtrace() |
| 436 | { |
| 437 | # No need for function definitions in dtrace backend |
| 438 | return |
| 439 | } |
| 440 | |
| 441 | linetoc_end_dtrace() |
| 442 | { |
| 443 | return |
| 444 | } |
| 445 | |
| 446 | linetod_begin_dtrace() |
| 447 | { |
| 448 | cat <<EOF |
| 449 | provider qemu { |
| 450 | EOF |
| 451 | } |
| 452 | |
| 453 | linetod_dtrace() |
| 454 | { |
Lluís | 4992604 | 2011-08-31 20:31:10 +0200 | [diff] [blame] | 455 | local name args |
Daniel P. Berrange | b3d08c0 | 2010-11-12 13:20:24 +0000 | [diff] [blame] | 456 | name=$(get_name "$1") |
| 457 | args=$(get_args "$1") |
Daniel P. Berrange | b3d08c0 | 2010-11-12 13:20:24 +0000 | [diff] [blame] | 458 | |
| 459 | # DTrace provider syntax expects foo() for empty |
| 460 | # params, not foo(void) |
| 461 | if [ "$args" = "void" ]; then |
| 462 | args="" |
| 463 | fi |
| 464 | |
| 465 | # Define prototype for probe arguments |
| 466 | cat <<EOF |
| 467 | probe $name($args); |
| 468 | EOF |
| 469 | } |
| 470 | |
| 471 | linetod_end_dtrace() |
| 472 | { |
| 473 | cat <<EOF |
| 474 | }; |
| 475 | EOF |
| 476 | } |
| 477 | |
Daniel P. Berrange | c276b17 | 2010-11-12 13:20:25 +0000 | [diff] [blame] | 478 | linetostap_begin_dtrace() |
| 479 | { |
| 480 | return |
| 481 | } |
| 482 | |
| 483 | linetostap_dtrace() |
| 484 | { |
Lluís | 4992604 | 2011-08-31 20:31:10 +0200 | [diff] [blame] | 485 | local i arg name args arglist |
Daniel P. Berrange | c276b17 | 2010-11-12 13:20:25 +0000 | [diff] [blame] | 486 | name=$(get_name "$1") |
| 487 | args=$(get_args "$1") |
| 488 | arglist=$(get_argnames "$1", "") |
Daniel P. Berrange | c276b17 | 2010-11-12 13:20:25 +0000 | [diff] [blame] | 489 | |
| 490 | # Define prototype for probe arguments |
| 491 | cat <<EOF |
Jes Sorensen | e323c93 | 2011-02-17 13:26:05 +0100 | [diff] [blame] | 492 | probe $probeprefix.$name = process("$binary").mark("$name") |
Daniel P. Berrange | c276b17 | 2010-11-12 13:20:25 +0000 | [diff] [blame] | 493 | { |
| 494 | EOF |
| 495 | |
| 496 | i=1 |
| 497 | for arg in $arglist |
| 498 | do |
| 499 | # 'limit' is a reserved keyword |
| 500 | if [ "$arg" = "limit" ]; then |
| 501 | arg="_limit" |
| 502 | fi |
| 503 | cat <<EOF |
| 504 | $arg = \$arg$i; |
| 505 | EOF |
Lluís | fa2d480 | 2011-04-06 20:34:03 +0200 | [diff] [blame] | 506 | i="$((i+1))" |
Daniel P. Berrange | c276b17 | 2010-11-12 13:20:25 +0000 | [diff] [blame] | 507 | done |
| 508 | |
| 509 | cat <<EOF |
| 510 | } |
| 511 | EOF |
| 512 | } |
| 513 | |
| 514 | linetostap_end_dtrace() |
| 515 | { |
| 516 | return |
| 517 | } |
| 518 | |
Stefan Hajnoczi | 94a420b | 2010-05-22 17:52:39 +0100 | [diff] [blame] | 519 | # Process stdin by calling begin, line, and end functions for the backend |
| 520 | convert() |
| 521 | { |
Lluís Vilanova | b7d66a7 | 2011-12-06 17:38:15 +0100 | [diff] [blame^] | 522 | local begin process_line end str name NAME enabled |
Stefan Hajnoczi | 94a420b | 2010-05-22 17:52:39 +0100 | [diff] [blame] | 523 | begin="lineto$1_begin_$backend" |
| 524 | process_line="lineto$1_$backend" |
| 525 | end="lineto$1_end_$backend" |
| 526 | |
| 527 | "$begin" |
| 528 | |
| 529 | while read -r str; do |
| 530 | # Skip comments and empty lines |
Stefan Hajnoczi | 5eb5527 | 2010-10-05 14:28:51 +0100 | [diff] [blame] | 531 | test -z "${str%%#*}" && continue |
Stefan Hajnoczi | 94a420b | 2010-05-22 17:52:39 +0100 | [diff] [blame] | 532 | |
| 533 | echo |
Lluís | dd215f6 | 2011-08-31 20:31:38 +0200 | [diff] [blame] | 534 | # Process the line. The nop backend handles disabled lines. |
| 535 | if has_property "$str" "disable"; then |
| 536 | "lineto$1_nop" "$str" |
Lluís Vilanova | b7d66a7 | 2011-12-06 17:38:15 +0100 | [diff] [blame^] | 537 | enabled=0 |
Stefan Hajnoczi | 1e2cf2b | 2010-05-24 11:32:09 +0100 | [diff] [blame] | 538 | else |
| 539 | "$process_line" "$str" |
Lluís Vilanova | b7d66a7 | 2011-12-06 17:38:15 +0100 | [diff] [blame^] | 540 | enabled=1 |
| 541 | fi |
| 542 | if [ "$1" = "h" ]; then |
| 543 | name=$(get_name "$str") |
| 544 | NAME=$(echo $name | tr '[:lower:]' '[:upper:]') |
| 545 | echo "#define TRACE_${NAME}_ENABLED ${enabled}" |
Stefan Hajnoczi | 1e2cf2b | 2010-05-24 11:32:09 +0100 | [diff] [blame] | 546 | fi |
Stefan Hajnoczi | 94a420b | 2010-05-22 17:52:39 +0100 | [diff] [blame] | 547 | done |
| 548 | |
| 549 | echo |
| 550 | "$end" |
| 551 | } |
| 552 | |
| 553 | tracetoh() |
| 554 | { |
| 555 | cat <<EOF |
| 556 | #ifndef TRACE_H |
| 557 | #define TRACE_H |
| 558 | |
| 559 | /* This file is autogenerated by tracetool, do not edit. */ |
| 560 | |
| 561 | #include "qemu-common.h" |
| 562 | EOF |
| 563 | convert h |
| 564 | echo "#endif /* TRACE_H */" |
| 565 | } |
| 566 | |
| 567 | tracetoc() |
| 568 | { |
| 569 | echo "/* This file is autogenerated by tracetool, do not edit. */" |
| 570 | convert c |
| 571 | } |
| 572 | |
Daniel P. Berrange | b3d08c0 | 2010-11-12 13:20:24 +0000 | [diff] [blame] | 573 | tracetod() |
| 574 | { |
| 575 | if [ $backend != "dtrace" ]; then |
| 576 | echo "DTrace probe generator not applicable to $backend backend" |
| 577 | exit 1 |
| 578 | fi |
| 579 | echo "/* This file is autogenerated by tracetool, do not edit. */" |
| 580 | convert d |
| 581 | } |
| 582 | |
Daniel P. Berrange | c276b17 | 2010-11-12 13:20:25 +0000 | [diff] [blame] | 583 | tracetostap() |
| 584 | { |
| 585 | if [ $backend != "dtrace" ]; then |
| 586 | echo "SystemTAP tapset generator not applicable to $backend backend" |
| 587 | exit 1 |
| 588 | fi |
| 589 | if [ -z "$binary" ]; then |
| 590 | echo "--binary is required for SystemTAP tapset generator" |
| 591 | exit 1 |
| 592 | fi |
Jes Sorensen | e323c93 | 2011-02-17 13:26:05 +0100 | [diff] [blame] | 593 | if [ -z "$probeprefix" -a -z "$targettype" ]; then |
Daniel P. Berrange | c276b17 | 2010-11-12 13:20:25 +0000 | [diff] [blame] | 594 | echo "--target-type is required for SystemTAP tapset generator" |
| 595 | exit 1 |
| 596 | fi |
Jes Sorensen | e323c93 | 2011-02-17 13:26:05 +0100 | [diff] [blame] | 597 | if [ -z "$probeprefix" -a -z "$targetarch" ]; then |
Daniel P. Berrange | c276b17 | 2010-11-12 13:20:25 +0000 | [diff] [blame] | 598 | echo "--target-arch is required for SystemTAP tapset generator" |
| 599 | exit 1 |
| 600 | fi |
Jes Sorensen | e323c93 | 2011-02-17 13:26:05 +0100 | [diff] [blame] | 601 | if [ -z "$probeprefix" ]; then |
Lluís | fa2d480 | 2011-04-06 20:34:03 +0200 | [diff] [blame] | 602 | probeprefix="qemu.$targettype.$targetarch"; |
Jes Sorensen | e323c93 | 2011-02-17 13:26:05 +0100 | [diff] [blame] | 603 | fi |
Daniel P. Berrange | c276b17 | 2010-11-12 13:20:25 +0000 | [diff] [blame] | 604 | echo "/* This file is autogenerated by tracetool, do not edit. */" |
| 605 | convert stap |
| 606 | } |
Stefan Hajnoczi | 94a420b | 2010-05-22 17:52:39 +0100 | [diff] [blame] | 607 | |
Daniel P. Berrange | c276b17 | 2010-11-12 13:20:25 +0000 | [diff] [blame] | 608 | |
| 609 | backend= |
| 610 | output= |
| 611 | binary= |
| 612 | targettype= |
| 613 | targetarch= |
Jes Sorensen | e323c93 | 2011-02-17 13:26:05 +0100 | [diff] [blame] | 614 | probeprefix= |
Daniel P. Berrange | c276b17 | 2010-11-12 13:20:25 +0000 | [diff] [blame] | 615 | |
| 616 | |
| 617 | until [ -z "$1" ] |
| 618 | do |
| 619 | case "$1" in |
Fabien Chouteau | 320fba2 | 2011-01-27 10:24:41 +0100 | [diff] [blame] | 620 | "--nop" | "--simple" | "--stderr" | "--ust" | "--dtrace") backend="${1#--}" ;; |
Daniel P. Berrange | c276b17 | 2010-11-12 13:20:25 +0000 | [diff] [blame] | 621 | |
| 622 | "--binary") shift ; binary="$1" ;; |
| 623 | "--target-arch") shift ; targetarch="$1" ;; |
| 624 | "--target-type") shift ; targettype="$1" ;; |
Jes Sorensen | e323c93 | 2011-02-17 13:26:05 +0100 | [diff] [blame] | 625 | "--probe-prefix") shift ; probeprefix="$1" ;; |
Daniel P. Berrange | c276b17 | 2010-11-12 13:20:25 +0000 | [diff] [blame] | 626 | |
| 627 | "-h" | "-c" | "-d") output="${1#-}" ;; |
| 628 | "--stap") output="${1#--}" ;; |
| 629 | |
| 630 | "--check-backend") exit 0 ;; # used by ./configure to test for backend |
| 631 | |
Fabien Chouteau | 320fba2 | 2011-01-27 10:24:41 +0100 | [diff] [blame] | 632 | "--list-backends") # used by ./configure to list available backends |
| 633 | echo "nop simple stderr ust dtrace" |
| 634 | exit 0 |
| 635 | ;; |
| 636 | |
Daniel P. Berrange | c276b17 | 2010-11-12 13:20:25 +0000 | [diff] [blame] | 637 | *) |
| 638 | usage;; |
| 639 | esac |
| 640 | shift |
| 641 | done |
| 642 | |
| 643 | if [ "$backend" = "" -o "$output" = "" ]; then |
| 644 | usage |
| 645 | fi |
| 646 | |
| 647 | gen="traceto$output" |
| 648 | "$gen" |
Stefan Hajnoczi | 94a420b | 2010-05-22 17:52:39 +0100 | [diff] [blame] | 649 | |
| 650 | exit 0 |