Skip to content

Commit 45be2f5

Browse files
Lluís VilanovastefanhaRH
Lluís Vilanova
authored andcommitted
trace: Provide a generic tracing event descriptor
Uses tracetool to generate a backend-independent tracing event description (struct TraceEvent). The values for such structure are generated with the non-public "events" backend ("events-c" frontend). The generation of the defines to check if an event is statically enabled is also moved to the "events" backend ("events-h" frontend). Signed-off-by: Lluís Vilanova <[email protected]> Signed-off-by: Stefan Hajnoczi <[email protected]>
1 parent 93fba16 commit 45be2f5

File tree

7 files changed

+172
-9
lines changed

7 files changed

+172
-9
lines changed

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ GENERATED_HEADERS = config-host.h qemu-options.def
3535
GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h
3636
GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c
3737

38+
GENERATED_HEADERS += trace/generated-events.h
39+
GENERATED_SOURCES += trace/generated-events.c
40+
3841
GENERATED_HEADERS += trace/generated-tracers.h
3942
ifeq ($(TRACE_BACKEND),dtrace)
4043
GENERATED_HEADERS += trace/generated-tracers-dtrace.h

scripts/tracetool/backend/events.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
"""
5+
Generic event description.
6+
7+
This is a dummy backend to establish appropriate frontend/backend compatibility
8+
checks.
9+
"""
10+
11+
__author__ = "Lluís Vilanova <[email protected]>"
12+
__copyright__ = "Copyright 2012, Lluís Vilanova <[email protected]>"
13+
__license__ = "GPL version 2 or (at your option) any later version"
14+
15+
__maintainer__ = "Stefan Hajnoczi"
16+
__email__ = "[email protected]"
17+
18+
19+
def events_h(events):
20+
pass
21+
22+
def events_c(events):
23+
pass

scripts/tracetool/format/events_c.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
"""
5+
Generate .c for event description.
6+
"""
7+
8+
__author__ = "Lluís Vilanova <[email protected]>"
9+
__copyright__ = "Copyright 2012, Lluís Vilanova <[email protected]>"
10+
__license__ = "GPL version 2 or (at your option) any later version"
11+
12+
__maintainer__ = "Stefan Hajnoczi"
13+
__email__ = "[email protected]"
14+
15+
16+
from tracetool import out
17+
18+
19+
def begin(events):
20+
out('/* This file is autogenerated by tracetool, do not edit. */',
21+
'',
22+
'#include "trace.h"',
23+
'#include "trace/generated-events.h"',
24+
'#include "trace/control.h"',
25+
'',
26+
)
27+
28+
out('TraceEvent trace_events[TRACE_EVENT_COUNT] = {')
29+
30+
for e in events:
31+
out(' { .id = %(id)s, .name = \"%(name)s\", .sstate = %(sstate)s, .dstate = 0 },',
32+
id = "TRACE_" + e.name.upper(),
33+
name = e.name,
34+
sstate = "TRACE_%s_ENABLED" % e.name.upper(),
35+
)
36+
37+
out('};',
38+
'',
39+
)

scripts/tracetool/format/events_h.py

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
"""
5+
Generate .h for event description.
6+
"""
7+
8+
__author__ = "Lluís Vilanova <[email protected]>"
9+
__copyright__ = "Copyright 2012, Lluís Vilanova <[email protected]>"
10+
__license__ = "GPL version 2 or (at your option) any later version"
11+
12+
__maintainer__ = "Stefan Hajnoczi"
13+
__email__ = "[email protected]"
14+
15+
16+
from tracetool import out
17+
18+
19+
def begin(events):
20+
out('/* This file is autogenerated by tracetool, do not edit. */',
21+
'',
22+
'#ifndef TRACE__GENERATED_EVENTS_H',
23+
'#define TRACE__GENERATED_EVENTS_H',
24+
'',
25+
'#include <stdbool.h>',
26+
''
27+
)
28+
29+
# event identifiers
30+
out('typedef enum {')
31+
32+
for e in events:
33+
out(' TRACE_%s,' % e.name.upper())
34+
35+
out(' TRACE_EVENT_COUNT',
36+
'} TraceEventID;',
37+
)
38+
39+
# static state
40+
for e in events:
41+
if 'disable' in e.properties:
42+
enabled = 0
43+
else:
44+
enabled = 1
45+
out('#define TRACE_%s_ENABLED %d' % (e.name.upper(), enabled))
46+
47+
out('#include "trace/event-internal.h"',
48+
'',
49+
'#endif /* TRACE__GENERATED_EVENTS_H */',
50+
)

scripts/tracetool/format/h.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,7 @@ def begin(events):
2525
'#include "qemu-common.h"')
2626

2727
def end(events):
28-
for e in events:
29-
if "disable" in e.properties:
30-
enabled = 0
31-
else:
32-
enabled = 1
33-
out('#define TRACE_%s_ENABLED %d' % (e.name.upper(), enabled))
34-
out('',
35-
'#endif /* TRACE__GENERATED_TRACERS_H */')
28+
out('#endif /* TRACE__GENERATED_TRACERS_H */')
3629

3730
def nop(events):
3831
for e in events:

trace/Makefile.objs

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
11
# -*- mode: makefile -*-
22

33
######################################################################
4-
# Auto-generated header for tracing routines
4+
# Auto-generated event descriptions
5+
6+
$(obj)/generated-events.h: $(obj)/generated-events.h-timestamp
7+
$(obj)/generated-events.h-timestamp: $(SRC_PATH)/trace-events
8+
$(call quiet-command,$(TRACETOOL) \
9+
--format=events-h \
10+
--backend=events \
11+
< $< > $@," GEN $(patsubst %-timestamp,%,$@)")
12+
@cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@)
13+
14+
$(obj)/generated-events.c: $(obj)/generated-events.c-timestamp
15+
$(obj)/generated-events.c-timestamp: $(SRC_PATH)/trace-events
16+
$(call quiet-command,$(TRACETOOL) \
17+
--format=events-c \
18+
--backend=events \
19+
< $< > $@," GEN $(patsubst %-timestamp,%,$@)")
20+
@cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@)
21+
22+
util-obj-y += generated-events.o
23+
24+
25+
######################################################################
26+
# Auto-generated tracing routines
527

628
$(obj)/generated-tracers.h: $(obj)/generated-tracers.h-timestamp
729
@cmp -s $< $@ || cp $< $@

trace/event-internal.h

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Interface for configuring and controlling the state of tracing events.
3+
*
4+
* Copyright (C) 2012 Lluís Vilanova <[email protected]>
5+
*
6+
* This work is licensed under the terms of the GNU GPL, version 2 or later.
7+
* See the COPYING file in the top-level directory.
8+
*/
9+
10+
#ifndef TRACE__EVENT_INTERNAL_H
11+
#define TRACE__EVENT_INTERNAL_H
12+
13+
#include "trace/generated-events.h"
14+
15+
16+
/**
17+
* TraceEvent:
18+
* @id: Unique event identifier.
19+
* @name: Event name.
20+
* @sstate: Static tracing state.
21+
* @dstate: Dynamic tracing state.
22+
*
23+
* Opaque generic description of a tracing event.
24+
*/
25+
typedef struct TraceEvent {
26+
TraceEventID id;
27+
const char * name;
28+
const bool sstate;
29+
bool dstate;
30+
} TraceEvent;
31+
32+
33+
#endif /* TRACE__EVENT_INTERNAL_H */

0 commit comments

Comments
 (0)