Skip to content

Commit

Permalink
trace: give each trace event a named TraceEvent struct
Browse files Browse the repository at this point in the history
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 _EVENT suffix.

Reviewed-by: Lluís Vilanova <[email protected]>
Reviewed-by: Stefan Hajnoczi <[email protected]>
Signed-off-by: Daniel P. Berrange <[email protected]>
Message-id: [email protected]
Signed-off-by: Stefan Hajnoczi <[email protected]>
  • Loading branch information
berrange authored and stefanhaRH committed Oct 12, 2016
1 parent a82417b commit 79218be
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions scripts/tracetool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ def formats(self):
QEMU_TRACE = "trace_%(name)s"
QEMU_TRACE_TCG = QEMU_TRACE + "_tcg"
QEMU_DSTATE = "_TRACE_%(NAME)s_DSTATE"
QEMU_EVENT = "_TRACE_%(NAME)s_EVENT"

def api(self, fmt=None):
if fmt is None:
Expand Down
19 changes: 13 additions & 6 deletions scripts/tracetool/format/events_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,29 @@ 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 = e.api(e.QEMU_EVENT),
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 = e.api(e.QEMU_EVENT))

out('};',
'')
11 changes: 8 additions & 3 deletions scripts/tracetool/format/events_h.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ 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 %(event)s;',
event = e.api(e.QEMU_EVENT))

# event identifiers
out('typedef enum {')
Expand Down Expand Up @@ -58,6 +64,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 */')
2 changes: 1 addition & 1 deletion trace/control-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "qom/cpu.h"


extern TraceEvent trace_events[];
extern TraceEvent *trace_events[];
extern int trace_events_enabled_count;


Expand Down
2 changes: 1 addition & 1 deletion trace/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 79218be

Please sign in to comment.