Skip to contentSkip to conversation

Tracing patches

GIT PULL New Stefan Hajnoczi 1 participant 12 messages Mar 28, 2013 Kbuild

lore
Share & tools
lore
#0 lore raw

The following changes since commit e280ff5e9159ed227a117339c1157143627cab96:

spice-qemu-char: Drop hackish vmc_register on spice_chr_write (2013-03-27 10:26:50 -0500)

are available in the git repository at:

git://github.com/stefanha/qemu.git tracing

for you to fetch changes up to 7e8660032cd21c1bdc4160b8fab7deec62e1aa12:

vl: add runstate_set tracepoint (2013-03-28 14:20:58 +0100)

----------------------------------------------------------------
Kazuya Saito (1):
vl: add runstate_set tracepoint

Lluís Vilanova (7):
trace: [tracetool] Explicitly identify public backends
trace: Provide a generic tracing event descriptor
trace: Provide a detailed event control interface
trace: [monitor] Use new event control interface
trace: [default] Port to generic event information and new control interface
trace: [simple] Port to generic event information and new control interface
trace: [stderr] Port to generic event information and new control interface

Stefan Hajnoczi (3):
trace: rebuild generated-events.o when configuration changes .gitignore: add trace/generated-events.[ch] .gitignore: rename trace/generated-tracers.dtrace

 .gitignore                            |   4 +-
 Makefile                              |   3 +
 docs/tracing.txt                      |  44 ++++----
 monitor.c                             |  13 ++-
 scripts/tracetool.py                  |   4 +-
 scripts/tracetool/backend/__init__.py |  16 ++-
 scripts/tracetool/backend/dtrace.py   |   3 +
 scripts/tracetool/backend/events.py   |  23 ++++
 scripts/tracetool/backend/simple.py   |  22 ++--
 scripts/tracetool/backend/stderr.py   |  28 ++---
 scripts/tracetool/backend/ust.py      |   3 +
 scripts/tracetool/format/events_c.py  |  39 +++++++
 scripts/tracetool/format/events_h.py  |  50 +++++++++
 scripts/tracetool/format/h.py         |   9 +-
 trace-events                          |   1 +
 trace/Makefile.objs                   |  24 ++++-
 trace/control-internal.h              |  67 ++++++++++++
 trace/control.c                       | 106 ++++++++++++++++---
 trace/control.h                       | 190 ++++++++++++++++++++++++++++++----
 trace/default.c                       |   5 +-
 trace/event-internal.h                |  33 ++++++
 trace/simple.c                        |  35 ++-----
 trace/simple.h                        |   6 +-
 trace/stderr.c                        |  34 ++----
 trace/stderr.h                        |  11 --
 vl.c                                  |   2 +-
 26 files changed, 595 insertions(+), 180 deletions(-)
 create mode 100644 scripts/tracetool/backend/events.py
 create mode 100644 scripts/tracetool/format/events_c.py
 create mode 100644 scripts/tracetool/format/events_h.py
 create mode 100644 trace/control-internal.h
 create mode 100644 trace/event-internal.h
 delete mode 100644 trace/stderr.h
Signature · 1 line
1.8.1.4
#1 lore raw

PATCH 1/11 trace: [tracetool] Explicitly identify public backends

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

Public backends are those printed by "--list-backends" and thus considered valid by the configure script.

---
 scripts/tracetool.py                  |  4 ++--
 scripts/tracetool/backend/__init__.py | 16 +++++++++++++++-
 scripts/tracetool/backend/dtrace.py   |  3 +++
 scripts/tracetool/backend/simple.py   |  4 ++++
 scripts/tracetool/backend/stderr.py   |  3 +++
 scripts/tracetool/backend/ust.py      |  3 +++
 6 files changed, 30 insertions(+), 3 deletions(-)
scripts/tracetool.py +2 -2
index c003cf6..a79ec0f 100755
@@ -90,8 +90,8 @@ def main(args):
             arg_format = arg
 
         elif opt == "--list-backends":
-            backends = tracetool.backend.get_list()
-            out(", ".join([ b for b,_ in backends ]))
+            public_backends = tracetool.backend.get_list(only_public = True)
+            out(", ".join([ b for b,_ in public_backends ]))
             sys.exit(0)
         elif opt == "--check-backend":
             check_backend = True
scripts/tracetool/backend/__init__.py +15 -1
index be43472..f0314ee 100644
@@ -17,6 +17,16 @@ considered its short description.
 All backends must generate their contents through the 'tracetool.out' routine.
 
 
+Backend attributes
+------------------
+
+========= ====================================================================
+Attribute Description
+========= ====================================================================
+PUBLIC    If exists and is set to 'True', the backend is considered "public".
+========= ====================================================================
+
+
 Backend functions
 -----------------
 
@@ -42,7 +52,7 @@ import os
 import tracetool
 
 
-def get_list():
+def get_list(only_public = False):
     """Get a list of (name, description) pairs."""
     res = [("nop", "Tracing disabled.")]
     modnames = []
@@ -57,6 +67,10 @@ def get_list():
             continue
         module = module[1]
 
+        public = getattr(module, "PUBLIC", False)
+        if only_public and not public:
+            continue
+
         doc = module.__doc__
         if doc is None:
             doc = ""
scripts/tracetool/backend/dtrace.py +3 -0
index ad5eb3b..e31bc79 100644
@@ -16,6 +16,9 @@ __email__      = "[email protected]"
 from tracetool import out
 
 
+PUBLIC = True
+
+
 PROBEPREFIX = None
 
 def _probeprefix():
scripts/tracetool/backend/simple.py +4 -0
index e4b4a7f..ac864f3 100644
@@ -15,6 +15,10 @@ __email__      = "[email protected]"
 
 from tracetool import out
 
+
+PUBLIC = True
+
+
 def is_string(arg):
     strtype = ('const char*', 'char*', 'const char *', 'char *')
     if arg.lstrip().startswith(strtype):
scripts/tracetool/backend/stderr.py +3 -0
index 917fde7..a10fbb8 100644
@@ -16,6 +16,9 @@ __email__      = "[email protected]"
 from tracetool import out
 
 
+PUBLIC = True
+
+
 def c(events):
     out('#include "trace.h"',
         '',
scripts/tracetool/backend/ust.py +3 -0
index 31a2ff0..ea36995 100644
@@ -16,6 +16,9 @@ __email__      = "[email protected]"
 from tracetool import out
 
 
+PUBLIC = True
+
+
 def c(events):
     out('#include <ust/marker.h>',
         '#undef mutex_lock',
Signature · 1 line
1.8.1.4
#2 lore raw

PATCH 2/11 trace: Provide a generic tracing event descriptor

In reply to Stefan Hajnoczi

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

Uses tracetool to generate a backend-independent tracing event description (struct TraceEvent).

The values for such structure are generated with the non-public "events" backend ("events-c" frontend).

The generation of the defines to check if an event is statically enabled is also moved to the "events" backend ("events-h" frontend).

---
 Makefile                             |  3 +++
 scripts/tracetool/backend/events.py  | 23 +++++++++++++++++
 scripts/tracetool/format/events_c.py | 39 ++++++++++++++++++++++++++++
 scripts/tracetool/format/events_h.py | 50 ++++++++++++++++++++++++++++++++++++
 scripts/tracetool/format/h.py        |  9 +------
 trace/Makefile.objs                  | 24 ++++++++++++++++-
 trace/event-internal.h               | 33 ++++++++++++++++++++++++
 7 files changed, 172 insertions(+), 9 deletions(-)
 create mode 100644 scripts/tracetool/backend/events.py
 create mode 100644 scripts/tracetool/format/events_c.py
 create mode 100644 scripts/tracetool/format/events_h.py
 create mode 100644 trace/event-internal.h
Makefile +3 -0
index 6915178..80344d9 100644
@@ -35,6 +35,9 @@ GENERATED_HEADERS = config-host.h qemu-options.def
 GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h
 GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c
 
+GENERATED_HEADERS += trace/generated-events.h
+GENERATED_SOURCES += trace/generated-events.c
+
 GENERATED_HEADERS += trace/generated-tracers.h
 ifeq ($(TRACE_BACKEND),dtrace)
 GENERATED_HEADERS += trace/generated-tracers-dtrace.h
scripts/tracetool/backend/events.py new file +23 -0
new file mode 100644
index 0000000..5afce3e
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+Generic event description.
+
+This is a dummy backend to establish appropriate frontend/backend compatibility
+checks.
+"""
+
+__author__     = "Lluís Vilanova <[email protected]>"
+__copyright__  = "Copyright 2012, Lluís Vilanova <[email protected]>"
+__license__    = "GPL version 2 or (at your option) any later version"
+
+__maintainer__ = "Stefan Hajnoczi"
+__email__      = "[email protected]"
+
+
+def events_h(events):
+    pass
+
+def events_c(events):
+    pass
scripts/tracetool/format/events_c.py new file +39 -0
new file mode 100644
index 0000000..d670ec8
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+Generate .c for event description.
+"""
+
+__author__     = "Lluís Vilanova <[email protected]>"
+__copyright__  = "Copyright 2012, Lluís Vilanova <[email protected]>"
+__license__    = "GPL version 2 or (at your option) any later version"
+
+__maintainer__ = "Stefan Hajnoczi"
+__email__      = "[email protected]"
+
+
+from tracetool import out
+
+
+def begin(events):
+    out('/* This file is autogenerated by tracetool, do not edit. */',
+        '',
+        '#include "trace.h"',
+        '#include "trace/generated-events.h"',
+        '#include "trace/control.h"',
+        '',
+        )
+
+    out('TraceEvent trace_events[TRACE_EVENT_COUNT] = {')
+
+    for e in events:
+        out('    { .id = %(id)s, .name = \"%(name)s\", .sstate = %(sstate)s, .dstate = 0 },',
+            id = "TRACE_" + e.name.upper(),
+            name = e.name,
+            sstate = "TRACE_%s_ENABLED" % e.name.upper(),
+            )
+
+    out('};',
+        '',
+        )
scripts/tracetool/format/events_h.py new file +50 -0

50 lines not on this page · raw message

scripts/tracetool/format/h.py +1 -8
index 9a58de1..93132fc 100644
@@ -25,14 +25,7 @@ def begin(events):
         '#include "qemu-common.h"')
 
 def end(events):
-    for e in events:
-        if "disable" in e.properties:
-            enabled = 0
-        else:
-            enabled = 1
-        out('#define TRACE_%s_ENABLED %d' % (e.name.upper(), enabled))
-    out('',
-        '#endif /* TRACE__GENERATED_TRACERS_H */')
+    out('#endif /* TRACE__GENERATED_TRACERS_H */')
 
 def nop(events):
     for e in events:
trace/Makefile.objs +23 -1
index dde9d57..156aa25 100644
@@ -1,7 +1,29 @@
 # -*- mode: makefile -*-
 
 ######################################################################
-# Auto-generated header for tracing routines
+# Auto-generated event descriptions
+
+$(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=events \
+		< $< > $@,"  GEN   $(patsubst %-timestamp,%,$@)")
+	@cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@)
+
+$(obj)/generated-events.c: $(obj)/generated-events.c-timestamp
+$(obj)/generated-events.c-timestamp: $(SRC_PATH)/trace-events
+	$(call quiet-command,$(TRACETOOL) \
+		--format=events-c \
+		--backend=events \
+		< $< > $@,"  GEN   $(patsubst %-timestamp,%,$@)")
+	@cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@)
+
+util-obj-y += generated-events.o
+
+
+######################################################################
+# Auto-generated tracing routines
 
 $(obj)/generated-tracers.h: $(obj)/generated-tracers.h-timestamp
 	@cmp -s $< $@ || cp $< $@
trace/event-internal.h new file +33 -0
new file mode 100644
index 0000000..b2310d9
@@ -0,0 +1,33 @@
+/*
+ * Interface for configuring and controlling the state of tracing events.
+ *
+ * Copyright (C) 2012 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.
+ */
+
+#ifndef TRACE__EVENT_INTERNAL_H
+#define TRACE__EVENT_INTERNAL_H
+
+#include "trace/generated-events.h"
+
+
+/**
+ * TraceEvent:
+ * @id: Unique event identifier.
+ * @name: Event name.
+ * @sstate: Static tracing state.
+ * @dstate: Dynamic tracing state.
+ *
+ * Opaque generic description of a tracing event.
+ */
+typedef struct TraceEvent {
+    TraceEventID id;
+    const char * name;
+    const bool sstate;
+    bool dstate;
+} TraceEvent;
+
+
+#endif  /* TRACE__EVENT_INTERNAL_H */
Signature · 1 line
1.8.1.4
#3 lore raw

PATCH 3/11 trace: Provide a detailed event control interface

In reply to Stefan Hajnoczi

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

This interface decouples event obtaining from interaction.

Events can be obtained through three different methods:

* identifier
* name
* simple wildcard pattern

---
 docs/tracing.txt         |  44 +++++------
 trace/control-internal.h |  67 +++++++++++++++++
 trace/control.c          | 106 ++++++++++++++++++++++----
 trace/control.h          | 190 ++++++++++++++++++++++++++++++++++++++++++-----
 4 files changed, 349 insertions(+), 58 deletions(-)
 create mode 100644 trace/control-internal.h
docs/tracing.txt +18 -26
index 14db3bf..cf53c17 100644
@@ -100,49 +100,37 @@ respectively.  This ensures portability between 32- and 64-bit platforms.
 
 == Generic interface and monitor commands ==
 
-You can programmatically query and control the dynamic state of trace events
-through a backend-agnostic interface:
+You can programmatically query and control the state of trace events through a
+backend-agnostic interface provided by the header "trace/control.h".
 
-* trace_print_events
+Note that some of the backends do not provide an implementation for some parts
+of this interface, in which case QEMU will just print a warning (please refer to
+header "trace/control.h" to see which routines are backend-dependent).
 
-* trace_event_set_state
-  Enables or disables trace events at runtime inside QEMU.
-  The function returns "true" if the state of the event has been successfully
-  changed, or "false" otherwise:
-
-    #include "trace/control.h"
-    
-    trace_event_set_state("virtio_irq", true); /* enable */
-    [...]
-    trace_event_set_state("virtio_irq", false); /* disable */
-
-Note that some of the backends do not provide an implementation for this
-interface, in which case QEMU will just print a warning.
-
-This functionality is also provided through monitor commands:
+The state of events can also be queried and modified through monitor commands:
 
 * info trace-events
   View available trace events and their state.  State 1 means enabled, state 0
   means disabled.
 
 * trace-event NAME on|off
-  Enable/disable a given trace event or a group of events having common prefix
-  through wildcard.
+  Enable/disable a given trace event or a group of events (using wildcards).
 
 The "-trace events=<file>" command line argument can be used to enable the
 events listed in <file> from the very beginning of the program. This file must
 contain one event name per line.
 
-A basic wildcard matching is supported in both the monitor command "trace
--event" and the events list file. That means you can enable/disable the events
-having a common prefix in a batch. For example, virtio-blk trace events could
-be enabled using:
-  trace-event virtio_blk_* on
-
 If a line in the "-trace events=<file>" file begins with a '-', the trace event
 will be disabled instead of enabled.  This is useful when a wildcard was used
 to enable an entire family of events but one noisy event needs to be disabled.
 
+Wildcard matching is supported in both the monitor command "trace-event" and the
+events list file. That means you can enable/disable the events having a common
+prefix in a batch. For example, virtio-blk trace events could be enabled using
+the following monitor command:
+
+    trace-event virtio_blk_* on
+
 == Trace backends ==
 
 The "tracetool" script automates tedious trace event code generation and also
@@ -263,3 +251,7 @@ guard such computations and avoid its compilation when the event is disabled:
         }
         return ptr;
     }
+
+You can check both if the event has been disabled and is dynamically enabled at
+the same time using the 'trace_event_get_state' routine (see header
+"trace/control.h" for more information).
trace/control-internal.h new file +67 -0

67 lines not on this page · raw message

trace/control.c +93 -13

127 lines not on this page · raw message

trace/control.h +171 -19

212 lines not on this page · raw message

Signature · 1 line
1.8.1.4
#4 lore raw

PATCH 4/11 trace: [monitor] Use new event control interface

In reply to Stefan Hajnoczi

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

---
 monitor.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
monitor.c +11 -2
index 5dfae2a..4ec1db9 100644
@@ -761,9 +761,18 @@ static void do_trace_event_set_state(Monitor *mon, const QDict *qdict)
 {
     const char *tp_name = qdict_get_str(qdict, "name");
     bool new_state = qdict_get_bool(qdict, "option");
-    int ret = trace_event_set_state(tp_name, new_state);
 
-    if (!ret) {
+    bool found = false;
+    TraceEvent *ev = NULL;
+    while ((ev = trace_event_pattern(tp_name, ev)) != NULL) {
+        found = true;
+        if (!trace_event_get_state_static(ev)) {
+            monitor_printf(mon, "event \"%s\" is not traceable\n", tp_name);
+        } else {
+            trace_event_set_state_dynamic(ev, new_state);
+        }
+    }
+    if (!trace_event_is_pattern(tp_name) && !found) {
         monitor_printf(mon, "unknown event name \"%s\"\n", tp_name);
     }
 }
Signature · 1 line
1.8.1.4
#5 lore raw

PATCH 5/11 trace: [default] Port to generic event information and new control interface

In reply to Stefan Hajnoczi

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

---
 trace/default.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
trace/default.c +2 -3
index c9b27a2..6e07a47 100644
@@ -1,7 +1,7 @@
 /*
  * Default implementation for backend initialization from commandline.
  *
- * Copyright (C) 2011 Lluís Vilanova <[email protected]>
+ * 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.
@@ -18,11 +18,10 @@ void trace_print_events(FILE *stream, fprintf_function stream_printf)
                   "operation not supported with the current backend\n");
 }
 
-bool trace_event_set_state(const char *name, bool state)
+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");
-    return false;
 }
 
 bool trace_backend_init(const char *events, const char *file)
Signature · 1 line
1.8.1.4
#6 lore raw

PATCH 6/11 trace: [simple] Port to generic event information and new control interface

In reply to Stefan Hajnoczi

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

The backend is forced to dump event numbers using 64 bits, as TraceEventID is an enum.

---
 scripts/tracetool/backend/simple.py | 18 +++++-------------
 trace/simple.c                      | 35 +++++++----------------------------
 trace/simple.h                      |  6 +-----
 3 files changed, 13 insertions(+), 46 deletions(-)
scripts/tracetool/backend/simple.py +5 -13
index ac864f3..37ef599 100644
@@ -28,17 +28,10 @@ def is_string(arg):
 
 def c(events):
     out('#include "trace.h"',
+        '#include "trace/control.h"',
         '#include "trace/simple.h"',
         '',
-        'TraceEvent trace_list[] = {')
-
-    for e in events:
-        out('{.tp_name = "%(name)s", .state=0},',
-            name = e.name,
-            )
-
-    out('};',
-        '')
+        )
 
     for num, event in enumerate(events):
         out('void trace_%(name)s(%(args)s)',
@@ -63,7 +56,9 @@ def c(events):
 
 
         out('',
-            '    if (!trace_list[%(event_id)s].state) {',
+            '    TraceEvent *eventp = trace_event_id(%(event_id)s);',
+            '    bool _state = trace_event_get_state_dynamic(eventp);',
+            '    if (!_state) {',
             '        return;',
             '    }',
             '',
@@ -106,6 +101,3 @@ def h(events):
             name = event.name,
             args = event.args,
             )
-    out('')
-    out('#define NR_TRACE_EVENTS %d' % len(events))
-    out('extern TraceEvent trace_list[NR_TRACE_EVENTS];')
trace/simple.c +7 -28
index 375d98f..1e3f691 100644
@@ -218,6 +218,7 @@ int trace_record_start(TraceBufferRecord *rec, TraceEventID event, size_t datasi
 {
     unsigned int idx, rec_off, old_idx, new_idx;
     uint32_t rec_len = sizeof(TraceRecord) + datasize;
+    uint64_t event_u64 = event;
     uint64_t timestamp_ns = get_clock();
 
     do {
@@ -235,7 +236,7 @@ int trace_record_start(TraceBufferRecord *rec, TraceEventID event, size_t datasi
     idx = old_idx % TRACE_BUF_LEN;
 
     rec_off = idx;
-    rec_off = write_to_buffer(rec_off, &event, sizeof(event));
+    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));
 
@@ -359,38 +360,16 @@ void trace_print_events(FILE *stream, fprintf_function stream_printf)
 {
     unsigned int i;
 
-    for (i = 0; i < NR_TRACE_EVENTS; 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_list[i].tp_name, i, trace_list[i].state);
+                      trace_event_get_name(ev), i, trace_event_get_state_dynamic(ev));
     }
 }
 
-bool trace_event_set_state(const char *name, bool state)
+void trace_event_set_state_dynamic_backend(TraceEvent *ev, bool state)
 {
-    unsigned int i;
-    unsigned int len;
-    bool wildcard = false;
-    bool matched = false;
-
-    len = strlen(name);
-    if (len > 0 && name[len - 1] == '*') {
-        wildcard = true;
-        len -= 1;
-    }
-    for (i = 0; i < NR_TRACE_EVENTS; i++) {
-        if (wildcard) {
-            if (!strncmp(trace_list[i].tp_name, name, len)) {
-                trace_list[i].state = state;
-                matched = true;
-            }
-            continue;
-        }
-        if (!strcmp(trace_list[i].tp_name, name)) {
-            trace_list[i].state = state;
-            return true;
-        }
-    }
-    return matched;
+    ev->dstate = state;
 }
 
 /* Helper function to create a thread with signals blocked.  Use glib's
trace/simple.h +1 -5
index 2ab96a8..5260d9a 100644
@@ -15,12 +15,8 @@
 #include <stdbool.h>
 #include <stdio.h>
 
-typedef uint64_t TraceEventID;
+#include "trace/generated-events.h"
 
-typedef struct {
-    const char *tp_name;
-    bool state;
-} TraceEvent;
 
 void st_print_trace_file_status(FILE *stream, fprintf_function stream_printf);
 void st_set_trace_file_enabled(bool enable);
Signature · 1 line
1.8.1.4
#7 lore raw

PATCH 7/11 trace: [stderr] Port to generic event information and new control interface

In reply to Stefan Hajnoczi

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

---
 scripts/tracetool/backend/stderr.py | 27 ++++++++-------------------
 trace/stderr.c                      | 34 ++++++----------------------------
 trace/stderr.h                      | 11 -----------
 3 files changed, 14 insertions(+), 58 deletions(-)
 delete mode 100644 trace/stderr.h
scripts/tracetool/backend/stderr.py +8 -19
index a10fbb8..6f93dbd 100644
@@ -20,40 +20,29 @@ PUBLIC = True
 
 
 def c(events):
-    out('#include "trace.h"',
-        '',
-        'TraceEvent trace_list[] = {')
-
-    for e in events:
-        out('{.tp_name = "%(name)s", .state=0},',
-            name = e.name,
-            )
-
-    out('};')
+    pass
 
 def h(events):
     out('#include <stdio.h>',
-        '#include "trace/stderr.h"',
+        '#include "trace/control.h"',
         '',
-        'extern TraceEvent trace_list[];')
+        )
 
-    for num, e in enumerate(events):
+    for e in events:
         argnames = ", ".join(e.args.names())
         if len(e.args) > 0:
             argnames = ", " + argnames
 
         out('static inline void trace_%(name)s(%(args)s)',
             '{',
-            '    if (trace_list[%(event_num)s].state != 0) {',
+            '    bool _state = trace_event_get_state(%(event_id)s);',
+            '    if (_state) {',
             '        fprintf(stderr, "%(name)s " %(fmt)s "\\n" %(argnames)s);',
             '    }',
             '}',
             name = e.name,
             args = e.args,
-            event_num = num,
-            fmt = e.fmt,
+            event_id = "TRACE_" + e.name.upper(),
+            fmt = e.fmt.rstrip("\n"),
             argnames = argnames,
             )
-
-    out('',
-        '#define NR_TRACE_EVENTS %d' % len(events))
trace/stderr.c +6 -28
index 0810d6f..e212efd 100644
@@ -4,40 +4,18 @@
 
 void trace_print_events(FILE *stream, fprintf_function stream_printf)
 {
-    unsigned int i;
+    TraceEventID i;
 
-    for (i = 0; i < NR_TRACE_EVENTS; 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_list[i].tp_name, i, trace_list[i].state);
+                      trace_event_get_name(ev), i, trace_event_get_state_dynamic(ev));
     }
 }
 
-bool trace_event_set_state(const char *name, bool state)
+void trace_event_set_state_dynamic_backend(TraceEvent *ev, bool state)
 {
-    unsigned int i;
-    unsigned int len;
-    bool wildcard = false;
-    bool matched = false;
-
-    len = strlen(name);
-    if (len > 0 && name[len - 1] == '*') {
-        wildcard = true;
-        len -= 1;
-    }
-    for (i = 0; i < NR_TRACE_EVENTS; i++) {
-        if (wildcard) {
-            if (!strncmp(trace_list[i].tp_name, name, len)) {
-                trace_list[i].state = state;
-                matched = true;
-            }
-            continue;
-        }
-        if (!strcmp(trace_list[i].tp_name, name)) {
-            trace_list[i].state = state;
-            return true;
-        }
-    }
-    return matched;
+    ev->dstate = state;
 }
 
 bool trace_backend_init(const char *events, const char *file)
trace/stderr.h deleted +0 -11
deleted file mode 100644
index d575b61..0000000
@@ -1,11 +0,0 @@
-#ifndef TRACE_STDERR_H
-#define TRACE_STDERR_H
-
-typedef uint64_t TraceEventID;
-
-typedef struct {
-    const char *tp_name;
-    bool state;
-} TraceEvent;
-
-#endif /* ! TRACE_STDERR_H */
Signature · 1 line
1.8.1.4
#8 lore raw

PATCH 8/11 trace: rebuild generated-events.o when configuration changes

In reply to Stefan Hajnoczi

Make sure to rebuild generated-events.o when ./configure options change. This prevents linker errors when a stale generated-events.o gets linked with code compiled against fresh headers. For example, try building with ./configure --enable-trace-backend=stderr followed by ./configure --enable-trace-backend=dtrace.

---
 trace/Makefile.objs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
trace/Makefile.objs +1 -1
index 156aa25..a043072 100644
@@ -11,7 +11,7 @@ $(obj)/generated-events.h-timestamp: $(SRC_PATH)/trace-events
 		< $< > $@,"  GEN   $(patsubst %-timestamp,%,$@)")
 	@cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@)
 
-$(obj)/generated-events.c: $(obj)/generated-events.c-timestamp
+$(obj)/generated-events.c: $(obj)/generated-events.c-timestamp $(BUILD_DIR)/config-host.mak
 $(obj)/generated-events.c-timestamp: $(SRC_PATH)/trace-events
 	$(call quiet-command,$(TRACETOOL) \
 		--format=events-c \
Signature · 1 line
1.8.1.4
#9 lore raw

PATCH 9/11 .gitignore: add trace/generated-events.[ch]

In reply to Stefan Hajnoczi

Don't display autogenerated files in git-status(1).

---
 .gitignore | 2 ++
 1 file changed, 2 insertions(+)
.gitignore +2 -0
index 9c234a3..c0238aa 100644
@@ -7,6 +7,8 @@ trace/generated-tracers.h
 trace/generated-tracers.c
 trace/generated-tracers-dtrace.h
 trace/generated-tracers-dtrace.dtrace
+trace/generated-events.h
+trace/generated-events.c
 libcacard/trace/generated-tracers.c
 *-timestamp
 *-softmmu
Signature · 1 line
1.8.1.4
#10 lore raw

PATCH 10/11 .gitignore: rename trace/generated-tracers.dtrace

In reply to Stefan Hajnoczi

For a while the file was called trace/generated-tracers-dtrace.dtrace but today it's called trace/generated-tracers.dtrace.

---
 .gitignore | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
.gitignore +1 -1
index c0238aa..487813a 100644
@@ -6,7 +6,7 @@ config-target.*
 trace/generated-tracers.h
 trace/generated-tracers.c
 trace/generated-tracers-dtrace.h
-trace/generated-tracers-dtrace.dtrace
+trace/generated-tracers.dtrace
 trace/generated-events.h
 trace/generated-events.c
 libcacard/trace/generated-tracers.c
Signature · 1 line
1.8.1.4
#11 lore raw

PATCH 11/11 vl: add runstate_set tracepoint

In reply to Stefan Hajnoczi

From: Kazuya Saito <[email protected]>

This patch enables us to know RunState transition. It will be userful for investigation when the trouble occured in special event such like live migration, shutdown, suspend, and so on.

---
 trace-events | 1 +
 vl.c         | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
trace-events +1 -0
index 406fe5f..85dd49c 100644
@@ -474,6 +474,7 @@ scsi_request_sense(int target, int lun, int tag) "target %d lun %d tag %d"
 # vl.c
 vm_state_notify(int running, int reason) "running %d reason %d"
 load_file(const char *name, const char *path) "name %s location %s"
+runstate_set(int new_state) "new state %d"
 
 # block/qcow2.c
 qcow2_writev_start_req(void *co, int64_t sector, int nb_sectors) "co %p sector %" PRIx64 " nb_sectors %d"
vl.c +1 -1
index 7643f16..770cb7f 100644
@@ -642,7 +642,7 @@ void runstate_set(RunState new_state)
                 RunState_lookup[new_state]);
         abort();
     }
-
+    trace_runstate_set(new_state);
     current_run_state = new_state;
 }
 
Signature · 1 line
1.8.1.4