Currently we only expose a TraceEvent array, which must be indexed via the TraceEventID enum constants. This changes the generator to expose a named TraceEvent instance for each event, with an _EV suffix.
Signed-off-by: Daniel P. Berrange <berra...@redhat.com> --- scripts/tracetool/format/events_c.py | 20 ++++++++++++++------ scripts/tracetool/format/events_h.py | 10 +++++++--- trace/control-internal.h | 2 +- trace/control.c | 2 +- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/scripts/tracetool/format/events_c.py b/scripts/tracetool/format/events_c.py index ef873fa..5f67a7b 100644 --- a/scripts/tracetool/format/events_c.py +++ b/scripts/tracetool/format/events_c.py @@ -28,22 +28,30 @@ def generate(events, backend): for e in events: out('uint16_t %s;' % e.api(e.QEMU_DSTATE)) - out('TraceEvent trace_events[TRACE_EVENT_COUNT] = {') - for e in events: if "vcpu" in e.properties: vcpu_id = "TRACE_VCPU_" + e.name.upper() else: vcpu_id = "TRACE_VCPU_EVENT_COUNT" - out(' { .id = %(id)s, .vcpu_id = %(vcpu_id)s,' - ' .name = \"%(name)s\",' - ' .sstate = %(sstate)s,', - ' .dstate = &%(dstate)s, }, ', + out('TraceEvent %(event)s = {', + ' .id = %(id)s,', + ' .vcpu_id = %(vcpu_id)s,', + ' .name = \"%(name)s\",', + ' .sstate = %(sstate)s,', + ' .dstate = &%(dstate)s ', + '};', + event = "TRACE_" + e.name.upper() + "_EV", id = "TRACE_" + e.name.upper(), vcpu_id = vcpu_id, name = e.name, sstate = "TRACE_%s_ENABLED" % e.name.upper(), dstate = e.api(e.QEMU_DSTATE)) + out('TraceEvent *trace_events[TRACE_EVENT_COUNT] = {') + + for e in events: + out('&%(event)s,', + event = "TRACE_" + e.name.upper() + "_EV") + out('};', '') diff --git a/scripts/tracetool/format/events_h.py b/scripts/tracetool/format/events_h.py index 03417de..1478e4c 100644 --- a/scripts/tracetool/format/events_h.py +++ b/scripts/tracetool/format/events_h.py @@ -21,7 +21,12 @@ def generate(events, backend): '', '#ifndef TRACE__GENERATED_EVENTS_H', '#define TRACE__GENERATED_EVENTS_H', - '') + '', + '#include "trace/event-internal.h"', + ) + + for e in events: + out('extern TraceEvent TRACE_%s_EV;' % e.name.upper()) # event identifiers out('typedef enum {') @@ -58,6 +63,5 @@ def generate(events, backend): enabled=enabled) out('#define TRACE_%s_ENABLED %d' % (e.name.upper(), enabled)) - out('#include "trace/event-internal.h"', - '', + out('', '#endif /* TRACE__GENERATED_EVENTS_H */') diff --git a/trace/control-internal.h b/trace/control-internal.h index 828c1fc..52b6b72 100644 --- a/trace/control-internal.h +++ b/trace/control-internal.h @@ -15,7 +15,7 @@ #include "qom/cpu.h" -extern TraceEvent trace_events[]; +extern TraceEvent *trace_events[]; extern int trace_events_enabled_count; diff --git a/trace/control.c b/trace/control.c index c681fa0..71ad6ba 100644 --- a/trace/control.c +++ b/trace/control.c @@ -106,7 +106,7 @@ void trace_event_iter_init(TraceEventIter *iter, const char *pattern) TraceEvent *trace_event_iter_next(TraceEventIter *iter) { while (iter->event < TRACE_EVENT_COUNT) { - TraceEvent *ev = &(trace_events[iter->event]); + TraceEvent *ev = trace_events[iter->event]; iter->event++; if (!iter->pattern || pattern_glob(iter->pattern, -- 2.7.4