Skip to contentSkip to conversation

Tracing pull request

GIT PULL Applied Stefan Hajnoczi 2 participants 8 messages Jun 9, 2014 – Jun 16, 2014 Kbuild

lore
Share & tools
lore
#0 lore raw

v2:
* Previous version was interleaved with an older pull request and the email thread was a mess. Resending.

The following changes since commit 959e41473f2179850578482052fb73b913bc4e42:

slirp/arp: do not special-case bogus IP addresses (2014-06-09 01:49:28 +0200)

are available in the git repository at:

git://github.com/stefanha/qemu.git tags/tracing-pull-request

for you to fetch changes up to a35d9be622a85d9ad6be5448e78c8a3f95ee5f00:

trace: Replace fprintf with error_report and print location (2014-06-09 15:43:40 +0200)

----------------------------------------------------------------
Tracing pull request

----------------------------------------------------------------
Alexey Kardashevskiy (2):
trace: Replace error with warning if event is not defined
trace: Replace fprintf with error_report and print location

Lluís Vilanova (1):
trace: Multi-backend tracing

Stefan Hajnoczi (2):
trace: add pid field to simpletrace record
simpletrace: add support for trace record pid field

 .travis.yml                           |  8 ++--
 Makefile                              |  4 +-
 Makefile.target                       |  4 +-
 configure                             | 47 ++++++++++---------
 docs/tracing.txt                      |  4 +-
 qemu-io.c                             |  2 +-
 scripts/simpletrace.py                | 26 ++++++-----
 scripts/tracetool.py                  | 43 +++++++++---------
 scripts/tracetool/__init__.py         | 24 +++++-----
 scripts/tracetool/backend/__init__.py | 15 +++---
 trace/Makefile.objs                   | 32 ++++++-------
 trace/control-internal.h              |  4 +-
 trace/control.c                       | 86 +++++++++++++++++++++++++++--------
 trace/control.h                       | 27 ++---------
 trace/default.c                       | 40 ----------------
 trace/ftrace.c                        | 25 +---------
 trace/ftrace.h                        |  5 ++
 trace/simple.c                        | 27 +++--------
 trace/simple.h                        |  1 +
 trace/stderr.c                        | 30 ------------
 vl.c                                  |  4 +-
 21 files changed, 195 insertions(+), 263 deletions(-)
 delete mode 100644 trace/default.c
 delete mode 100644 trace/stderr.c
Signature · 1 line
1.9.3
#1 lore raw

[Qemu-devel] [PULL 1/5] trace: add pid field to simpletrace record

It is useful to know the QEMU process ID when working with traces from multiple VMs. Although the trace filename may contain the pid, tools that aggregate traces or even trace globally need somewhere to record the pid.

There is a reserved field in the trace event header struct that we can use.

It is not necessary to bump the simpletrace file format version number because it has already been incremented for the QEMU 2.1 release cycle in commit "trace: [simple] Bump up log version number".

---
 trace/simple.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
trace/simple.c +6 -2
index bb0b52c..5a2e188 100644
@@ -75,6 +75,7 @@ uint8_t trace_buf[TRACE_BUF_LEN];
 static volatile gint trace_idx;
 static unsigned int writeout_idx;
 static volatile gint dropped_events;
+static uint32_t trace_pid;
 static FILE *trace_fp;
 static char *trace_file_name;
 
@@ -83,7 +84,7 @@ typedef struct {
     uint64_t event; /*   TraceEventID */
     uint64_t timestamp_ns;
     uint32_t length;   /*    in bytes */
-    uint32_t reserved; /*    unused */
+    uint32_t pid;
     uint64_t arguments[];
 } TraceRecord;
 
@@ -190,7 +191,7 @@ static gpointer writeout_thread(gpointer opaque)
             dropped.rec.event = DROPPED_EVENT_ID,
             dropped.rec.timestamp_ns = get_clock();
             dropped.rec.length = sizeof(TraceRecord) + sizeof(uint64_t),
-            dropped.rec.reserved = 0;
+            dropped.rec.pid = trace_pid;
             do {
                 dropped_count = g_atomic_int_get(&dropped_events);
             } while (!g_atomic_int_compare_and_exchange(&dropped_events,
@@ -249,6 +250,7 @@ int trace_record_start(TraceBufferRecord *rec, TraceEventID event, size_t datasi
     rec_off = write_to_buffer(rec_off, &event_u64, sizeof(event_u64));
     rec_off = write_to_buffer(rec_off, &timestamp_ns, sizeof(timestamp_ns));
     rec_off = write_to_buffer(rec_off, &rec_len, sizeof(rec_len));
+    rec_off = write_to_buffer(rec_off, &trace_pid, sizeof(trace_pid));
 
     rec->tbuf_idx = idx;
     rec->rec_off  = (idx + sizeof(TraceRecord)) % TRACE_BUF_LEN;
@@ -414,6 +416,8 @@ bool trace_backend_init(const char *events, const char *file)
 {
     GThread *thread;
 
+    trace_pid = getpid();
+
 #if !GLIB_CHECK_VERSION(2, 31, 0)
     trace_available_cond = g_cond_new();
     trace_empty_cond = g_cond_new();
Signature · 1 line
1.9.3
#2 lore raw

[Qemu-devel] [PULL 2/5] simpletrace: add support for trace record pid field

In reply to Stefan Hajnoczi

Extract the pid field from the trace record and print it.

Change the trace record tuple from:
(event_num, timestamp, arg1, ..., arg6)
to:
(event_num, timestamp, pid, arg1, ..., arg6)

Trace event methods now support 3 prototypes:
1. <event-name>(arg1, arg2, arg3)
2. <event-name>(timestamp, arg1, arg2, arg3)
3. <event-name>(timestamp, pid, arg1, arg2, arg3)

Existing script continue to work without changes, they only know about prototypes 1 and 2.

---
 scripts/simpletrace.py | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)
scripts/simpletrace.py +15 -11
index 800835a..1aa9460 100755
@@ -31,10 +31,10 @@ def read_header(fobj, hfmt):
     return struct.unpack(hfmt, hdr)
 
 def get_record(edict, rechdr, fobj):
-    """Deserialize a trace record from a file into a tuple (event_num, timestamp, arg1, ..., arg6)."""
+    """Deserialize a trace record from a file into a tuple (event_num, timestamp, pid, arg1, ..., arg6)."""
     if rechdr is None:
         return None
-    rec = (rechdr[0], rechdr[1])
+    rec = (rechdr[0], rechdr[1], rechdr[3])
     if rechdr[0] != dropped_event_id:
         event_id = rechdr[0]
         event = edict[event_id]
@@ -54,12 +54,12 @@ def get_record(edict, rechdr, fobj):
 
 
 def read_record(edict, fobj):
-    """Deserialize a trace record from a file into a tuple (event_num, timestamp, arg1, ..., arg6)."""
+    """Deserialize a trace record from a file into a tuple (event_num, timestamp, pid, arg1, ..., arg6)."""
     rechdr = read_header(fobj, rec_header_fmt)
     return get_record(edict, rechdr, fobj) # return tuple of record elements
 
 def read_trace_file(edict, fobj):
-    """Deserialize trace records from a file, yielding record tuples (event_num, timestamp, arg1, ..., arg6)."""
+    """Deserialize trace records from a file, yielding record tuples (event_num, timestamp, pid, arg1, ..., arg6)."""
     header = read_header(fobj, log_header_fmt)
     if header is None or \
        header[0] != header_event_id or \
@@ -127,10 +127,13 @@ def process(events, log, analyzer):
         fn_argcount = len(inspect.getargspec(fn)[0]) - 1
         if fn_argcount == event_argcount + 1:
             # Include timestamp as first argument
-            return lambda _, rec: fn(*rec[1:2 + event_argcount])
+            return lambda _, rec: fn(*((rec[1:2],) + rec[3:3 + event_argcount]))
+        elif fn_argcount == event_argcount + 2:
+            # Include timestamp and pid
+            return lambda _, rec: fn(*rec[1:3 + event_argcount])
         else:
-            # Just arguments, no timestamp
-            return lambda _, rec: fn(*rec[2:2 + event_argcount])
+            # Just arguments, no timestamp or pid
+            return lambda _, rec: fn(*rec[3:3 + event_argcount])
 
     analyzer.begin()
     fn_cache = {}
@@ -162,19 +165,20 @@ if __name__ == '__main__':
             self.last_timestamp = None
 
         def catchall(self, event, rec):
-            i = 1
             timestamp = rec[1]
             if self.last_timestamp is None:
                 self.last_timestamp = timestamp
             delta_ns = timestamp - self.last_timestamp
             self.last_timestamp = timestamp
 
-            fields = [event.name, '%0.3f' % (delta_ns / 1000.0)]
+            fields = [event.name, '%0.3f' % (delta_ns / 1000.0),
+                      'pid=%d' % rec[2]]
+            i = 3
             for type, name in event.args:
                 if is_string(type):
-                    fields.append('%s=%s' % (name, rec[i + 1]))
+                    fields.append('%s=%s' % (name, rec[i]))
                 else:
-                    fields.append('%s=0x%x' % (name, rec[i + 1]))
+                    fields.append('%s=0x%x' % (name, rec[i]))
                 i += 1
             print ' '.join(fields)
 
Signature · 1 line
1.9.3
#3 lore raw

[Qemu-devel] [PULL 3/5] trace: Replace error with warning if event is not defined

In reply to Stefan Hajnoczi

From: Alexey Kardashevskiy <[email protected]>

At the moment QEMU exits if trace point is not defined which makes a developer life harder if he has to switch between branches with different traces implemented.

This replaces error+exit wit WARNING if the tracepoint does not exist or not traceable.

---
 trace/control.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
trace/control.c +7 -7
index 49f61e1..4aa02cf 100644
@@ -112,15 +112,15 @@ void trace_backend_init_events(const char *fname)
                 TraceEvent *ev = trace_event_name(line_ptr);
                 if (ev == NULL) {
                     fprintf(stderr,
-                            "error: trace event '%s' does not exist\n", line_ptr);
-                    exit(1);
-                }
-                if (!trace_event_get_state_static(ev)) {
+                            "WARNING: trace event '%s' does not exist\n",
+                            line_ptr);
+                } else if (!trace_event_get_state_static(ev)) {
                     fprintf(stderr,
-                            "error: trace event '%s' is not traceable\n", line_ptr);
-                    exit(1);
+                            "WARNING: trace event '%s' is not traceable\n",
+                            line_ptr);
+                } else {
+                    trace_event_set_state_dynamic(ev, enable);
                 }
-                trace_event_set_state_dynamic(ev, enable);
             }
         }
     }
Signature · 1 line
1.9.3
#4 lore raw

[Qemu-devel] [PULL 5/5] trace: Replace fprintf with error_report and print location

In reply to Stefan Hajnoczi

From: Alexey Kardashevskiy <[email protected]>

This replaces fprintf(stderr) with error_report.

This moves local variables to the beginning of the function to comply with QEMU's coding style.

---
 trace/control.c | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)
trace/control.c +18 -13
index 45e6604..9631a40 100644
@@ -14,7 +14,7 @@
 #ifdef CONFIG_TRACE_FTRACE
 #include "trace/ftrace.h"
 #endif
-
+#include "qemu/error-report.h"
 
 TraceEvent *trace_event_name(const char *name)
 {
@@ -100,18 +100,24 @@ void trace_print_events(FILE *stream, fprintf_function stream_printf)
 
 static void trace_init_events(const char *fname)
 {
+    Location loc;
+    FILE *fp;
+    char line_buf[1024];
+    size_t line_idx = 0;
+
     if (fname == NULL) {
         return;
     }
 
-    FILE *fp = fopen(fname, "r");
+    loc_push_none(&loc);
+    loc_set_file(fname, 0);
+    fp = fopen(fname, "r");
     if (!fp) {
-        fprintf(stderr, "error: could not open trace events file '%s': %s\n",
-                fname, strerror(errno));
+        error_report("%s", strerror(errno));
         exit(1);
     }
-    char line_buf[1024];
     while (fgets(line_buf, sizeof(line_buf), fp)) {
+        loc_set_file(fname, ++line_idx);
         size_t len = strlen(line_buf);
         if (len > 1) {              /* skip empty lines */
             line_buf[len - 1] = '\0';
@@ -130,13 +136,11 @@ static void trace_init_events(const char *fname)
             } else {
                 TraceEvent *ev = trace_event_name(line_ptr);
                 if (ev == NULL) {
-                    fprintf(stderr,
-                            "WARNING: trace event '%s' does not exist\n",
-                            line_ptr);
+                    error_report("WARNING: trace event '%s' does not exist",
+                                 line_ptr);
                 } else if (!trace_event_get_state_static(ev)) {
-                    fprintf(stderr,
-                            "WARNING: trace event '%s' is not traceable\n",
-                            line_ptr);
+                    error_report("WARNING: trace event '%s' is not traceable\n",
+                                 line_ptr);
                 } else {
                     trace_event_set_state_dynamic(ev, enable);
                 }
@@ -144,10 +148,11 @@ static void trace_init_events(const char *fname)
         }
     }
     if (fclose(fp) != 0) {
-        fprintf(stderr, "error: closing file '%s': %s\n",
-                fname, strerror(errno));
+        loc_set_file(fname, 0);
+        error_report("%s", strerror(errno));
         exit(1);
     }
+    loc_pop(&loc);
 }
 
 bool trace_init_backends(const char *events, const char *file)
Signature · 1 line
1.9.3
#5 lore raw

[Qemu-devel] [PULL 4/5] trace: Multi-backend tracing

In reply to Stefan Hajnoczi

From: Lluís Vilanova <[email protected]>

Adds support to compile QEMU with multiple tracing backends at the same time.

For example, you can compile QEMU with:

  $ ./configure --enable-trace-backends=ftrace,dtrace

Where 'ftrace' can be handy for having an in-flight record of events, and 'dtrace' can be later used to extract more information from the system.

This patch allows having both available without recompiling QEMU.

---
 .travis.yml                           |  8 +++---
 Makefile                              |  4 +--
 Makefile.target                       |  4 +--
 configure                             | 47 ++++++++++++++++-----------------
 docs/tracing.txt                      |  4 +--
 qemu-io.c                             |  2 +-
 scripts/tracetool.py                  | 43 +++++++++++++++---------------
 scripts/tracetool/__init__.py         | 24 ++++++++---------
 scripts/tracetool/backend/__init__.py | 15 ++++++-----
 trace/Makefile.objs                   | 32 +++++++++++------------
 trace/control-internal.h              |  4 +--
 trace/control.c                       | 49 +++++++++++++++++++++++++++++++++--
 trace/control.h                       | 27 +++----------------
 trace/default.c                       | 40 ----------------------------
 trace/ftrace.c                        | 25 +-----------------
 trace/ftrace.h                        |  5 ++++
 trace/simple.c                        | 19 +-------------
 trace/simple.h                        |  1 +
 trace/stderr.c                        | 30 ---------------------
 vl.c                                  |  4 +--
 20 files changed, 153 insertions(+), 234 deletions(-)
 delete mode 100644 trace/default.c
 delete mode 100644 trace/stderr.c
.travis.yml +4 -4
index 04da973..89c30ae 100644
@@ -66,16 +66,16 @@ matrix:
       compiler: gcc
     # All the trace backends (apart from dtrace)
     - env: TARGETS=i386-softmmu,x86_64-softmmu
-           EXTRA_CONFIG="--enable-trace-backend=stderr"
+           EXTRA_CONFIG="--enable-trace-backends=stderr"
       compiler: gcc
     - env: TARGETS=i386-softmmu,x86_64-softmmu
-           EXTRA_CONFIG="--enable-trace-backend=simple"
+           EXTRA_CONFIG="--enable-trace-backends=simple"
       compiler: gcc
     - env: TARGETS=i386-softmmu,x86_64-softmmu
-           EXTRA_CONFIG="--enable-trace-backend=ftrace"
+           EXTRA_CONFIG="--enable-trace-backends=ftrace"
            TEST_CMD=""
       compiler: gcc
     - env: TARGETS=i386-softmmu,x86_64-softmmu
           EXTRA_PKGS="liblttng-ust-dev liburcu-dev"
-          EXTRA_CONFIG="--enable-trace-backend=ust"
+          EXTRA_CONFIG="--enable-trace-backends=ust"
       compiler: gcc
Makefile +2 -2
index d830483..3c8f19c 100644
@@ -52,12 +52,12 @@ GENERATED_HEADERS += trace/generated-events.h
 GENERATED_SOURCES += trace/generated-events.c
 
 GENERATED_HEADERS += trace/generated-tracers.h
-ifeq ($(TRACE_BACKEND),dtrace)
+ifeq ($(findstring dtrace,$(TRACE_BACKENDS)),dtrace)
 GENERATED_HEADERS += trace/generated-tracers-dtrace.h
 endif
 GENERATED_SOURCES += trace/generated-tracers.c
 
-ifeq ($(TRACE_BACKEND),ust)
+ifeq ($(findstring ust,$(TRACE_BACKENDS)),ust)
 GENERATED_HEADERS += trace/generated-ust-provider.h
 GENERATED_SOURCES += trace/generated-ust.c
 endif
Makefile.target +2 -2
index 9986047..8155496 100644
@@ -49,7 +49,7 @@ endif
 $(QEMU_PROG).stp-installed: $(SRC_PATH)/trace-events
 	$(call quiet-command,$(TRACETOOL) \
 		--format=stap \
-		--backend=$(TRACE_BACKEND) \
+		--backends=$(TRACE_BACKENDS) \
 		--binary=$(bindir)/$(QEMU_PROG) \
 		--target-name=$(TARGET_NAME) \
 		--target-type=$(TARGET_TYPE) \
@@ -58,7 +58,7 @@ $(QEMU_PROG).stp-installed: $(SRC_PATH)/trace-events
 $(QEMU_PROG).stp: $(SRC_PATH)/trace-events
 	$(call quiet-command,$(TRACETOOL) \
 		--format=stap \
-		--backend=$(TRACE_BACKEND) \
+		--backends=$(TRACE_BACKENDS) \
 		--binary=$(realpath .)/$(QEMU_PROG) \
 		--target-name=$(TARGET_NAME) \
 		--target-type=$(TARGET_TYPE) \
configure +23 -24

122 lines not on this page · raw message

docs/tracing.txt +2 -2
index bf2e15c..c6ab1c1 100644
@@ -9,7 +9,7 @@ for debugging, profiling, and observing execution.
 
 1. Build with the 'simple' trace backend:
 
-    ./configure --enable-trace-backend=simple
+    ./configure --enable-trace-backends=simple
     make
 
 2. Create a file with the events you want to trace:
@@ -142,7 +142,7 @@ script.
 The trace backend is chosen at configure time and only one trace backend can
 be built into the binary:
 
-    ./configure --trace-backend=simple
+    ./configure --trace-backends=simple
 
 For a list of supported trace backends, try ./configure --help or see below.
 
qemu-io.c +1 -1
index 795cf46..b55a550 100644
@@ -433,7 +433,7 @@ int main(int argc, char **argv)
             }
             break;
         case 'T':
-            if (!trace_backend_init(optarg, NULL)) {
+            if (!trace_init_backends(optarg, NULL)) {
                 exit(1); /* error message will have been printed */
             }
             break;
scripts/tracetool.py +22 -21

100 lines not on this page · raw message

scripts/tracetool/__init__.py +11 -13
index eccf552..e8e8edc 100644
@@ -233,9 +233,9 @@ def try_import(mod_name, attr_name=None, attr_default=None):
         return False, None
 
 
-def generate(fevents, format, backend,
+def generate(fevents, format, backends,
              binary=None, probe_prefix=None):
-    """Generate the output for the given (format, backend) pair.
+    """Generate the output for the given (format, backends) pair.
 
     Parameters
     ----------
@@ -243,8 +243,8 @@ def generate(fevents, format, backend,
         Event description file.
     format : str
         Output format name.
-    backend : str
-        Output backend name.
+    backends : list
+        Output backend names.
     binary : str or None
         See tracetool.backend.dtrace.BINARY.
     probe_prefix : str or None
@@ -258,15 +258,13 @@ def generate(fevents, format, backend,
         raise TracetoolError("format not set")
     if not tracetool.format.exists(format):
         raise TracetoolError("unknown format: %s" % format)
-    format = format.replace("-", "_")
-
-    backend = str(backend)
-    if len(backend) is 0:
-        raise TracetoolError("backend not set")
-    if not tracetool.backend.exists(backend):
-        raise TracetoolError("unknown backend: %s" % backend)
-    backend = backend.replace("-", "_")
-    backend = tracetool.backend.Wrapper(backend, format)
+
+    if len(backends) is 0:
+        raise TracetoolError("no backends specified")
+    for backend in backends:
+        if not tracetool.backend.exists(backend):
+            raise TracetoolError("unknown backend: %s" % backend)
+    backend = tracetool.backend.Wrapper(backends, format)
 
     import tracetool.backend.dtrace
     tracetool.backend.dtrace.BINARY = binary
scripts/tracetool/backend/__init__.py +8 -7
index 5e36f04..5bfa1ef 100644
@@ -99,17 +99,18 @@ def exists(name):
 
 
 class Wrapper:
-    def __init__(self, backend, format):
-        self._backend = backend.replace("-", "_")
+    def __init__(self, backends, format):
+        self._backends = [backend.replace("-", "_") for backend in backends]
         self._format = format.replace("-", "_")
-        assert exists(self._backend)
+        assert all(exists(backend) for backend in self._backends)
         assert tracetool.format.exists(self._format)
 
     def _run_function(self, name, *args, **kwargs):
-        func = tracetool.try_import("tracetool.backend." + self._backend,
-                                    name % self._format, None)[1]
-        if func is not None:
-            func(*args, **kwargs)
+        for backend in self._backends:
+            func = tracetool.try_import("tracetool.backend." + backend,
+                                        name % self._format, None)[1]
+            if func is not None:
+                func(*args, **kwargs)
 
     def generate_begin(self, events):
         self._run_function("generate_%s_begin", events)
trace/Makefile.objs +15 -17
index 6a30467..d7a8696 100644
@@ -3,12 +3,12 @@
 ######################################################################
 # Auto-generated event descriptions for LTTng ust code
 
-ifeq ($(TRACE_BACKEND),ust)
+ifeq ($(findstring ust,$(TRACE_BACKENDS)),ust)
 $(obj)/generated-ust-provider.h: $(obj)/generated-ust-provider.h-timestamp
 $(obj)/generated-ust-provider.h-timestamp: $(SRC_PATH)/trace-events
 	$(call quiet-command,$(TRACETOOL) \
 		--format=ust-events-h \
-		--backend=$(TRACE_BACKEND) \
+		--backends=$(TRACE_BACKENDS) \
 		< $< > $@,"  GEN   $(patsubst %-timestamp,%,$@)")
 	@cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@)
 
@@ -16,7 +16,7 @@ $(obj)/generated-ust.c: $(obj)/generated-ust.c-timestamp $(BUILD_DIR)/config-hos
 $(obj)/generated-ust.c-timestamp: $(SRC_PATH)/trace-events
 	$(call quiet-command,$(TRACETOOL) \
 		--format=ust-events-c \
-		--backend=$(TRACE_BACKEND) \
+		--backends=$(TRACE_BACKENDS) \
 		< $< > $@,"  GEN   $(patsubst %-timestamp,%,$@)")
 	@cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@)
 
@@ -31,7 +31,7 @@ $(obj)/generated-events.h: $(obj)/generated-events.h-timestamp
 $(obj)/generated-events.h-timestamp: $(SRC_PATH)/trace-events
 	$(call quiet-command,$(TRACETOOL) \
 		--format=events-h \
-		--backend=$(TRACE_BACKEND) \
+		--backends=$(TRACE_BACKENDS) \
 		< $< > $@,"  GEN   $(patsubst %-timestamp,%,$@)")
 	@cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@)
 
@@ -39,7 +39,7 @@ $(obj)/generated-events.c: $(obj)/generated-events.c-timestamp $(BUILD_DIR)/conf
 $(obj)/generated-events.c-timestamp: $(SRC_PATH)/trace-events
 	$(call quiet-command,$(TRACETOOL) \
 		--format=events-c \
-		--backend=$(TRACE_BACKEND) \
+		--backends=$(TRACE_BACKENDS) \
 		< $< > $@,"  GEN   $(patsubst %-timestamp,%,$@)")
 	@cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@)
 
@@ -54,23 +54,21 @@ $(obj)/generated-tracers.h: $(obj)/generated-tracers.h-timestamp
 $(obj)/generated-tracers.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
 	$(call quiet-command,$(TRACETOOL) \
 		--format=h \
-		--backend=$(TRACE_BACKEND) \
+		--backends=$(TRACE_BACKENDS) \
 		< $< > $@,"  GEN   $(patsubst %-timestamp,%,$@)")
 
 ######################################################################
 # Auto-generated tracing routines (non-DTrace)
 
-ifneq ($(TRACE_BACKEND),dtrace)
 $(obj)/generated-tracers.c: $(obj)/generated-tracers.c-timestamp
 	@cmp -s $< $@ || cp $< $@
 $(obj)/generated-tracers.c-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
 	$(call quiet-command,$(TRACETOOL) \
 		--format=c \
-		--backend=$(TRACE_BACKEND) \
+		--backends=$(TRACE_BACKENDS) \
 		< $< > $@,"  GEN   $(patsubst %-timestamp,%,$@)")
 
 $(obj)/generated-tracers.o: $(obj)/generated-tracers.c $(obj)/generated-tracers.h
-endif
 
 
 ######################################################################
@@ -79,27 +77,27 @@ endif
 # Normal practice is to name DTrace probe file with a '.d' extension
 # but that gets picked up by QEMU's Makefile as an external dependency
 # rule file. So we use '.dtrace' instead
-ifeq ($(TRACE_BACKEND),dtrace)
-$(obj)/generated-tracers.dtrace: $(obj)/generated-tracers.dtrace-timestamp
-$(obj)/generated-tracers.dtrace-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
+ifeq ($(findstring dtrace,$(TRACE_BACKENDS)),dtrace)
+$(obj)/generated-tracers-dtrace.dtrace: $(obj)/generated-tracers-dtrace.dtrace-timestamp
+$(obj)/generated-tracers-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
 	$(call quiet-command,$(TRACETOOL) \
 		--format=d \
-		--backend=$(TRACE_BACKEND) \
+		--backends=$(TRACE_BACKENDS) \
 		< $< > $@,"  GEN   $(patsubst %-timestamp,%,$@)")
 	@cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@)
 
-$(obj)/generated-tracers-dtrace.h: $(obj)/generated-tracers.dtrace
+$(obj)/generated-tracers-dtrace.h: $(obj)/generated-tracers-dtrace.dtrace
 	$(call quiet-command,dtrace -o $@ -h -s $<, "  GEN   $@")
 
-$(obj)/generated-tracers.o: $(obj)/generated-tracers.dtrace
+$(obj)/generated-tracers-dtrace.o: $(obj)/generated-tracers-dtrace.dtrace
+
+util-obj-y += generated-tracers-dtrace.o
 endif
 
 ######################################################################
 # Backend code
 
-util-obj-$(CONFIG_TRACE_DEFAULT) += default.o
 util-obj-$(CONFIG_TRACE_SIMPLE) += simple.o
-util-obj-$(CONFIG_TRACE_STDERR) += stderr.o
 util-obj-$(CONFIG_TRACE_FTRACE) += ftrace.o
 util-obj-$(CONFIG_TRACE_UST) += generated-ust.o
 util-obj-y += control.o
trace/control-internal.h +2 -2
index b3f587e..5a8df28 100644
@@ -1,7 +1,7 @@
 /*
  * Interface for configuring and controlling the state of tracing events.
  *
- * Copyright (C) 2011-2012 Lluís Vilanova <[email protected]>
+ * Copyright (C) 2011-2014 Lluís Vilanova <[email protected]>
  *
  * This work is licensed under the terms of the GNU GPL, version 2 or later.
  * See the COPYING file in the top-level directory.
@@ -61,7 +61,7 @@ static inline void trace_event_set_state_dynamic(TraceEvent *ev, bool state)
 {
     assert(ev != NULL);
     assert(trace_event_get_state_static(ev));
-    return trace_event_set_state_dynamic_backend(ev, state);
+    ev->dstate = state;
 }
 
 #endif  /* TRACE__CONTROL_INTERNAL_H */
trace/control.c +47 -2

70 lines not on this page · raw message

trace/control.h +4 -23
index cde8260..e1ec033 100644
@@ -1,7 +1,7 @@
 /*
  * Interface for configuring and controlling the state of tracing events.
  *
- * Copyright (C) 2011-2012 Lluís Vilanova <[email protected]>
+ * Copyright (C) 2011-2014 Lluís Vilanova <[email protected]>
  *
  * This work is licensed under the terms of the GNU GPL, version 2 or later.
  * See the COPYING file in the top-level directory.
@@ -146,26 +146,17 @@ static bool trace_event_get_state_dynamic(TraceEvent *ev);
  */
 static void trace_event_set_state_dynamic(TraceEvent *ev, bool state);
 
-/**
- * trace_event_set_state_dynamic_backend:
- *
- * Warning: This function must be implemented by each tracing backend.
- */
-void trace_event_set_state_dynamic_backend(TraceEvent *ev, bool state);
-
 
 
 /**
  * trace_print_events:
  *
  * Print the state of all events.
- *
- * Warning: This function must be implemented by each tracing backend.
  */
 void trace_print_events(FILE *stream, fprintf_function stream_printf);
 
 /**
- * trace_backend_init:
+ * trace_init_backends:
  * @events: Name of file with events to be enabled at startup; may be NULL.
  *          Corresponds to commandline option "-trace events=...".
  * @file:   Name of trace output file; may be NULL.
@@ -173,19 +164,9 @@ void trace_print_events(FILE *stream, fprintf_function stream_printf);
  *
  * Initialize the tracing backend.
  *
- * Warning: This function must be implemented by each tracing backend.
- *
- * Returns: Whether the backend could be successfully initialized.
- */
-bool trace_backend_init(const char *events, const char *file);
-
-/**
- * trace_backend_init_events:
- * @fname: Name of file with events to enable; may be NULL.
- *
- * Generic function to initialize the state of events.
+ * Returns: Whether the backends could be successfully initialized.
  */
-void trace_backend_init_events(const char *fname);
+bool trace_init_backends(const char *events, const char *file);
 
 
 #include "trace/control-internal.h"
trace/default.c deleted +0 -40
deleted file mode 100644
index 6e07a47..0000000
@@ -1,40 +0,0 @@
-/*
- * Default implementation for backend initialization from commandline.
- *
- * Copyright (C) 2011-2012 Lluís Vilanova <[email protected]>
- *
- * This work is licensed under the terms of the GNU GPL, version 2.  See
- * the COPYING file in the top-level directory.
- */
-
-#include "trace/control.h"
-
-
-void trace_print_events(FILE *stream, fprintf_function stream_printf)
-{
-    fprintf(stderr, "warning: "
-            "cannot print the trace events with the current backend\n");
-    stream_printf(stream, "error: "
-                  "operation not supported with the current backend\n");
-}
-
-void trace_event_set_state_dynamic_backend(TraceEvent *ev, bool state)
-{
-    fprintf(stderr, "warning: "
-            "cannot set the state of a trace event with the current backend\n");
-}
-
-bool trace_backend_init(const char *events, const char *file)
-{
-    if (events) {
-        fprintf(stderr, "error: -trace events=...: "
-                "option not supported by the selected tracing backend\n");
-        return false;
-    }
-    if (file) {
-        fprintf(stderr, "error: -trace file=...: "
-                "option not supported by the selected tracing backend\n");
-        return false;
-    }
-    return true;
-}
trace/ftrace.c +1 -24
index 46b7fdb..a7ae371 100644
@@ -42,35 +42,13 @@ static int find_debugfs(char *debugfs)
     return 1;
 }
 
-void trace_print_events(FILE *stream, fprintf_function stream_printf)
-{
-    TraceEventID i;
-
-    for (i = 0; i < trace_event_count(); i++) {
-        TraceEvent *ev = trace_event_id(i);
-        stream_printf(stream, "%s [Event ID %u] : state %u\n",
-                      trace_event_get_name(ev), i, trace_event_get_state_dynamic(ev));
-    }
-}
-
-void trace_event_set_state_dynamic_backend(TraceEvent *ev, bool state)
-{
-    ev->dstate = state;
-}
-
-bool trace_backend_init(const char *events, const char *file)
+bool ftrace_init(void)
 {
     char debugfs[PATH_MAX];
     char path[PATH_MAX];
     int debugfs_found;
     int trace_fd = -1;
 
-    if (file) {
-        fprintf(stderr, "error: -trace file=...: "
-                "option not supported by the selected tracing backend\n");
-        return false;
-    }
-
     debugfs_found = find_debugfs(debugfs);
     if (debugfs_found) {
         snprintf(path, PATH_MAX, "%s/tracing/tracing_on", debugfs);
@@ -97,6 +75,5 @@ bool trace_backend_init(const char *events, const char *file)
         return false;
     }
 
-    trace_backend_init_events(events);
     return true;
 }
trace/ftrace.h +5 -0
index 94cb8d5..863e052 100644
@@ -1,10 +1,15 @@
 #ifndef TRACE_FTRACE_H
 #define TRACE_FTRACE_H
 
+#include <stdbool.h>
+
+
 #define MAX_TRACE_STRLEN 512
 #define _STR(x) #x
 #define STR(x) _STR(x)
 
 extern int trace_marker_fd;
 
+bool ftrace_init(void);
+
 #endif /* ! TRACE_FTRACE_H */
trace/simple.c +1 -18
index 5a2e188..a8f923c 100644
@@ -368,22 +368,6 @@ void st_flush_trace_buffer(void)
     flush_trace_file(true);
 }
 
-void trace_print_events(FILE *stream, fprintf_function stream_printf)
-{
-    unsigned int i;
-
-    for (i = 0; i < trace_event_count(); i++) {
-        TraceEvent *ev = trace_event_id(i);
-        stream_printf(stream, "%s [Event ID %u] : state %u\n",
-                      trace_event_get_name(ev), i, trace_event_get_state_dynamic(ev));
-    }
-}
-
-void trace_event_set_state_dynamic_backend(TraceEvent *ev, bool state)
-{
-    ev->dstate = state;
-}
-
 /* Helper function to create a thread with signals blocked.  Use glib's
  * portable threads since QEMU abstractions cannot be used due to reentrancy in
  * the tracer.  Also note the signal masking on POSIX hosts so that the thread
@@ -412,7 +396,7 @@ static GThread *trace_thread_create(GThreadFunc fn)
     return thread;
 }
 
-bool trace_backend_init(const char *events, const char *file)
+bool st_init(const char *file)
 {
     GThread *thread;
 
@@ -430,7 +414,6 @@ bool trace_backend_init(const char *events, const char *file)
     }
 
     atexit(st_flush_trace_buffer);
-    trace_backend_init_events(events);
     st_set_trace_file(file);
     return true;
 }
trace/simple.h +1 -0
index 5260d9a..6997996 100644
@@ -21,6 +21,7 @@
 void st_print_trace_file_status(FILE *stream, fprintf_function stream_printf);
 void st_set_trace_file_enabled(bool enable);
 bool st_set_trace_file(const char *file);
+bool st_init(const char *file);
 void st_flush_trace_buffer(void);
 
 typedef struct {
trace/stderr.c deleted +0 -30
deleted file mode 100644
index e212efd..0000000
@@ -1,30 +0,0 @@
-#include "trace.h"
-#include "trace/control.h"
-
-
-void trace_print_events(FILE *stream, fprintf_function stream_printf)
-{
-    TraceEventID i;
-
-    for (i = 0; i < trace_event_count(); i++) {
-        TraceEvent *ev = trace_event_id(i);
-        stream_printf(stream, "%s [Event ID %u] : state %u\n",
-                      trace_event_get_name(ev), i, trace_event_get_state_dynamic(ev));
-    }
-}
-
-void trace_event_set_state_dynamic_backend(TraceEvent *ev, bool state)
-{
-    ev->dstate = state;
-}
-
-bool trace_backend_init(const char *events, const char *file)
-{
-    if (file) {
-        fprintf(stderr, "error: -trace file=...: "
-                "option not supported by the selected tracing backend\n");
-        return false;
-    }
-    trace_backend_init_events(events);
-    return true;
-}
vl.c +2 -2
index a3def97..ac0e3d7 100644
@@ -4039,7 +4039,7 @@ int main(int argc, char **argv, char **envp)
     }
 
     if (!is_daemonized()) {
-        if (!trace_backend_init(trace_events, trace_file)) {
+        if (!trace_init_backends(trace_events, trace_file)) {
             exit(1);
         }
     }
@@ -4559,7 +4559,7 @@ int main(int argc, char **argv, char **envp)
     os_setup_post();
 
     if (is_daemonized()) {
-        if (!trace_backend_init(trace_events, trace_file)) {
+        if (!trace_init_backends(trace_events, trace_file)) {
             exit(1);
         }
     }
Signature · 1 line
1.9.3
#7 lore raw
In reply to Stefan Hajnoczi
Quoted 10 lines · Stefan Hajnoczi

v2:
* Previous version was interleaved with an older pull request and the email thread was a mess. Resending.

The following changes since commit 959e41473f2179850578482052fb73b913bc4e42:

slirp/arp: do not special-case bogus IP addresses (2014-06-09 01:49:28 +0200)

are available in the git repository at:

Quoted 8 lines

git://github.com/stefanha/qemu.git tags/tracing-pull-request

for you to fetch changes up to a35d9be622a85d9ad6be5448e78c8a3f95ee5f00:

trace: Replace fprintf with error_report and print location (2014-06-09 15:43:40 +0200)

----------------------------------------------------------------
Tracing pull request

Applied, thanks.

-- PMM

#6 lore raw

Re: [Qemu-devel] [PULL 4/5] trace: Multi-backend tracing

In reply to Stefan Hajnoczi
Quoted 11 lines · Stefan Hajnoczi

From: Lluís Vilanova <[email protected]>

Adds support to compile QEMU with multiple tracing backends at the same time.

For example, you can compile QEMU with:

  $ ./configure --enable-trace-backends=ftrace,dtrace

Where 'ftrace' can be handy for having an in-flight record of events, and 'dtrace' can be later used to extract more information from the system.

This patch allows having both available without recompiling QEMU.

Hi. This patch causes QEMU to fail to do a rebuild unless you do a distclean, because:

* the trace headers are in GENERATED_HEADERS, and so Makefile depends on them
* this means that when Make does its "is any makefile or include out of date and needing a rebuild?" check, as well as possibly running configure (to update config-host.mak) it will also rebuild GENERATED_HEADERS under the "old" config-host.mak regime
* if you run the new trace header rules with an old config-host.mak then the tracetool script will barf (printing its usage message) because it has been passed an empty string for the list of backends.

Paolo suggested that adding
$(GENERATED_HEADERS): config-host.mak

to the makefile might fix this. Unfortunately it doesn't help much, because although it ensures that configure gets run first, make won't reread any of its files (including config-host.mak) until it has rebuilt all of them, so we still run the header rules with the old config-host.mak. It does mean that configure gets run first, so you can guarantee that manually rerunning make will work (without the dependency then the headers might get built first and fail before make gets round to running configure).

thanks
-- PMM