Revision 4addb112

b/.gitignore
4 4
config-target.*
5 5
trace.h
6 6
trace.c
7
trace-dtrace.h
8
trace-dtrace.dtrace
7 9
*-timestamp
8 10
*-softmmu
9 11
*-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
4 7

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

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

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

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

  
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

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

  
125 146
version.o: $(SRC_PATH)/version.rc config-host.mak
......
157 178
	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
158 179
	rm -f qemu-img-cmds.h
159 180
	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
160 183
	$(MAKE) -C tests clean
161 184
	for d in $(ALL_SUBDIRS) libhw32 libhw64 libuser libdis libdis-user; do \
162 185
	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
289 292
trace-obj-y = trace.o
290 293
ifeq ($(TRACE_BACKEND),simple)
291 294
trace-obj-y += simpletrace.o
292 295
user-obj-y += qemu-timer-common.o
293 296
endif
297
endif
294 298

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

  
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"
932
echo "  --trace-backend=B        Trace backend nop simple ust dtrace"
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

  
2196 2208
##########################################
2197 2209
# End of CC checks
2198 2210
# 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
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