Revision 06da6e44

b/.gitignore
4 4
config-target.*
5 5
trace.h
6 6
trace.c
7
trace-dtrace.h
8
trace-dtrace.dtrace
9 7
*-timestamp
10 8
*-softmmu
11 9
*-darwin-user
b/Makefile
1 1
# Makefile for QEMU.
2 2

  
3 3
GENERATED_HEADERS = config-host.h trace.h qemu-options.def
4
ifeq ($(TRACE_BACKEND),dtrace)
5
GENERATED_HEADERS += trace-dtrace.h
6
endif
7 4

  
8 5
ifneq ($(wildcard config-host.mak),)
9 6
# Put the all: rule here so that config-host.mak can contain dependencies.
......
111 108

  
112 109
bt-host.o: QEMU_CFLAGS += $(BLUEZ_CFLAGS)
113 110

  
114
ifeq ($(TRACE_BACKEND),dtrace)
115
trace.h: trace.h-timestamp trace-dtrace.h
116
else
117 111
trace.h: trace.h-timestamp
118
endif
119 112
trace.h-timestamp: $(SRC_PATH)/trace-events config-host.mak
120 113
	$(call quiet-command,sh $(SRC_PATH)/tracetool --$(TRACE_BACKEND) -h < $< > $@,"  GEN   trace.h")
121 114
	@cmp -s $@ trace.h || cp $@ trace.h
......
127 120

  
128 121
trace.o: trace.c $(GENERATED_HEADERS)
129 122

  
130
trace-dtrace.h: trace-dtrace.dtrace
131
	$(call quiet-command,dtrace -o $@ -h -s $<, "  GEN   trace-dtrace.h")
132

  
133
# Normal practice is to name DTrace probe file with a '.d' extension
134
# but that gets picked up by QEMU's Makefile as an external dependancy
135
# rule file. So we use '.dtrace' instead
136
trace-dtrace.dtrace: trace-dtrace.dtrace-timestamp
137
trace-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events config-host.mak
138
	$(call quiet-command,sh $(SRC_PATH)/tracetool --$(TRACE_BACKEND) -d < $< > $@,"  GEN   trace-dtrace.dtrace")
139
	@cmp -s $@ trace-dtrace.dtrace || cp $@ trace-dtrace.dtrace
140

  
141
trace-dtrace.o: trace-dtrace.dtrace $(GENERATED_HEADERS)
142
	$(call quiet-command,dtrace -o $@ -G -s $<, "  GEN trace-dtrace.o")
143

  
144 123
simpletrace.o: simpletrace.c $(GENERATED_HEADERS)
145 124

  
146 125
version.o: $(SRC_PATH)/version.rc config-host.mak
......
178 157
	rm -f slirp/*.o slirp/*.d audio/*.o audio/*.d block/*.o block/*.d net/*.o net/*.d fsdev/*.o fsdev/*.d ui/*.o ui/*.d
179 158
	rm -f qemu-img-cmds.h
180 159
	rm -f trace.c trace.h trace.c-timestamp trace.h-timestamp
181
	rm -f trace-dtrace.dtrace trace-dtrace.dtrace-timestamp
182
	rm -f trace-dtrace.h trace-dtrace.h-timestamp
183 160
	$(MAKE) -C tests clean
184 161
	for d in $(ALL_SUBDIRS) libhw32 libhw64 libuser libdis libdis-user; do \
185 162
	if test -d $$d; then $(MAKE) -C $$d $@ || exit 1; fi; \
b/Makefile.objs
286 286
######################################################################
287 287
# trace
288 288

  
289
ifeq ($(TRACE_BACKEND),dtrace)
290
trace-obj-y = trace-dtrace.o
291
else
292 289
trace-obj-y = trace.o
293 290
ifeq ($(TRACE_BACKEND),simple)
294 291
trace-obj-y += simpletrace.o
295 292
user-obj-y += qemu-timer-common.o
296 293
endif
297
endif
298 294

  
299 295
vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
300 296

  
b/configure
929 929
echo "  --disable-docs           disable documentation build"
930 930
echo "  --disable-vhost-net      disable vhost-net acceleration support"
931 931
echo "  --enable-vhost-net       enable vhost-net acceleration support"
932
echo "  --trace-backend=B        Trace backend nop simple ust dtrace"
932
echo "  --trace-backend=B        Trace backend nop simple ust"
933 933
echo "  --trace-file=NAME        Full PATH,NAME of file to store traces"
934 934
echo "                           Default:trace-<pid>"
935 935
echo "  --disable-spice          disable spice"
......
2193 2193
    exit 1
2194 2194
  fi
2195 2195
fi
2196

  
2197
##########################################
2198
# For 'dtrace' backend, test if 'dtrace' command is present
2199
if test "$trace_backend" = "dtrace"; then
2200
  if ! has 'dtrace' ; then
2201
    echo
2202
    echo "Error: dtrace command is not found in PATH $PATH"
2203
    echo
2204
    exit 1
2205
  fi
2206
fi
2207

  
2208 2196
##########################################
2209 2197
# End of CC checks
2210 2198
# After here, no more $cc or $ld runs
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