* [Qemu-devel] [PATCH v3 0/6] trace: Generic event state description
@ 2012-02-10 14:28 Lluís Vilanova
2012-02-10 14:28 ` [Qemu-devel] [PATCH v3 1/6] trace: Provide a generic tracing event descriptor Lluís Vilanova
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: Lluís Vilanova @ 2012-02-10 14:28 UTC (permalink / raw)
To: qemu-devel; +Cc: blauwirbel, stefanha
NOTE: Applies on top of the tracetool-handling trivial changes.
Provides a generic event state description and a more detailed event control and
query interface.
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
Changes in v3:
* Add some assertions.
* Remove debugging printf's.
* Improve documentation.
* Make 'trace_event_get_state_static' use run-time information, and leave
TRACE_*_ENABLED for compile-time checks.
Changes in v2:
* Minor compilation fixes.
Lluís Vilanova (6):
trace: Provide a generic tracing event descriptor
trace: Provide a detailed event control interface
trace: [monitor] Use new event control interface
trace: [default] Use new event control interface
trace: [simple] Port to generic event information and new control interface
trace: [stderr] Port to generic event information and new control interface
Makefile | 5 ++
Makefile.objs | 15 ++++-
docs/tracing.txt | 41 +++++--------
monitor.c | 15 ++++-
scripts/tracetool.py | 149 ++++++++++++++++++++++++++++++++--------------
trace/control-internal.h | 60 +++++++++++++++++++
trace/control.c | 92 ++++++++++++++++++++++++++--
trace/control.h | 148 ++++++++++++++++++++++++++++++++++++++++++----
trace/default.c | 3 -
trace/event-internal.h | 28 +++++++++
trace/simple.c | 33 ++--------
trace/simple.h | 6 --
trace/stderr.c | 35 ++---------
trace/stderr.h | 11 ---
14 files changed, 475 insertions(+), 166 deletions(-)
create mode 100644 trace/control-internal.h
create mode 100644 trace/event-internal.h
delete mode 100644 trace/stderr.h
To: qemu-devel@nongnu.org
Cc: Stefan Hajnoczi <stefanha@gmail.com>
Cc: Blue Swirl <blauwirbel@gmail.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH v3 1/6] trace: Provide a generic tracing event descriptor
2012-02-10 14:28 [Qemu-devel] [PATCH v3 0/6] trace: Generic event state description Lluís Vilanova
@ 2012-02-10 14:28 ` Lluís Vilanova
2012-02-10 14:28 ` [Qemu-devel] [PATCH v3 2/6] trace: Provide a detailed event control interface Lluís Vilanova
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Lluís Vilanova @ 2012-02-10 14:28 UTC (permalink / raw)
To: qemu-devel; +Cc: blauwirbel, stefanha
Uses tracetool to generate a backend-independent tracing event description.
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
Makefile | 5 +++
Makefile.objs | 15 +++++++-
scripts/tracetool.py | 94 ++++++++++++++++++++++++++++++++++++++++++++----
trace/event-internal.h | 28 ++++++++++++++
4 files changed, 134 insertions(+), 8 deletions(-)
create mode 100644 trace/event-internal.h
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..31abd21 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
@@ -389,7 +402,7 @@ trace/simple.o: trace/simple.c $(GENERATED_HEADERS)
trace-obj-$(CONFIG_TRACE_DTRACE) += trace-dtrace.o
ifneq ($(TRACE_BACKEND),dtrace)
-trace-obj-y = trace.o
+trace-obj-y += trace.o
endif
trace-nested-$(CONFIG_TRACE_DEFAULT) += default.o
diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index 7053a74..724b595 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,26 @@ 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
+
+@for_backend("nop", "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..d62e82f
--- /dev/null
+++ b/trace/event-internal.h
@@ -0,0 +1,28 @@
+/*
+ * 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"
+
+
+typedef struct TraceEvent {
+ /** 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 */
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH v3 2/6] trace: Provide a detailed event control interface
2012-02-10 14:28 [Qemu-devel] [PATCH v3 0/6] trace: Generic event state description Lluís Vilanova
2012-02-10 14:28 ` [Qemu-devel] [PATCH v3 1/6] trace: Provide a generic tracing event descriptor Lluís Vilanova
@ 2012-02-10 14:28 ` Lluís Vilanova
2012-02-10 14:28 ` [Qemu-devel] [PATCH v3 3/6] trace: [monitor] Use new " Lluís Vilanova
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Lluís Vilanova @ 2012-02-10 14:28 UTC (permalink / raw)
To: qemu-devel; +Cc: blauwirbel, stefanha
This interface decouples event obtention from interaction.
Event can be obtained through three different methods:
* identifier
* name
* simple wildcard pattern
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
docs/tracing.txt | 41 +++++--------
trace/control-internal.h | 60 +++++++++++++++++++
trace/control.c | 92 ++++++++++++++++++++++++++---
trace/control.h | 148 ++++++++++++++++++++++++++++++++++++++++++----
4 files changed, 296 insertions(+), 45 deletions(-)
create mode 100644 trace/control-internal.h
diff --git a/docs/tracing.txt b/docs/tracing.txt
index a92716f..17690f1 100644
--- a/docs/tracing.txt
+++ b/docs/tracing.txt
@@ -100,44 +100,32 @@ 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 file "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-dependant).
-* 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
+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 ==
@@ -268,3 +256,6 @@ 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.
diff --git a/trace/control-internal.h b/trace/control-internal.h
new file mode 100644
index 0000000..81db761
--- /dev/null
+++ b/trace/control-internal.h
@@ -0,0 +1,60 @@
+/*
+ * Interface for configuring and controlling the state of tracing events.
+ *
+ * Copyright (C) 2011, 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.
+ */
+
+
+extern TraceEvent trace_events[];
+
+
+static inline TraceEvent *trace_event_id(TraceEventID id)
+{
+ assert(id < trace_event_count());
+ return &trace_events[id];
+}
+
+static inline TraceEventID trace_event_count(void)
+{
+ return TRACE_EVENT_COUNT;
+}
+
+static inline bool trace_event_is_pattern(const char *str)
+{
+ assert(str != NULL);
+
+ while (*str != '\0') {
+ if (*str == '*') {
+ return true;
+ }
+ str++;
+ }
+ return false;
+}
+
+static inline TraceEventID trace_event_get_id(TraceEvent *ev)
+{
+ assert(ev != NULL);
+ return ev->id;
+}
+
+static inline const char * trace_event_get_name(TraceEvent *ev)
+{
+ assert(ev != NULL);
+ return ev->name;
+}
+
+static inline bool trace_event_get_state_static(TraceEvent *ev)
+{
+ assert(ev != NULL);
+ return ev->sstate;
+}
+
+static inline bool trace_event_get_state_dynamic(TraceEvent *ev)
+{
+ assert(ev != NULL);
+ return ev->dstate;
+}
diff --git a/trace/control.c b/trace/control.c
index 4c5527d..7fbe854 100644
--- a/trace/control.c
+++ b/trace/control.c
@@ -1,15 +1,84 @@
/*
* Interface for configuring and controlling the state of tracing events.
*
- * Copyright (C) 2011 Lluís Vilanova <vilanova@ac.upc.edu>
+ * Copyright (C) 2011, 2012 Lluís Vilanova <vilanova@ac.upc.edu>
*
- * This work is licensed under the terms of the GNU GPL, version 2. See
- * the COPYING file in the top-level directory.
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
*/
#include "trace/control.h"
+TraceEvent *trace_event_name(const char *name)
+{
+ assert(name != NULL);
+
+ TraceEventID i;
+ for (i = 0; i < trace_event_count(); i++) {
+ TraceEvent *ev = trace_event_id(i);
+ if (strcmp(trace_event_get_name(ev), name) == 0) {
+ return ev;
+ }
+ }
+ return NULL;
+}
+
+static inline bool glob(const char *pat, const char *ev)
+{
+ while (*pat != '\0' && *ev != '\0') {
+ if (*pat == *ev) {
+ pat++;
+ ev++;
+ }
+ else if (*pat == '*') {
+ if (glob(pat, ev+1)) {
+ return true;
+ } else if (glob(pat+1, ev)) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ while (*pat == '*') {
+ pat++;
+ }
+
+ if (*pat == '\0' && *ev == '\0') {
+ return true;
+ } else {
+ return false;
+ }
+}
+
+TraceEvent *trace_event_pattern(const char *pat, TraceEvent *ev)
+{
+ assert(pat != NULL);
+
+ TraceEventID i;
+
+ if (ev == NULL) {
+ i = -1;
+ } else {
+ i = trace_event_get_id(ev);
+ }
+ i++;
+
+ while (i < trace_event_count()) {
+ TraceEvent *res = trace_event_id(i);
+ if (glob(pat, trace_event_get_name(res))) {
+ return res;
+ }
+ i++;
+ }
+
+ return NULL;
+}
+
void trace_backend_init_events(const char *fname)
{
if (fname == NULL) {
@@ -27,10 +96,19 @@ void trace_backend_init_events(const char *fname)
size_t len = strlen(line_buf);
if (len > 1) { /* skip empty lines */
line_buf[len - 1] = '\0';
- if (!trace_event_set_state(line_buf, true)) {
- fprintf(stderr,
- "error: trace event '%s' does not exist\n", line_buf);
- exit(1);
+ if (trace_event_is_pattern(line_buf)) {
+ TraceEvent *ev;
+ while ((ev = trace_event_pattern(line_buf, ev)) != NULL) {
+ trace_event_set_state_dynamic(ev, true);
+ }
+ } else {
+ TraceEvent *ev = trace_event_name(line_buf);
+ if (ev == NULL) {
+ fprintf(stderr,
+ "error: trace event '%s' does not exist\n", line_buf);
+ exit(1);
+ }
+ trace_event_set_state_dynamic(ev, true);
}
}
}
diff --git a/trace/control.h b/trace/control.h
index 2acaa42..3b9c6f5 100644
--- a/trace/control.h
+++ b/trace/control.h
@@ -1,41 +1,163 @@
/*
* Interface for configuring and controlling the state of tracing events.
*
- * Copyright (C) 2011 Lluís Vilanova <vilanova@ac.upc.edu>
+ * Copyright (C) 2011, 2012 Lluís Vilanova <vilanova@ac.upc.edu>
*
- * This work is licensed under the terms of the GNU GPL, version 2. See
- * the COPYING file in the top-level directory.
+ * 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_CONTROL_H
-#define TRACE_CONTROL_H
+#ifndef TRACE__CONTROL_H
+#define TRACE__CONTROL_H
#include "qemu-common.h"
+#include "trace-events.h"
-/** Print the state of all events. */
-void trace_print_events(FILE *stream, fprintf_function stream_printf);
-/** Set the state of an event.
+/**
+ * Opaque generic description of a tracing event.
+ */
+struct TraceEvent;
+typedef struct TraceEvent TraceEvent;
+
+/**
+ * TraceEventID - Unique tracing event identifier.
+ *
+ * These are named as 'TRACE_${EVENT_NAME}'.
+ *
+ * See also: trace-events.h
+ */
+
+/**
+ * Get an event by its identifier.
+ *
+ * @id Event identifier.
+ *
+ * @return Pointer to event.
+ *
+ * @pre The identifier is valid.
+ */
+static TraceEvent *trace_event_id(TraceEventID id);
+
+/**
+ * Search an event by its name.
+ *
+ * @id Event name.
+ *
+ * @return Pointer to Event or NULL if not found.
+ */
+TraceEvent *trace_event_name(const char *name);
+
+/**
+ * Get all events with a given name pattern.
+ *
+ * @pat Event name pattern.
+ * @ev Event to start searching from.
+ *
+ * @return Pointer to Event or NULL if not found.
+ */
+TraceEvent *trace_event_pattern(const char *pat, TraceEvent *ev);
+
+/**
+ * Whether the given string is an event name pattern.
+ */
+static bool trace_event_is_pattern(const char *str);
+
+/**
+ * Return the number of events.
+ */
+static TraceEventID trace_event_count(void);
+
+
+
+/**
+ * Get the identifier of an event.
+ */
+static TraceEventID trace_event_get_id(TraceEvent *ev);
+
+/**
+ * Get the name of an event.
+ */
+static const char * trace_event_get_name(TraceEvent *ev);
+
+/**
+ * Get the tracing state of an event (both static and dynamic).
+ *
+ * @id Event identifier.
+ *
+ * If the event has the disabled property, the check will have no performance
+ * impact.
+ *
+ * As a down side, you must always use an immediate TraceEventID value.
+ */
+#define trace_event_get_state(id) \
+ ((id ##_ENABLED) && trace_event_get_state_dynamic(trace_event_id(id)))
+
+/**
+ * Get the static tracing state of an event.
+ *
+ * @id Event identifier.
+ *
+ * Use the define 'TRACE_${EVENT_NAME}_ENABLED' for compile-time checks (it will
+ * be set to 1 or 0 according to the presence of the disabled property).
+ */
+static bool trace_event_get_state_static(TraceEvent *ev);
+
+/**
+ * Get the dynamic tracing state of an event.
+ */
+static bool trace_event_get_state_dynamic(TraceEvent *ev);
+
+/**
+ * Set the tracing state of an event.
+ */
+#define trace_event_set_state(id, state) \
+ do { \
+ if ((id ##_ENABLED)) { \
+ TraceEvent *_e = trace_event_id(id); \
+ trace_event_set_state_dynamic(_e, state); \
+ } \
+ } while (0)
+
+/**
+ * Set the dynamic tracing state of an event.
*
- * @return Whether the state changed.
+ * @warning This function must be implemented by each tracing backend.
*/
-bool trace_event_set_state(const char *name, bool state);
+void trace_event_set_state_dynamic(TraceEvent *ev, bool state);
-/** Initialize the tracing backend.
+
+/**
+ * Print the state of all events.
+ *
+ * @warning This function must be implemented by each tracing backend.
+ *
+ * @todo Should this be moved to generic code?
+ */
+void trace_print_events(FILE *stream, fprintf_function stream_printf);
+
+/**
+ * Initialize the tracing backend.
*
* @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.
* Corresponds to commandline option "-trace file=...".
* @return Whether the backend could be successfully initialized.
+ *
+ * @warning This function must be implemented by each tracing backend.
*/
bool trace_backend_init(const char *events, const char *file);
-/** Generic function to initialize the state of events.
+/**
+ * Generic function to initialize the state of events.
*
* @fname Name of file with events to enable; may be NULL.
*/
void trace_backend_init_events(const char *fname);
-#endif /* TRACE_CONTROL_H */
+
+#include "trace/control-internal.h"
+
+#endif /* TRACE__CONTROL_H */
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH v3 3/6] trace: [monitor] Use new event control interface
2012-02-10 14:28 [Qemu-devel] [PATCH v3 0/6] trace: Generic event state description Lluís Vilanova
2012-02-10 14:28 ` [Qemu-devel] [PATCH v3 1/6] trace: Provide a generic tracing event descriptor Lluís Vilanova
2012-02-10 14:28 ` [Qemu-devel] [PATCH v3 2/6] trace: Provide a detailed event control interface Lluís Vilanova
@ 2012-02-10 14:28 ` Lluís Vilanova
2012-02-10 14:28 ` [Qemu-devel] [PATCH v3 4/6] trace: [default] " Lluís Vilanova
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Lluís Vilanova @ 2012-02-10 14:28 UTC (permalink / raw)
To: qemu-devel; +Cc: blauwirbel, stefanha
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
monitor.c | 15 ++++++++++++---
1 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/monitor.c b/monitor.c
index 5e099bd..010f659 100644
--- a/monitor.c
+++ b/monitor.c
@@ -617,10 +617,19 @@ 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) {
- monitor_printf(mon, "unknown event name \"%s\"\n", tp_name);
+ if (trace_event_is_pattern(tp_name)) {
+ TraceEvent *ev = NULL;
+ while ((ev = trace_event_pattern(tp_name, ev)) != NULL) {
+ trace_event_set_state_dynamic(ev, new_state);
+ }
+ } else {
+ TraceEvent *ev = trace_event_name(tp_name);
+ if (ev == NULL) {
+ monitor_printf(mon, "unknown event name \"%s\"\n", tp_name);
+ } else {
+ trace_event_set_state_dynamic(ev, new_state);
+ }
}
}
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH v3 4/6] trace: [default] Use new event control interface
2012-02-10 14:28 [Qemu-devel] [PATCH v3 0/6] trace: Generic event state description Lluís Vilanova
` (2 preceding siblings ...)
2012-02-10 14:28 ` [Qemu-devel] [PATCH v3 3/6] trace: [monitor] Use new " Lluís Vilanova
@ 2012-02-10 14:28 ` Lluís Vilanova
2012-02-10 14:29 ` [Qemu-devel] [PATCH v3 5/6] trace: [simple] Port to generic event information and new " Lluís Vilanova
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Lluís Vilanova @ 2012-02-10 14:28 UTC (permalink / raw)
To: qemu-devel; +Cc: blauwirbel, stefanha
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
trace/default.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/trace/default.c b/trace/default.c
index c9b27a2..12db18d 100644
--- a/trace/default.c
+++ b/trace/default.c
@@ -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(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)
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH v3 5/6] trace: [simple] Port to generic event information and new control interface
2012-02-10 14:28 [Qemu-devel] [PATCH v3 0/6] trace: Generic event state description Lluís Vilanova
` (3 preceding siblings ...)
2012-02-10 14:28 ` [Qemu-devel] [PATCH v3 4/6] trace: [default] " Lluís Vilanova
@ 2012-02-10 14:29 ` Lluís Vilanova
2012-02-10 14:29 ` [Qemu-devel] [PATCH v3 6/6] trace: [stderr] " Lluís Vilanova
2012-03-14 13:32 ` [Qemu-devel] [PATCH v3 0/6] trace: Generic event state description Lluís Vilanova
6 siblings, 0 replies; 8+ messages in thread
From: Lluís Vilanova @ 2012-02-10 14:29 UTC (permalink / raw)
To: qemu-devel; +Cc: blauwirbel, stefanha
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
scripts/tracetool.py | 29 ++++++++++-------------------
trace/simple.c | 33 ++++++---------------------------
trace/simple.h | 6 +-----
trace/stderr.h | 11 -----------
4 files changed, 17 insertions(+), 62 deletions(-)
delete mode 100644 trace/stderr.h
diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index 724b595..98a8ca8 100755
--- a/scripts/tracetool.py
+++ b/scripts/tracetool.py
@@ -265,28 +265,18 @@ def simple_h(events):
'name': event.name,
'args': event.args
}
- print
- print '#define NR_TRACE_EVENTS %d' % len(events)
- print 'extern TraceEvent trace_list[NR_TRACE_EVENTS];'
@for_backend("simple", "c")
def simple_c(events):
rec_off = 0
- print '#include "trace.h"'
- print '#include "trace/simple.h"'
- print
- print 'TraceEvent trace_list[] = {'
- print
- for event in events:
- print '{.tp_name = "%(name)s", .state=0},' % {
- 'name': event.name
-}
- print
- print '};'
- print
+ print """\
+#include "trace.h"
+#include "trace/control.h"
+#include "trace/simple.h"
+"""
- for num, event in enumerate(events):
- sizes = []
+ for event in events:
+ sizes = ["0"]
for type_, name in event.args:
if type_is_string(type_):
sizes.append("4 + strlen(%s)" % name)
@@ -301,7 +291,8 @@ def simple_c(events):
uint64_t pvar64 __attribute__ ((unused));
uint32_t slen __attribute__ ((unused));
- if (!trace_list[%(event_id)s].state) {
+ bool _state = trace_event_get_state(%(event_id)s);
+ if (!_state) {
return;
}
@@ -310,7 +301,7 @@ def simple_c(events):
''' % {
'name': event.name,
'args': event.args,
- 'event_id': num,
+ 'event_id': "TRACE_" + event.name.upper(),
'sizestr' : sizestr,
}
diff --git a/trace/simple.c b/trace/simple.c
index f5aa3bd..3c99923 100644
--- a/trace/simple.c
+++ b/trace/simple.c
@@ -263,38 +263,17 @@ 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(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;
+ assert(ev != NULL);
+ ev->dstate = state;
}
/* Helper function to create a thread with signals blocked. Use glib's
diff --git a/trace/simple.h b/trace/simple.h
index 671cbeb..6850ac5 100644
--- a/trace/simple.h
+++ b/trace/simple.h
@@ -15,12 +15,8 @@
#include <stdbool.h>
#include <stdio.h>
-typedef uint64_t TraceEventID;
+#include "trace-events.h"
-typedef struct {
- const char *tp_name;
- bool state;
-} TraceEvent;
void st_print_trace(FILE *stream, fprintf_function stream_printf);
void st_print_trace_file_status(FILE *stream, fprintf_function stream_printf);
diff --git a/trace/stderr.h b/trace/stderr.h
deleted file mode 100644
index d575b61..0000000
--- a/trace/stderr.h
+++ /dev/null
@@ -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 */
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH v3 6/6] trace: [stderr] Port to generic event information and new control interface
2012-02-10 14:28 [Qemu-devel] [PATCH v3 0/6] trace: Generic event state description Lluís Vilanova
` (4 preceding siblings ...)
2012-02-10 14:29 ` [Qemu-devel] [PATCH v3 5/6] trace: [simple] Port to generic event information and new " Lluís Vilanova
@ 2012-02-10 14:29 ` Lluís Vilanova
2012-03-14 13:32 ` [Qemu-devel] [PATCH v3 0/6] trace: Generic event state description Lluís Vilanova
6 siblings, 0 replies; 8+ messages in thread
From: Lluís Vilanova @ 2012-02-10 14:29 UTC (permalink / raw)
To: qemu-devel; +Cc: blauwirbel, stefanha
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
scripts/tracetool.py | 26 ++++++++------------------
trace/stderr.c | 35 +++++++----------------------------
2 files changed, 15 insertions(+), 46 deletions(-)
diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index 98a8ca8..a3135b8 100755
--- a/scripts/tracetool.py
+++ b/scripts/tracetool.py
@@ -348,10 +348,10 @@ def simple_c(events):
@for_backend("stderr", "h", "Stderr built-in backend")
def stderr_h(events):
- print '''#include <stdio.h>
-#include "trace/stderr.h"
-
-extern TraceEvent trace_list[];'''
+ print """\
+#include <stdio.h>
+#include "trace/control.h"
+"""
for num, event in enumerate(events):
argnames = ", ".join(event.args.names())
@@ -360,31 +360,21 @@ extern TraceEvent trace_list[];'''
print '''
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': event.name,
'args': event.args,
- 'event_num': num,
+ 'event_id': "TRACE_" + event.name.upper(),
'fmt': event.fmt.rstrip('\n'),
'argnames': argnames
}
- print
- print '#define NR_TRACE_EVENTS %d' % len(events)
@for_backend("stderr", "c")
def stderr_c(events):
- print '''#include "trace.h"
-
-TraceEvent trace_list[] = {
-'''
- for event in events:
- print '{.tp_name = "%(name)s", .state=0},' % {
- 'name': event.name
-}
- print
- print '};'
+ pass
##################################################
diff --git a/trace/stderr.c b/trace/stderr.c
index 0810d6f..3d5f313 100644
--- a/trace/stderr.c
+++ b/trace/stderr.c
@@ -4,40 +4,19 @@
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(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;
+ assert(ev != NULL);
+ ev->dstate = state;
}
bool trace_backend_init(const char *events, const char *file)
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH v3 0/6] trace: Generic event state description
2012-02-10 14:28 [Qemu-devel] [PATCH v3 0/6] trace: Generic event state description Lluís Vilanova
` (5 preceding siblings ...)
2012-02-10 14:29 ` [Qemu-devel] [PATCH v3 6/6] trace: [stderr] " Lluís Vilanova
@ 2012-03-14 13:32 ` Lluís Vilanova
6 siblings, 0 replies; 8+ messages in thread
From: Lluís Vilanova @ 2012-03-14 13:32 UTC (permalink / raw)
To: qemu-devel; +Cc: blauwirbel, stefanha
Lluís Vilanova writes:
> NOTE: Applies on top of the tracetool-handling trivial changes.
> Provides a generic event state description and a more detailed event control and
> query interface.
Please disregard this series; it will be resent after acceptance of the
tracetool rewrite.
Thanks,
Lluis
--
"And it's much the same thing with knowledge, for whenever you learn
something new, the whole world becomes that much richer."
-- The Princess of Pure Reason, as told by Norton Juster in The Phantom
Tollbooth
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2012-03-14 13:33 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-10 14:28 [Qemu-devel] [PATCH v3 0/6] trace: Generic event state description Lluís Vilanova
2012-02-10 14:28 ` [Qemu-devel] [PATCH v3 1/6] trace: Provide a generic tracing event descriptor Lluís Vilanova
2012-02-10 14:28 ` [Qemu-devel] [PATCH v3 2/6] trace: Provide a detailed event control interface Lluís Vilanova
2012-02-10 14:28 ` [Qemu-devel] [PATCH v3 3/6] trace: [monitor] Use new " Lluís Vilanova
2012-02-10 14:28 ` [Qemu-devel] [PATCH v3 4/6] trace: [default] " Lluís Vilanova
2012-02-10 14:29 ` [Qemu-devel] [PATCH v3 5/6] trace: [simple] Port to generic event information and new " Lluís Vilanova
2012-02-10 14:29 ` [Qemu-devel] [PATCH v3 6/6] trace: [stderr] " Lluís Vilanova
2012-03-14 13:32 ` [Qemu-devel] [PATCH v3 0/6] trace: Generic event state description Lluís Vilanova
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).