[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v5 03/20] trace: add trace event iterator APIs
From: |
Daniel P. Berrange |
Subject: |
[Qemu-devel] [PATCH v5 03/20] trace: add trace event iterator APIs |
Date: |
Wed, 28 Sep 2016 14:08:06 +0100 |
Currently methods which want to iterate over trace events,
do so using the trace_event_count() and trace_event_id()
methods. This leaks the concept of a single ID enum to
the callers. There is an alternative trace_event_pattern()
method which can be used in an iteration context, but its
design is stateless, so is not easy to expand it in the
future.
This defines a formal iterator API will provide a future-
proof way of iterating over events.
The iterator is also able to apply a pattern match filter
to events, further removing the need for the pattern
Reviewed-by: Stefan Hajnoczi <address@hidden>
Reviewed-by: Lluís Vilanova <address@hidden>
Signed-off-by: Daniel P. Berrange <address@hidden>
---
trace/control.c | 21 +++++++++++++++++++++
trace/control.h | 27 +++++++++++++++++++++++++++
2 files changed, 48 insertions(+)
diff --git a/trace/control.c b/trace/control.c
index 05d85ac..1a96049 100644
--- a/trace/control.c
+++ b/trace/control.c
@@ -125,6 +125,27 @@ TraceEvent *trace_event_pattern(const char *pat,
TraceEvent *ev)
return NULL;
}
+void trace_event_iter_init(TraceEventIter *iter, const char *pattern)
+{
+ iter->event = 0;
+ iter->pattern = pattern;
+}
+
+TraceEvent *trace_event_iter_next(TraceEventIter *iter)
+{
+ while (iter->event < TRACE_EVENT_COUNT) {
+ TraceEvent *ev = &(trace_events[iter->event]);
+ iter->event++;
+ if (!iter->pattern ||
+ pattern_glob(iter->pattern,
+ trace_event_get_name(ev))) {
+ return ev;
+ }
+ }
+
+ return NULL;
+}
+
void trace_list_events(void)
{
int i;
diff --git a/trace/control.h b/trace/control.h
index 27a16fc..c71b405 100644
--- a/trace/control.h
+++ b/trace/control.h
@@ -13,6 +13,10 @@
#include "qemu-common.h"
#include "trace/generated-events.h"
+typedef struct TraceEventIter {
+ size_t event;
+ const char *pattern;
+} TraceEventIter;
/**
* TraceEventID:
@@ -25,6 +29,29 @@
*/
enum TraceEventID;
+
+/**
+ * trace_event_iter_init:
+ * @iter: the event iterator struct
+ * @pattern: optional pattern to filter events on name
+ *
+ * Initialize the event iterator struct @iter,
+ * optionally using @pattern to filter out events
+ * with non-matching names.
+ */
+void trace_event_iter_init(TraceEventIter *iter, const char *pattern);
+
+/**
+ * trace_event_iter_next:
+ * @iter: the event iterator struct
+ *
+ * Get the next event, if any. When this returns NULL,
+ * the iterator should no longer be used.
+ *
+ * Returns: the next event, or NULL if no more events exist
+ */
+TraceEvent *trace_event_iter_next(TraceEventIter *iter);
+
/**
* trace_event_id:
* @id: Event identifier.
--
2.7.4
- [Qemu-devel] [PATCH v5 00/20] Refactor trace to allow modular build, Daniel P. Berrange, 2016/09/28
- [Qemu-devel] [PATCH v5 02/20] trace: remove double-underscore in event name, Daniel P. Berrange, 2016/09/28
- [Qemu-devel] [PATCH v5 04/20] trace: convert code to use event iterators, Daniel P. Berrange, 2016/09/28
- [Qemu-devel] [PATCH v5 01/20] trace: move colo trace events to net/ sub-directory, Daniel P. Berrange, 2016/09/28
- [Qemu-devel] [PATCH v5 05/20] trace: remove some now unused functions, Daniel P. Berrange, 2016/09/28
- [Qemu-devel] [PATCH v5 03/20] trace: add trace event iterator APIs,
Daniel P. Berrange <=
- [Qemu-devel] [PATCH v5 08/20] trace: break circular dependency in event-internal.h, Daniel P. Berrange, 2016/09/28
- [Qemu-devel] [PATCH v5 06/20] trace: remove global 'uint16 dstate[]' array, Daniel P. Berrange, 2016/09/28
- [Qemu-devel] [PATCH v5 12/20] trace: don't abort qemu if ftrace can't be initialized, Daniel P. Berrange, 2016/09/28
- [Qemu-devel] [PATCH v5 07/20] trace: remove duplicate control.h includes in generated-tracers.h, Daniel P. Berrange, 2016/09/28
- [Qemu-devel] [PATCH v5 09/20] trace: give each trace event a named TraceEvent struct, Daniel P. Berrange, 2016/09/28
- [Qemu-devel] [PATCH v5 11/20] trace: emit name <-> ID mapping in simpletrace header, Daniel P. Berrange, 2016/09/28
- [Qemu-devel] [PATCH v5 14/20] trace: dynamically allocate trace_dstate in CPUState, Daniel P. Berrange, 2016/09/28
- [Qemu-devel] [PATCH v5 10/20] trace: remove the TraceEventID and TraceEventVCPUID enums, Daniel P. Berrange, 2016/09/28