diff options
-rw-r--r-- | trace/control.c | 21 | ||||
-rw-r--r-- | trace/control.h | 27 |
2 files changed, 48 insertions, 0 deletions
diff --git a/trace/control.c b/trace/control.c index 10b3e9baba..5a9bb5a8c7 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 a22d11242e..36d7cd23ed 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. |