Revision 4addb112 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
23 24

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

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

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

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

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

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

  
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

  
309 393
# Process stdin by calling begin, line, and end functions for the backend
310 394
convert()
311 395
{
......
324 408
        disable=${str%%disable *}
325 409
        echo
326 410
        if test -z "$disable"; 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
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
330 415
                "$process_line" "$str"
331 416
            else
332 417
                "lineto$1_nop" "${str##disable }"
......
360 445
    convert c
361 446
}
362 447

  
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

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

Also available in: Unified diff