Revision 06da6e44 tracetool

b/tracetool
20 20
  --nop     Tracing disabled
21 21
  --simple  Simple built-in backend
22 22
  --ust     LTTng User Space Tracing backend
23
  --dtrace  DTrace/SystemTAP backend
24 23

  
25 24
Output formats:
26 25
  -h    Generate .h file
27 26
  -c    Generate .c file
28
  -d    Generate .d file (DTrace only)
29 27
EOF
30 28
    exit 1
31 29
}
......
48 46
# Get the argument name list of a trace event
49 47
get_argnames()
50 48
{
51
    local nfields field name sep
49
    local nfields field name
52 50
    nfields=0
53
    sep="$2"
54 51
    for field in $(get_args "$1"); do
55 52
        nfields=$((nfields + 1))
56 53

  
......
61 58
        name=${field%,}
62 59
        test "$field" = "$name" && continue
63 60

  
64
        printf "%s%s " $name $sep
61
        printf "%s" "$name, "
65 62
    done
66 63

  
67 64
    # Last argument name
......
76 73
{
77 74
    local name argc
78 75
    argc=0
79
    for name in $(get_argnames "$1", ","); do
76
    for name in $(get_argnames "$1"); do
80 77
        argc=$((argc + 1))
81 78
    done
82 79
    echo $argc
......
157 154
cast_args_to_uint64_t()
158 155
{
159 156
    local arg
160
    for arg in $(get_argnames "$1", ","); do
157
    for arg in $(get_argnames "$1"); do
161 158
        printf "%s" "(uint64_t)(uintptr_t)$arg"
162 159
    done
163 160
}
......
250 247
    local name args argnames
251 248
    name=$(get_name "$1")
252 249
    args=$(get_args "$1")
253
    argnames=$(get_argnames "$1", ",")
250
    argnames=$(get_argnames "$1")
254 251

  
255 252
    cat <<EOF
256 253
DECLARE_TRACE(ust_$name, TP_PROTO($args), TP_ARGS($argnames));
......
277 274
    local name args argnames fmt
278 275
    name=$(get_name "$1")
279 276
    args=$(get_args "$1")
280
    argnames=$(get_argnames "$1", ",")
277
    argnames=$(get_argnames "$1")
281 278
    fmt=$(get_fmt "$1")
282 279

  
283 280
    cat <<EOF
......
309 306
    echo "}"
310 307
}
311 308

  
312
linetoh_begin_dtrace()
313
{
314
    cat <<EOF
315
#include "trace-dtrace.h"
316
EOF
317
}
318

  
319
linetoh_dtrace()
320
{
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 }
328
    fi
329

  
330
    nameupper=`echo $name | tr '[:lower:]' '[:upper:]'`
331

  
332
    # Define an empty function for the trace event
333
    cat <<EOF
334
static inline void trace_$name($args) {
335
    if (QEMU_${nameupper}_ENABLED()) {
336
        QEMU_${nameupper}($argnames);
337
    }
338
}
339
EOF
340
}
341

  
342
linetoh_end_dtrace()
343
{
344
    return
345
}
346

  
347
linetoc_begin_dtrace()
348
{
349
    return
350
}
351

  
352
linetoc_dtrace()
353
{
354
    # No need for function definitions in dtrace backend
355
    return
356
}
357

  
358
linetoc_end_dtrace()
359
{
360
    return
361
}
362

  
363
linetod_begin_dtrace()
364
{
365
    cat <<EOF
366
provider qemu {
367
EOF
368
}
369

  
370
linetod_dtrace()
371
{
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 }
378
    fi
379

  
380
    # Define prototype for probe arguments
381
    cat <<EOF
382
        probe $name($args);
383
EOF
384
}
385

  
386
linetod_end_dtrace()
387
{
388
    cat <<EOF
389
};
390
EOF
391
}
392

  
393 309
# Process stdin by calling begin, line, and end functions for the backend
394 310
convert()
395 311
{
......
408 324
        disable=${str%%disable *}
409 325
        echo
410 326
        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
327
            # Pass the disabled state as an arg to lineto$1_simple().
328
            # For all other cases, call lineto$1_nop()
329
            if [ $backend = "simple" ]; then
415 330
                "$process_line" "$str"
416 331
            else
417 332
                "lineto$1_nop" "${str##disable }"
......
445 360
    convert c
446 361
}
447 362

  
448
tracetod()
449
{
450
    if [ $backend != "dtrace" ]; then
451
       echo "DTrace probe generator not applicable to $backend backend"
452
       exit 1
453
    fi
454
    echo "/* This file is autogenerated by tracetool, do not edit. */"
455
    convert d
456
}
457

  
458 363
# Choose backend
459 364
case "$1" in
460
"--nop" | "--simple" | "--ust" | "--dtrace") backend="${1#--}" ;;
365
"--nop" | "--simple" | "--ust") backend="${1#--}" ;;
461 366
*) usage ;;
462 367
esac
463 368
shift
......
465 370
case "$1" in
466 371
"-h") tracetoh ;;
467 372
"-c") tracetoc ;;
468
"-d") tracetod ;;
469 373
"--check-backend") exit 0 ;; # used by ./configure to test for backend
470 374
*) usage ;;
471 375
esac

Also available in: Unified diff