Patchwork [1/6] trace: Provide a generic tracing event descriptor

login
register
mail settings
Submitter Lluís Vilanova
Date Feb. 3, 2012, 9:19 p.m.
Message ID <20120203211930.339.99059.stgit@ginnungagap.bsc.es>
Download mbox | patch
Permalink /patch/139471/
State New
Headers show

Comments

Lluís Vilanova - Feb. 3, 2012, 9:19 p.m.
Uses tracetool to generate a backend-independent tracing event description.

Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
 Makefile               |    5 +++
 Makefile.objs          |   13 +++++++
 scripts/tracetool.py   |   90 ++++++++++++++++++++++++++++++++++++++++++++----
 trace/event-internal.h |   31 +++++++++++++++++
 4 files changed, 132 insertions(+), 7 deletions(-)
 create mode 100644 trace/event-internal.h

Patch

diff --git a/Makefile b/Makefile
index a9f3c7e..13e603c 100644
--- a/Makefile
+++ b/Makefile
@@ -4,9 +4,14 @@ 
 BUILD_DIR=$(CURDIR)
 
 GENERATED_HEADERS = config-host.h trace.h qemu-options.def
+
+GENERATED_HEADERS += trace-events.h
+GENERATED_SOURCES += trace-events.c
+
 ifeq ($(TRACE_BACKEND),dtrace)
 GENERATED_HEADERS += trace-dtrace.h
 endif
+
 GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h
 GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c trace.c
 
diff --git a/Makefile.objs b/Makefile.objs
index e6644c6..194a33d 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -348,6 +348,19 @@  libdis-$(CONFIG_SPARC_DIS) += sparc-dis.o
 ######################################################################
 # trace
 
+trace-events.h: trace-events.h-timestamp
+trace-events.h-timestamp: $(SRC_PATH)/trace-events $(TRACETOOL)
+	$(call tracetool-gen,events-h,events)
+	$(call tracetool-ci)
+
+trace-events.c: trace-events.c-timestamp
+trace-events.c-timestamp: $(SRC_PATH)/trace-events $(TRACETOOL)
+	$(call tracetool-gen,events-c,events)
+	$(call tracetool-ci)
+
+trace-obj-y += trace-events.o
+
+
 ifeq ($(TRACE_BACKEND),dtrace)
 TRACE_H_EXTRA_DEPS=trace-dtrace.h
 endif
diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index 7053a74..91da998 100755
--- a/scripts/tracetool.py
+++ b/scripts/tracetool.py
@@ -118,6 +118,73 @@  def get_backend_descr(backend):
 # formats
 
 ##################################################
+# format: events-h
+
+@for_format("events-h", BEGIN, "Generate .h for event description")
+def process(events):
+    print """\
+/* This file is autogenerated by tracetool, do not edit. */
+
+#ifndef TRACE_EVENTS_H
+#define TRACE_EVENTS_H
+
+#include <stdbool.h>
+"""
+
+    # event identifiers
+    print """
+typedef enum {\
+"""
+    for event in events:
+        print "    TRACE_%s," % event.name.upper()
+    print """\
+    TRACE_EVENT_COUNT
+} TraceEventID;
+"""
+
+    # static state
+    for e in events:
+        if 'disable' in e.properties:
+            enabled = 0
+        else:
+            enabled = 1
+        print "#define TRACE_%s_ENABLED %d" % (e.name.upper(), enabled)
+
+    print """\
+#include "trace/event-internal.h"
+
+#endif  /* TRACE_EVENTS_H */\
+"""
+
+
+##################################################
+# format: events-c
+
+@for_format("events-c", BEGIN, "Generate .h for event description")
+def process(events):
+    print """\
+/* This file is autogenerated by tracetool, do not edit. */
+
+#include "trace.h"
+#include "trace-events.h"
+#include "trace/control.h"
+
+
+TraceEvent trace_events[TRACE_EVENT_COUNT] = {\
+"""
+    for e in events:
+        print """\
+    { .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(),
+        }
+    print """\
+};
+"""
+
+
+##################################################
 # format: h
 
 @for_format("h", BEGIN, "Generate .h file")
@@ -131,13 +198,6 @@  def trace_h_begin(events):
 
 @for_format("h", END)
 def trace_h_end(events):
-    for e in events:
-        if 'disable' in e.properties:
-            enabled = 0
-        else:
-            enabled = 1
-        print "#define TRACE_%s_ENABLED %d" % (e.name.upper(), enabled)
-    print
     print '#endif /* TRACE_H */'
 
 
@@ -154,6 +214,22 @@  def trace_c_begin(events):
 # backends
 
 ##################################################
+# backend: events
+
+@for_backend("events", "events-h", "Generic event description")
+def process(events):
+    pass
+
+@for_backend("nop", "events-h")
+def process(events):
+    pass
+
+@for_backend("events", "events-c")
+def process(events):
+    pass
+
+
+##################################################
 # backend: nop
 
 @for_backend("nop", "h", "Tracing disabled")
diff --git a/trace/event-internal.h b/trace/event-internal.h
new file mode 100644
index 0000000..48f1298
--- /dev/null
+++ b/trace/event-internal.h
@@ -0,0 +1,31 @@ 
+/*
+ * Interface for configuring and controlling the state of tracing events.
+ *
+ * Copyright (C) 2012 Lluís Vilanova <vilanova@ac.upc.edu>
+ *
+ * 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_H
+#define TRACE__EVENT_H
+
+#include "trace-events.h"
+
+
+/**
+ * Generic description of a tracing event.
+ */
+typedef struct {
+    /** Unique event identifier. */
+    TraceEventID id;
+    /** Event name. */
+    const char * name;
+    /** Static instrumentation state. */
+    const bool sstate;
+    /** Dynamic instrumentation state. */
+    bool dstate;
+} TraceEvent;
+
+
+#endif  /* TRACE__EVENT_H */