* [Qemu-devel] [PULL 1/5] trace: add pid field to simpletrace record
2014-06-09 13:45 [Qemu-devel] [PULL 0/5] Tracing patches Stefan Hajnoczi
@ 2014-06-09 13:45 ` Stefan Hajnoczi
2014-06-09 13:45 ` [Qemu-devel] [PULL 1/9] trace: [tracetool] Add method 'Event.api' to build event names Stefan Hajnoczi
` (13 subsequent siblings)
14 siblings, 0 replies; 21+ messages in thread
From: Stefan Hajnoczi @ 2014-06-09 13:45 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Stefan Hajnoczi
It is useful to know the QEMU process ID when working with traces from
multiple VMs. Although the trace filename may contain the pid, tools
that aggregate traces or even trace globally need somewhere to record
the pid.
There is a reserved field in the trace event header struct that we can
use.
It is not necessary to bump the simpletrace file format version number
because it has already been incremented for the QEMU 2.1 release cycle
in commit "trace: [simple] Bump up log version number".
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
trace/simple.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/trace/simple.c b/trace/simple.c
index bb0b52c..5a2e188 100644
--- a/trace/simple.c
+++ b/trace/simple.c
@@ -75,6 +75,7 @@ uint8_t trace_buf[TRACE_BUF_LEN];
static volatile gint trace_idx;
static unsigned int writeout_idx;
static volatile gint dropped_events;
+static uint32_t trace_pid;
static FILE *trace_fp;
static char *trace_file_name;
@@ -83,7 +84,7 @@ typedef struct {
uint64_t event; /* TraceEventID */
uint64_t timestamp_ns;
uint32_t length; /* in bytes */
- uint32_t reserved; /* unused */
+ uint32_t pid;
uint64_t arguments[];
} TraceRecord;
@@ -190,7 +191,7 @@ static gpointer writeout_thread(gpointer opaque)
dropped.rec.event = DROPPED_EVENT_ID,
dropped.rec.timestamp_ns = get_clock();
dropped.rec.length = sizeof(TraceRecord) + sizeof(uint64_t),
- dropped.rec.reserved = 0;
+ dropped.rec.pid = trace_pid;
do {
dropped_count = g_atomic_int_get(&dropped_events);
} while (!g_atomic_int_compare_and_exchange(&dropped_events,
@@ -249,6 +250,7 @@ int trace_record_start(TraceBufferRecord *rec, TraceEventID event, size_t datasi
rec_off = write_to_buffer(rec_off, &event_u64, sizeof(event_u64));
rec_off = write_to_buffer(rec_off, ×tamp_ns, sizeof(timestamp_ns));
rec_off = write_to_buffer(rec_off, &rec_len, sizeof(rec_len));
+ rec_off = write_to_buffer(rec_off, &trace_pid, sizeof(trace_pid));
rec->tbuf_idx = idx;
rec->rec_off = (idx + sizeof(TraceRecord)) % TRACE_BUF_LEN;
@@ -414,6 +416,8 @@ bool trace_backend_init(const char *events, const char *file)
{
GThread *thread;
+ trace_pid = getpid();
+
#if !GLIB_CHECK_VERSION(2, 31, 0)
trace_available_cond = g_cond_new();
trace_empty_cond = g_cond_new();
--
1.9.3
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [Qemu-devel] [PULL 1/9] trace: [tracetool] Add method 'Event.api' to build event names
2014-06-09 13:45 [Qemu-devel] [PULL 0/5] Tracing patches Stefan Hajnoczi
2014-06-09 13:45 ` [Qemu-devel] [PULL 1/5] trace: add pid field to simpletrace record Stefan Hajnoczi
@ 2014-06-09 13:45 ` Stefan Hajnoczi
2014-06-09 13:45 ` [Qemu-devel] [PULL 2/5] simpletrace: add support for trace record pid field Stefan Hajnoczi
` (12 subsequent siblings)
14 siblings, 0 replies; 21+ messages in thread
From: Stefan Hajnoczi @ 2014-06-09 13:45 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Lluís Vilanova, Stefan Hajnoczi
From: Lluís Vilanova <vilanova@ac.upc.edu>
Makes it easier to ensure proper naming across the different frontends and backends.
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
scripts/tracetool/__init__.py | 10 +++++++++-
scripts/tracetool/backend/dtrace.py | 6 +++---
scripts/tracetool/backend/simple.py | 10 +++++-----
scripts/tracetool/backend/stderr.py | 5 +++--
scripts/tracetool/backend/ust.py | 7 ++++---
scripts/tracetool/format/h.py | 6 +++---
6 files changed, 27 insertions(+), 17 deletions(-)
diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
index 175df08..305b99e 100644
--- a/scripts/tracetool/__init__.py
+++ b/scripts/tracetool/__init__.py
@@ -6,7 +6,7 @@ Machinery for generating tracing-related intermediate files.
"""
__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
-__copyright__ = "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>"
+__copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
__license__ = "GPL version 2 or (at your option) any later version"
__maintainer__ = "Stefan Hajnoczi"
@@ -173,6 +173,14 @@ class Event(object):
self.args,
self.fmt)
+ QEMU_TRACE = "trace_%(name)s"
+
+ def api(self, fmt=None):
+ if fmt is None:
+ fmt = Event.QEMU_TRACE
+ return fmt % {"name": self.name}
+
+
def _read_events(fobj):
res = []
for line in fobj:
diff --git a/scripts/tracetool/backend/dtrace.py b/scripts/tracetool/backend/dtrace.py
index e31bc79..3c369c4 100644
--- a/scripts/tracetool/backend/dtrace.py
+++ b/scripts/tracetool/backend/dtrace.py
@@ -6,7 +6,7 @@ DTrace/SystemTAP backend.
"""
__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
-__copyright__ = "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>"
+__copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
__license__ = "GPL version 2 or (at your option) any later version"
__maintainer__ = "Stefan Hajnoczi"
@@ -44,10 +44,10 @@ def h(events):
'')
for e in events:
- out('static inline void trace_%(name)s(%(args)s) {',
+ out('static inline void %(api)s(%(args)s) {',
' QEMU_%(uppername)s(%(argnames)s);',
'}',
- name = e.name,
+ api = e.api(),
args = e.args,
uppername = e.name.upper(),
argnames = ", ".join(e.args.names()),
diff --git a/scripts/tracetool/backend/simple.py b/scripts/tracetool/backend/simple.py
index 3dde372..ca48e12 100644
--- a/scripts/tracetool/backend/simple.py
+++ b/scripts/tracetool/backend/simple.py
@@ -6,7 +6,7 @@ Simple built-in backend.
"""
__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
-__copyright__ = "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>"
+__copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
__license__ = "GPL version 2 or (at your option) any later version"
__maintainer__ = "Stefan Hajnoczi"
@@ -34,10 +34,10 @@ def c(events):
)
for num, event in enumerate(events):
- out('void trace_%(name)s(%(args)s)',
+ out('void %(api)s(%(args)s)',
'{',
' TraceBufferRecord rec;',
- name = event.name,
+ api = event.api(),
args = event.args,
)
sizes = []
@@ -95,7 +95,7 @@ def c(events):
def h(events):
for event in events:
- out('void trace_%(name)s(%(args)s);',
- name = event.name,
+ out('void %(api)s(%(args)s);',
+ api = event.api(),
args = event.args,
)
diff --git a/scripts/tracetool/backend/stderr.py b/scripts/tracetool/backend/stderr.py
index 6f93dbd..6681e26 100644
--- a/scripts/tracetool/backend/stderr.py
+++ b/scripts/tracetool/backend/stderr.py
@@ -6,7 +6,7 @@ Stderr built-in backend.
"""
__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
-__copyright__ = "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>"
+__copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
__license__ = "GPL version 2 or (at your option) any later version"
__maintainer__ = "Stefan Hajnoczi"
@@ -33,13 +33,14 @@ def h(events):
if len(e.args) > 0:
argnames = ", " + argnames
- out('static inline void trace_%(name)s(%(args)s)',
+ out('static inline void %(api)s(%(args)s)',
'{',
' bool _state = trace_event_get_state(%(event_id)s);',
' if (_state) {',
' fprintf(stderr, "%(name)s " %(fmt)s "\\n" %(argnames)s);',
' }',
'}',
+ api = e.api(),
name = e.name,
args = e.args,
event_id = "TRACE_" + e.name.upper(),
diff --git a/scripts/tracetool/backend/ust.py b/scripts/tracetool/backend/ust.py
index 41c1c75..2fca4d2 100644
--- a/scripts/tracetool/backend/ust.py
+++ b/scripts/tracetool/backend/ust.py
@@ -6,7 +6,7 @@ LTTng User Space Tracing backend.
"""
__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
-__copyright__ = "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>"
+__copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
__license__ = "GPL version 2 or (at your option) any later version"
__maintainer__ = "Stefan Hajnoczi"
@@ -31,11 +31,12 @@ def h(events):
if len(e.args) > 0:
argnames = ", " + argnames
- out('static inline void trace_%(name)s(%(args)s)',
+ out('static inline void %(api)s(%(args)s)',
'{',
' tracepoint(qemu, %(name)s%(tp_args)s);',
'}',
'',
+ api = e.api()
name = e.name,
args = e.args,
tp_args = argnames,
@@ -79,4 +80,4 @@ def ust_events_h(events):
')',
'',
name = e.name,
- )
\ No newline at end of file
+ )
diff --git a/scripts/tracetool/format/h.py b/scripts/tracetool/format/h.py
index 93132fc..9b0903d 100644
--- a/scripts/tracetool/format/h.py
+++ b/scripts/tracetool/format/h.py
@@ -6,7 +6,7 @@ Generate .h file.
"""
__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
-__copyright__ = "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>"
+__copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
__license__ = "GPL version 2 or (at your option) any later version"
__maintainer__ = "Stefan Hajnoczi"
@@ -30,9 +30,9 @@ def end(events):
def nop(events):
for e in events:
out('',
- 'static inline void trace_%(name)s(%(args)s)',
+ 'static inline void %(api)s(%(args)s)',
'{',
'}',
- name = e.name,
+ api = e.api(),
args = e.args,
)
--
1.9.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [Qemu-devel] [PULL 2/5] simpletrace: add support for trace record pid field
2014-06-09 13:45 [Qemu-devel] [PULL 0/5] Tracing patches Stefan Hajnoczi
2014-06-09 13:45 ` [Qemu-devel] [PULL 1/5] trace: add pid field to simpletrace record Stefan Hajnoczi
2014-06-09 13:45 ` [Qemu-devel] [PULL 1/9] trace: [tracetool] Add method 'Event.api' to build event names Stefan Hajnoczi
@ 2014-06-09 13:45 ` Stefan Hajnoczi
2014-06-09 13:45 ` [Qemu-devel] [PULL 2/9] trace: [tracetool] Add methods 'Event.copy' and 'Arguments.copy' Stefan Hajnoczi
` (11 subsequent siblings)
14 siblings, 0 replies; 21+ messages in thread
From: Stefan Hajnoczi @ 2014-06-09 13:45 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Stefan Hajnoczi
Extract the pid field from the trace record and print it.
Change the trace record tuple from:
(event_num, timestamp, arg1, ..., arg6)
to:
(event_num, timestamp, pid, arg1, ..., arg6)
Trace event methods now support 3 prototypes:
1. <event-name>(arg1, arg2, arg3)
2. <event-name>(timestamp, arg1, arg2, arg3)
3. <event-name>(timestamp, pid, arg1, arg2, arg3)
Existing script continue to work without changes, they only know about
prototypes 1 and 2.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
scripts/simpletrace.py | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py
index 800835a..1aa9460 100755
--- a/scripts/simpletrace.py
+++ b/scripts/simpletrace.py
@@ -31,10 +31,10 @@ def read_header(fobj, hfmt):
return struct.unpack(hfmt, hdr)
def get_record(edict, rechdr, fobj):
- """Deserialize a trace record from a file into a tuple (event_num, timestamp, arg1, ..., arg6)."""
+ """Deserialize a trace record from a file into a tuple (event_num, timestamp, pid, arg1, ..., arg6)."""
if rechdr is None:
return None
- rec = (rechdr[0], rechdr[1])
+ rec = (rechdr[0], rechdr[1], rechdr[3])
if rechdr[0] != dropped_event_id:
event_id = rechdr[0]
event = edict[event_id]
@@ -54,12 +54,12 @@ def get_record(edict, rechdr, fobj):
def read_record(edict, fobj):
- """Deserialize a trace record from a file into a tuple (event_num, timestamp, arg1, ..., arg6)."""
+ """Deserialize a trace record from a file into a tuple (event_num, timestamp, pid, arg1, ..., arg6)."""
rechdr = read_header(fobj, rec_header_fmt)
return get_record(edict, rechdr, fobj) # return tuple of record elements
def read_trace_file(edict, fobj):
- """Deserialize trace records from a file, yielding record tuples (event_num, timestamp, arg1, ..., arg6)."""
+ """Deserialize trace records from a file, yielding record tuples (event_num, timestamp, pid, arg1, ..., arg6)."""
header = read_header(fobj, log_header_fmt)
if header is None or \
header[0] != header_event_id or \
@@ -127,10 +127,13 @@ def process(events, log, analyzer):
fn_argcount = len(inspect.getargspec(fn)[0]) - 1
if fn_argcount == event_argcount + 1:
# Include timestamp as first argument
- return lambda _, rec: fn(*rec[1:2 + event_argcount])
+ return lambda _, rec: fn(*((rec[1:2],) + rec[3:3 + event_argcount]))
+ elif fn_argcount == event_argcount + 2:
+ # Include timestamp and pid
+ return lambda _, rec: fn(*rec[1:3 + event_argcount])
else:
- # Just arguments, no timestamp
- return lambda _, rec: fn(*rec[2:2 + event_argcount])
+ # Just arguments, no timestamp or pid
+ return lambda _, rec: fn(*rec[3:3 + event_argcount])
analyzer.begin()
fn_cache = {}
@@ -162,19 +165,20 @@ if __name__ == '__main__':
self.last_timestamp = None
def catchall(self, event, rec):
- i = 1
timestamp = rec[1]
if self.last_timestamp is None:
self.last_timestamp = timestamp
delta_ns = timestamp - self.last_timestamp
self.last_timestamp = timestamp
- fields = [event.name, '%0.3f' % (delta_ns / 1000.0)]
+ fields = [event.name, '%0.3f' % (delta_ns / 1000.0),
+ 'pid=%d' % rec[2]]
+ i = 3
for type, name in event.args:
if is_string(type):
- fields.append('%s=%s' % (name, rec[i + 1]))
+ fields.append('%s=%s' % (name, rec[i]))
else:
- fields.append('%s=0x%x' % (name, rec[i + 1]))
+ fields.append('%s=0x%x' % (name, rec[i]))
i += 1
print ' '.join(fields)
--
1.9.3
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [Qemu-devel] [PULL 2/9] trace: [tracetool] Add methods 'Event.copy' and 'Arguments.copy'
2014-06-09 13:45 [Qemu-devel] [PULL 0/5] Tracing patches Stefan Hajnoczi
` (2 preceding siblings ...)
2014-06-09 13:45 ` [Qemu-devel] [PULL 2/5] simpletrace: add support for trace record pid field Stefan Hajnoczi
@ 2014-06-09 13:45 ` Stefan Hajnoczi
2014-06-09 13:45 ` [Qemu-devel] [PULL 3/5] trace: Replace error with warning if event is not defined Stefan Hajnoczi
` (10 subsequent siblings)
14 siblings, 0 replies; 21+ messages in thread
From: Stefan Hajnoczi @ 2014-06-09 13:45 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Lluís Vilanova, Stefan Hajnoczi
From: Lluís Vilanova <vilanova@ac.upc.edu>
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
scripts/tracetool/__init__.py | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
index 305b99e..bfe44bd 100644
--- a/scripts/tracetool/__init__.py
+++ b/scripts/tracetool/__init__.py
@@ -52,6 +52,10 @@ class Arguments:
"""
self._args = args
+ def copy(self):
+ """Create a new copy."""
+ return Arguments(list(self._args))
+
@staticmethod
def build(arg_str):
"""Build and Arguments instance from an argument string.
@@ -146,6 +150,11 @@ class Event(object):
if len(unknown_props) > 0:
raise ValueError("Unknown properties: %s" % ", ".join(unknown_props))
+ def copy(self):
+ """Create a new copy."""
+ return Event(self.name, list(self.properties), self.fmt,
+ self.args.copy(), self)
+
@staticmethod
def build(line_str):
"""Build an Event instance from a string.
--
1.9.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [Qemu-devel] [PULL 3/5] trace: Replace error with warning if event is not defined
2014-06-09 13:45 [Qemu-devel] [PULL 0/5] Tracing patches Stefan Hajnoczi
` (3 preceding siblings ...)
2014-06-09 13:45 ` [Qemu-devel] [PULL 2/9] trace: [tracetool] Add methods 'Event.copy' and 'Arguments.copy' Stefan Hajnoczi
@ 2014-06-09 13:45 ` Stefan Hajnoczi
2014-06-09 13:45 ` [Qemu-devel] [PULL 3/9] trace: [tracetool] Spacing changes Stefan Hajnoczi
` (9 subsequent siblings)
14 siblings, 0 replies; 21+ messages in thread
From: Stefan Hajnoczi @ 2014-06-09 13:45 UTC (permalink / raw)
To: qemu-devel; +Cc: Alexey Kardashevskiy, Peter Maydell, Stefan Hajnoczi
From: Alexey Kardashevskiy <aik@ozlabs.ru>
At the moment QEMU exits if trace point is not defined which makes
a developer life harder if he has to switch between branches with
different traces implemented.
This replaces error+exit wit WARNING if the tracepoint does not exist or
not traceable.
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
trace/control.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/trace/control.c b/trace/control.c
index 49f61e1..4aa02cf 100644
--- a/trace/control.c
+++ b/trace/control.c
@@ -112,15 +112,15 @@ void trace_backend_init_events(const char *fname)
TraceEvent *ev = trace_event_name(line_ptr);
if (ev == NULL) {
fprintf(stderr,
- "error: trace event '%s' does not exist\n", line_ptr);
- exit(1);
- }
- if (!trace_event_get_state_static(ev)) {
+ "WARNING: trace event '%s' does not exist\n",
+ line_ptr);
+ } else if (!trace_event_get_state_static(ev)) {
fprintf(stderr,
- "error: trace event '%s' is not traceable\n", line_ptr);
- exit(1);
+ "WARNING: trace event '%s' is not traceable\n",
+ line_ptr);
+ } else {
+ trace_event_set_state_dynamic(ev, enable);
}
- trace_event_set_state_dynamic(ev, enable);
}
}
}
--
1.9.3
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [Qemu-devel] [PULL 3/9] trace: [tracetool] Spacing changes
2014-06-09 13:45 [Qemu-devel] [PULL 0/5] Tracing patches Stefan Hajnoczi
` (4 preceding siblings ...)
2014-06-09 13:45 ` [Qemu-devel] [PULL 3/5] trace: Replace error with warning if event is not defined Stefan Hajnoczi
@ 2014-06-09 13:45 ` Stefan Hajnoczi
2014-06-09 13:45 ` [Qemu-devel] [PULL 4/5] trace: Multi-backend tracing Stefan Hajnoczi
` (8 subsequent siblings)
14 siblings, 0 replies; 21+ messages in thread
From: Stefan Hajnoczi @ 2014-06-09 13:45 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Lluís Vilanova, Stefan Hajnoczi
From: Lluís Vilanova <vilanova@ac.upc.edu>
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
scripts/tracetool/__init__.py | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
index bfe44bd..3cf7a4e 100644
--- a/scripts/tracetool/__init__.py
+++ b/scripts/tracetool/__init__.py
@@ -148,7 +148,8 @@ class Event(object):
unknown_props = set(self.properties) - self._VALID_PROPS
if len(unknown_props) > 0:
- raise ValueError("Unknown properties: %s" % ", ".join(unknown_props))
+ raise ValueError("Unknown properties: %s"
+ % ", ".join(unknown_props))
def copy(self):
"""Create a new copy."""
@@ -206,7 +207,7 @@ class TracetoolError (Exception):
pass
-def try_import(mod_name, attr_name = None, attr_default = None):
+def try_import(mod_name, attr_name=None, attr_default=None):
"""Try to import a module and get an attribute from it.
Parameters
@@ -233,7 +234,7 @@ def try_import(mod_name, attr_name = None, attr_default = None):
def generate(fevents, format, backend,
- binary = None, probe_prefix = None):
+ binary=None, probe_prefix=None):
"""Generate the output for the given (format, backend) pair.
Parameters
--
1.9.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [Qemu-devel] [PULL 4/5] trace: Multi-backend tracing
2014-06-09 13:45 [Qemu-devel] [PULL 0/5] Tracing patches Stefan Hajnoczi
` (5 preceding siblings ...)
2014-06-09 13:45 ` [Qemu-devel] [PULL 3/9] trace: [tracetool] Spacing changes Stefan Hajnoczi
@ 2014-06-09 13:45 ` Stefan Hajnoczi
2014-06-09 13:45 ` [Qemu-devel] [PULL 4/9] trace: [tracetool] Cosmetic changes Stefan Hajnoczi
` (7 subsequent siblings)
14 siblings, 0 replies; 21+ messages in thread
From: Stefan Hajnoczi @ 2014-06-09 13:45 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Lluís Vilanova, Stefan Hajnoczi
From: Lluís Vilanova <vilanova@ac.upc.edu>
Adds support to compile QEMU with multiple tracing backends at the same time.
For example, you can compile QEMU with:
$ ./configure --enable-trace-backends=ftrace,dtrace
Where 'ftrace' can be handy for having an in-flight record of events, and 'dtrace' can be later used to extract more information from the system.
This patch allows having both available without recompiling QEMU.
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
.travis.yml | 8 +++---
Makefile | 4 +--
Makefile.target | 4 +--
configure | 47 ++++++++++++++++-----------------
docs/tracing.txt | 4 +--
qemu-io.c | 2 +-
scripts/tracetool.py | 43 +++++++++++++++---------------
scripts/tracetool/__init__.py | 24 ++++++++---------
scripts/tracetool/backend/__init__.py | 15 ++++++-----
trace/Makefile.objs | 32 +++++++++++------------
trace/control-internal.h | 4 +--
trace/control.c | 49 +++++++++++++++++++++++++++++++++--
trace/control.h | 27 +++----------------
trace/default.c | 40 ----------------------------
trace/ftrace.c | 25 +-----------------
trace/ftrace.h | 5 ++++
trace/simple.c | 19 +-------------
trace/simple.h | 1 +
trace/stderr.c | 30 ---------------------
vl.c | 4 +--
20 files changed, 153 insertions(+), 234 deletions(-)
delete mode 100644 trace/default.c
delete mode 100644 trace/stderr.c
diff --git a/.travis.yml b/.travis.yml
index 04da973..89c30ae 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -66,16 +66,16 @@ matrix:
compiler: gcc
# All the trace backends (apart from dtrace)
- env: TARGETS=i386-softmmu,x86_64-softmmu
- EXTRA_CONFIG="--enable-trace-backend=stderr"
+ EXTRA_CONFIG="--enable-trace-backends=stderr"
compiler: gcc
- env: TARGETS=i386-softmmu,x86_64-softmmu
- EXTRA_CONFIG="--enable-trace-backend=simple"
+ EXTRA_CONFIG="--enable-trace-backends=simple"
compiler: gcc
- env: TARGETS=i386-softmmu,x86_64-softmmu
- EXTRA_CONFIG="--enable-trace-backend=ftrace"
+ EXTRA_CONFIG="--enable-trace-backends=ftrace"
TEST_CMD=""
compiler: gcc
- env: TARGETS=i386-softmmu,x86_64-softmmu
EXTRA_PKGS="liblttng-ust-dev liburcu-dev"
- EXTRA_CONFIG="--enable-trace-backend=ust"
+ EXTRA_CONFIG="--enable-trace-backends=ust"
compiler: gcc
diff --git a/Makefile b/Makefile
index d830483..3c8f19c 100644
--- a/Makefile
+++ b/Makefile
@@ -52,12 +52,12 @@ GENERATED_HEADERS += trace/generated-events.h
GENERATED_SOURCES += trace/generated-events.c
GENERATED_HEADERS += trace/generated-tracers.h
-ifeq ($(TRACE_BACKEND),dtrace)
+ifeq ($(findstring dtrace,$(TRACE_BACKENDS)),dtrace)
GENERATED_HEADERS += trace/generated-tracers-dtrace.h
endif
GENERATED_SOURCES += trace/generated-tracers.c
-ifeq ($(TRACE_BACKEND),ust)
+ifeq ($(findstring ust,$(TRACE_BACKENDS)),ust)
GENERATED_HEADERS += trace/generated-ust-provider.h
GENERATED_SOURCES += trace/generated-ust.c
endif
diff --git a/Makefile.target b/Makefile.target
index 9986047..8155496 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -49,7 +49,7 @@ endif
$(QEMU_PROG).stp-installed: $(SRC_PATH)/trace-events
$(call quiet-command,$(TRACETOOL) \
--format=stap \
- --backend=$(TRACE_BACKEND) \
+ --backends=$(TRACE_BACKENDS) \
--binary=$(bindir)/$(QEMU_PROG) \
--target-name=$(TARGET_NAME) \
--target-type=$(TARGET_TYPE) \
@@ -58,7 +58,7 @@ $(QEMU_PROG).stp-installed: $(SRC_PATH)/trace-events
$(QEMU_PROG).stp: $(SRC_PATH)/trace-events
$(call quiet-command,$(TRACETOOL) \
--format=stap \
- --backend=$(TRACE_BACKEND) \
+ --backends=$(TRACE_BACKENDS) \
--binary=$(realpath .)/$(QEMU_PROG) \
--target-name=$(TARGET_NAME) \
--target-type=$(TARGET_TYPE) \
diff --git a/configure b/configure
index 0e516f9..a994f41 100755
--- a/configure
+++ b/configure
@@ -182,6 +182,10 @@ path_of() {
return 1
}
+have_backend () {
+ echo "$trace_backends" | grep "$1" >/dev/null
+}
+
# default parameters
source_path=`dirname "$0"`
cpu=""
@@ -293,7 +297,7 @@ pkgversion=""
pie=""
zero_malloc=""
qom_cast_debug="yes"
-trace_backend="nop"
+trace_backends="nop"
trace_file="trace"
spice=""
rbd=""
@@ -753,7 +757,10 @@ for opt do
;;
--target-list=*) target_list="$optarg"
;;
- --enable-trace-backend=*) trace_backend="$optarg"
+ --enable-trace-backends=*) trace_backends="$optarg"
+ ;;
+ # XXX: backwards compatibility
+ --enable-trace-backend=*) trace_backends="$optarg"
;;
--with-trace-file=*) trace_file="$optarg"
;;
@@ -1320,7 +1327,7 @@ Advanced options (experts only):
--disable-docs disable documentation build
--disable-vhost-net disable vhost-net acceleration support
--enable-vhost-net enable vhost-net acceleration support
- --enable-trace-backend=B Set trace backend
+ --enable-trace-backends=B Set trace backend
Available backends: $($python $source_path/scripts/tracetool.py --list-backends)
--with-trace-file=NAME Full PATH,NAME of file to store traces
Default:trace-<pid>
@@ -3666,15 +3673,15 @@ fi
##########################################
# check if trace backend exists
-$python "$source_path/scripts/tracetool.py" "--backend=$trace_backend" --check-backend > /dev/null 2> /dev/null
+$python "$source_path/scripts/tracetool.py" "--backends=$trace_backends" --check-backends > /dev/null 2> /dev/null
if test "$?" -ne 0 ; then
- error_exit "invalid trace backend" \
- "Please choose a supported trace backend."
+ error_exit "invalid trace backends" \
+ "Please choose supported trace backends."
fi
##########################################
# For 'ust' backend, test if ust headers are present
-if test "$trace_backend" = "ust"; then
+if have_backend "ust"; then
cat > $TMPC << EOF
#include <lttng/tracepoint.h>
int main(void) { return 0; }
@@ -3700,7 +3707,7 @@ fi
##########################################
# For 'dtrace' backend, test if 'dtrace' command is present
-if test "$trace_backend" = "dtrace"; then
+if have_backend "dtrace"; then
if ! has 'dtrace' ; then
error_exit "dtrace command is not found in PATH $PATH"
fi
@@ -4170,7 +4177,7 @@ echo "uuid support $uuid"
echo "libcap-ng support $cap_ng"
echo "vhost-net support $vhost_net"
echo "vhost-scsi support $vhost_scsi"
-echo "Trace backend $trace_backend"
+echo "Trace backends $trace_backends"
if test "$trace_backend" = "simple"; then
echo "Trace output file $trace_file-<pid>"
fi
@@ -4664,43 +4671,35 @@ if test "$tpm" = "yes"; then
fi
fi
-# use default implementation for tracing backend-specific routines
-trace_default=yes
-echo "TRACE_BACKEND=$trace_backend" >> $config_host_mak
-if test "$trace_backend" = "nop"; then
+echo "TRACE_BACKENDS=$trace_backends" >> $config_host_mak
+if have_backend "nop"; then
echo "CONFIG_TRACE_NOP=y" >> $config_host_mak
fi
-if test "$trace_backend" = "simple"; then
+if have_backend "simple"; then
echo "CONFIG_TRACE_SIMPLE=y" >> $config_host_mak
- trace_default=no
# Set the appropriate trace file.
trace_file="\"$trace_file-\" FMT_pid"
fi
-if test "$trace_backend" = "stderr"; then
+if have_backend "stderr"; then
echo "CONFIG_TRACE_STDERR=y" >> $config_host_mak
- trace_default=no
fi
-if test "$trace_backend" = "ust"; then
+if have_backend "ust"; then
echo "CONFIG_TRACE_UST=y" >> $config_host_mak
fi
-if test "$trace_backend" = "dtrace"; then
+if have_backend "dtrace"; then
echo "CONFIG_TRACE_DTRACE=y" >> $config_host_mak
if test "$trace_backend_stap" = "yes" ; then
echo "CONFIG_TRACE_SYSTEMTAP=y" >> $config_host_mak
fi
fi
-if test "$trace_backend" = "ftrace"; then
+if have_backend "ftrace"; then
if test "$linux" = "yes" ; then
echo "CONFIG_TRACE_FTRACE=y" >> $config_host_mak
- trace_default=no
else
feature_not_found "ftrace(trace backend)" "ftrace requires Linux"
fi
fi
echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak
-if test "$trace_default" = "yes"; then
- echo "CONFIG_TRACE_DEFAULT=y" >> $config_host_mak
-fi
if test "$rdma" = "yes" ; then
echo "CONFIG_RDMA=y" >> $config_host_mak
diff --git a/docs/tracing.txt b/docs/tracing.txt
index bf2e15c..c6ab1c1 100644
--- a/docs/tracing.txt
+++ b/docs/tracing.txt
@@ -9,7 +9,7 @@ for debugging, profiling, and observing execution.
1. Build with the 'simple' trace backend:
- ./configure --enable-trace-backend=simple
+ ./configure --enable-trace-backends=simple
make
2. Create a file with the events you want to trace:
@@ -142,7 +142,7 @@ script.
The trace backend is chosen at configure time and only one trace backend can
be built into the binary:
- ./configure --trace-backend=simple
+ ./configure --trace-backends=simple
For a list of supported trace backends, try ./configure --help or see below.
diff --git a/qemu-io.c b/qemu-io.c
index 795cf46..b55a550 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -433,7 +433,7 @@ int main(int argc, char **argv)
}
break;
case 'T':
- if (!trace_backend_init(optarg, NULL)) {
+ if (!trace_init_backends(optarg, NULL)) {
exit(1); /* error message will have been printed */
}
break;
diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index 5f4890f..83bde7b 100755
--- a/scripts/tracetool.py
+++ b/scripts/tracetool.py
@@ -6,7 +6,7 @@ Command-line wrapper for the tracetool machinery.
"""
__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
-__copyright__ = "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>"
+__copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
__license__ = "GPL version 2 or (at your option) any later version"
__maintainer__ = "Stefan Hajnoczi"
@@ -32,7 +32,7 @@ def error_opt(msg = None):
format_descr = "\n".join([ " %-15s %s" % (n, d)
for n,d in tracetool.format.get_list() ])
error_write("""\
-Usage: %(script)s --format=<format> --backend=<backend> [<options>]
+Usage: %(script)s --format=<format> --backends=<backends> [<options>]
Backends:
%(backends)s
@@ -43,7 +43,7 @@ Formats:
Options:
--help This help message.
--list-backends Print list of available backends.
- --check-backend Check if the given backend is valid.
+ --check-backends Check if the given backend is valid.
--binary <path> Full path to QEMU binary.
--target-type <type> QEMU emulator target type ('system' or 'user').
--target-name <name> QEMU emulator target name.
@@ -65,16 +65,17 @@ def main(args):
global _SCRIPT
_SCRIPT = args[0]
- long_opts = [ "backend=", "format=", "help", "list-backends", "check-backend" ]
- long_opts += [ "binary=", "target-type=", "target-name=", "probe-prefix=" ]
+ long_opts = ["backends=", "format=", "help", "list-backends",
+ "check-backends"]
+ long_opts += ["binary=", "target-type=", "target-name=", "probe-prefix="]
try:
opts, args = getopt.getopt(args[1:], "", long_opts)
except getopt.GetoptError, err:
error_opt(str(err))
- check_backend = False
- arg_backend = ""
+ check_backends = False
+ arg_backends = []
arg_format = ""
binary = None
target_type = None
@@ -84,8 +85,8 @@ def main(args):
if opt == "--help":
error_opt()
- elif opt == "--backend":
- arg_backend = arg
+ elif opt == "--backends":
+ arg_backends = arg.split(",")
elif opt == "--format":
arg_format = arg
@@ -93,8 +94,8 @@ def main(args):
public_backends = tracetool.backend.get_list(only_public = True)
out(", ".join([ b for b,_ in public_backends ]))
sys.exit(0)
- elif opt == "--check-backend":
- check_backend = True
+ elif opt == "--check-backends":
+ check_backends = True
elif opt == "--binary":
binary = arg
@@ -108,14 +109,14 @@ def main(args):
else:
error_opt("unhandled option: %s" % opt)
- if arg_backend is None:
- error_opt("backend not set")
+ if len(arg_backends) == 0:
+ error_opt("no backends specified")
- if check_backend:
- if tracetool.backend.exists(arg_backend):
- sys.exit(0)
- else:
- sys.exit(1)
+ if check_backends:
+ for backend in arg_backends:
+ if not tracetool.backend.exists(backend):
+ sys.exit(1)
+ sys.exit(0)
if arg_format == "stap":
if binary is None:
@@ -126,11 +127,11 @@ def main(args):
error_opt("--target-name is required for SystemTAP tapset generator")
if probe_prefix is None:
- probe_prefix = ".".join([ "qemu", target_type, target_name ])
+ probe_prefix = ".".join(["qemu", target_type, target_name])
try:
- tracetool.generate(sys.stdin, arg_format, arg_backend,
- binary = binary, probe_prefix = probe_prefix)
+ tracetool.generate(sys.stdin, arg_format, arg_backends,
+ binary=binary, probe_prefix=probe_prefix)
except tracetool.TracetoolError, e:
error_opt(str(e))
diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
index eccf552..e8e8edc 100644
--- a/scripts/tracetool/__init__.py
+++ b/scripts/tracetool/__init__.py
@@ -233,9 +233,9 @@ def try_import(mod_name, attr_name=None, attr_default=None):
return False, None
-def generate(fevents, format, backend,
+def generate(fevents, format, backends,
binary=None, probe_prefix=None):
- """Generate the output for the given (format, backend) pair.
+ """Generate the output for the given (format, backends) pair.
Parameters
----------
@@ -243,8 +243,8 @@ def generate(fevents, format, backend,
Event description file.
format : str
Output format name.
- backend : str
- Output backend name.
+ backends : list
+ Output backend names.
binary : str or None
See tracetool.backend.dtrace.BINARY.
probe_prefix : str or None
@@ -258,15 +258,13 @@ def generate(fevents, format, backend,
raise TracetoolError("format not set")
if not tracetool.format.exists(format):
raise TracetoolError("unknown format: %s" % format)
- format = format.replace("-", "_")
-
- backend = str(backend)
- if len(backend) is 0:
- raise TracetoolError("backend not set")
- if not tracetool.backend.exists(backend):
- raise TracetoolError("unknown backend: %s" % backend)
- backend = backend.replace("-", "_")
- backend = tracetool.backend.Wrapper(backend, format)
+
+ if len(backends) is 0:
+ raise TracetoolError("no backends specified")
+ for backend in backends:
+ if not tracetool.backend.exists(backend):
+ raise TracetoolError("unknown backend: %s" % backend)
+ backend = tracetool.backend.Wrapper(backends, format)
import tracetool.backend.dtrace
tracetool.backend.dtrace.BINARY = binary
diff --git a/scripts/tracetool/backend/__init__.py b/scripts/tracetool/backend/__init__.py
index 5e36f04..5bfa1ef 100644
--- a/scripts/tracetool/backend/__init__.py
+++ b/scripts/tracetool/backend/__init__.py
@@ -99,17 +99,18 @@ def exists(name):
class Wrapper:
- def __init__(self, backend, format):
- self._backend = backend.replace("-", "_")
+ def __init__(self, backends, format):
+ self._backends = [backend.replace("-", "_") for backend in backends]
self._format = format.replace("-", "_")
- assert exists(self._backend)
+ assert all(exists(backend) for backend in self._backends)
assert tracetool.format.exists(self._format)
def _run_function(self, name, *args, **kwargs):
- func = tracetool.try_import("tracetool.backend." + self._backend,
- name % self._format, None)[1]
- if func is not None:
- func(*args, **kwargs)
+ for backend in self._backends:
+ func = tracetool.try_import("tracetool.backend." + backend,
+ name % self._format, None)[1]
+ if func is not None:
+ func(*args, **kwargs)
def generate_begin(self, events):
self._run_function("generate_%s_begin", events)
diff --git a/trace/Makefile.objs b/trace/Makefile.objs
index 6a30467..d7a8696 100644
--- a/trace/Makefile.objs
+++ b/trace/Makefile.objs
@@ -3,12 +3,12 @@
######################################################################
# Auto-generated event descriptions for LTTng ust code
-ifeq ($(TRACE_BACKEND),ust)
+ifeq ($(findstring ust,$(TRACE_BACKENDS)),ust)
$(obj)/generated-ust-provider.h: $(obj)/generated-ust-provider.h-timestamp
$(obj)/generated-ust-provider.h-timestamp: $(SRC_PATH)/trace-events
$(call quiet-command,$(TRACETOOL) \
--format=ust-events-h \
- --backend=$(TRACE_BACKEND) \
+ --backends=$(TRACE_BACKENDS) \
< $< > $@," GEN $(patsubst %-timestamp,%,$@)")
@cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@)
@@ -16,7 +16,7 @@ $(obj)/generated-ust.c: $(obj)/generated-ust.c-timestamp $(BUILD_DIR)/config-hos
$(obj)/generated-ust.c-timestamp: $(SRC_PATH)/trace-events
$(call quiet-command,$(TRACETOOL) \
--format=ust-events-c \
- --backend=$(TRACE_BACKEND) \
+ --backends=$(TRACE_BACKENDS) \
< $< > $@," GEN $(patsubst %-timestamp,%,$@)")
@cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@)
@@ -31,7 +31,7 @@ $(obj)/generated-events.h: $(obj)/generated-events.h-timestamp
$(obj)/generated-events.h-timestamp: $(SRC_PATH)/trace-events
$(call quiet-command,$(TRACETOOL) \
--format=events-h \
- --backend=$(TRACE_BACKEND) \
+ --backends=$(TRACE_BACKENDS) \
< $< > $@," GEN $(patsubst %-timestamp,%,$@)")
@cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@)
@@ -39,7 +39,7 @@ $(obj)/generated-events.c: $(obj)/generated-events.c-timestamp $(BUILD_DIR)/conf
$(obj)/generated-events.c-timestamp: $(SRC_PATH)/trace-events
$(call quiet-command,$(TRACETOOL) \
--format=events-c \
- --backend=$(TRACE_BACKEND) \
+ --backends=$(TRACE_BACKENDS) \
< $< > $@," GEN $(patsubst %-timestamp,%,$@)")
@cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@)
@@ -54,23 +54,21 @@ $(obj)/generated-tracers.h: $(obj)/generated-tracers.h-timestamp
$(obj)/generated-tracers.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
$(call quiet-command,$(TRACETOOL) \
--format=h \
- --backend=$(TRACE_BACKEND) \
+ --backends=$(TRACE_BACKENDS) \
< $< > $@," GEN $(patsubst %-timestamp,%,$@)")
######################################################################
# Auto-generated tracing routines (non-DTrace)
-ifneq ($(TRACE_BACKEND),dtrace)
$(obj)/generated-tracers.c: $(obj)/generated-tracers.c-timestamp
@cmp -s $< $@ || cp $< $@
$(obj)/generated-tracers.c-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
$(call quiet-command,$(TRACETOOL) \
--format=c \
- --backend=$(TRACE_BACKEND) \
+ --backends=$(TRACE_BACKENDS) \
< $< > $@," GEN $(patsubst %-timestamp,%,$@)")
$(obj)/generated-tracers.o: $(obj)/generated-tracers.c $(obj)/generated-tracers.h
-endif
######################################################################
@@ -79,27 +77,27 @@ endif
# Normal practice is to name DTrace probe file with a '.d' extension
# but that gets picked up by QEMU's Makefile as an external dependency
# rule file. So we use '.dtrace' instead
-ifeq ($(TRACE_BACKEND),dtrace)
-$(obj)/generated-tracers.dtrace: $(obj)/generated-tracers.dtrace-timestamp
-$(obj)/generated-tracers.dtrace-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
+ifeq ($(findstring dtrace,$(TRACE_BACKENDS)),dtrace)
+$(obj)/generated-tracers-dtrace.dtrace: $(obj)/generated-tracers-dtrace.dtrace-timestamp
+$(obj)/generated-tracers-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
$(call quiet-command,$(TRACETOOL) \
--format=d \
- --backend=$(TRACE_BACKEND) \
+ --backends=$(TRACE_BACKENDS) \
< $< > $@," GEN $(patsubst %-timestamp,%,$@)")
@cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@)
-$(obj)/generated-tracers-dtrace.h: $(obj)/generated-tracers.dtrace
+$(obj)/generated-tracers-dtrace.h: $(obj)/generated-tracers-dtrace.dtrace
$(call quiet-command,dtrace -o $@ -h -s $<, " GEN $@")
-$(obj)/generated-tracers.o: $(obj)/generated-tracers.dtrace
+$(obj)/generated-tracers-dtrace.o: $(obj)/generated-tracers-dtrace.dtrace
+
+util-obj-y += generated-tracers-dtrace.o
endif
######################################################################
# Backend code
-util-obj-$(CONFIG_TRACE_DEFAULT) += default.o
util-obj-$(CONFIG_TRACE_SIMPLE) += simple.o
-util-obj-$(CONFIG_TRACE_STDERR) += stderr.o
util-obj-$(CONFIG_TRACE_FTRACE) += ftrace.o
util-obj-$(CONFIG_TRACE_UST) += generated-ust.o
util-obj-y += control.o
diff --git a/trace/control-internal.h b/trace/control-internal.h
index b3f587e..5a8df28 100644
--- a/trace/control-internal.h
+++ b/trace/control-internal.h
@@ -1,7 +1,7 @@
/*
* Interface for configuring and controlling the state of tracing events.
*
- * Copyright (C) 2011-2012 Lluís Vilanova <vilanova@ac.upc.edu>
+ * Copyright (C) 2011-2014 Lluís Vilanova <vilanova@ac.upc.edu>
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
@@ -61,7 +61,7 @@ static inline void trace_event_set_state_dynamic(TraceEvent *ev, bool state)
{
assert(ev != NULL);
assert(trace_event_get_state_static(ev));
- return trace_event_set_state_dynamic_backend(ev, state);
+ ev->dstate = state;
}
#endif /* TRACE__CONTROL_INTERNAL_H */
diff --git a/trace/control.c b/trace/control.c
index 4aa02cf..45e6604 100644
--- a/trace/control.c
+++ b/trace/control.c
@@ -1,13 +1,19 @@
/*
* Interface for configuring and controlling the state of tracing events.
*
- * Copyright (C) 2011-2012 Lluís Vilanova <vilanova@ac.upc.edu>
+ * Copyright (C) 2011-2014 Lluís Vilanova <vilanova@ac.upc.edu>
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*/
#include "trace/control.h"
+#ifdef CONFIG_TRACE_SIMPLE
+#include "trace/simple.h"
+#endif
+#ifdef CONFIG_TRACE_FTRACE
+#include "trace/ftrace.h"
+#endif
TraceEvent *trace_event_name(const char *name)
@@ -79,7 +85,20 @@ TraceEvent *trace_event_pattern(const char *pat, TraceEvent *ev)
return NULL;
}
-void trace_backend_init_events(const char *fname)
+void trace_print_events(FILE *stream, fprintf_function stream_printf)
+{
+ TraceEventID i;
+
+ for (i = 0; i < trace_event_count(); i++) {
+ TraceEvent *ev = trace_event_id(i);
+ stream_printf(stream, "%s [Event ID %u] : state %u\n",
+ trace_event_get_name(ev), i,
+ trace_event_get_state_static(ev) &&
+ trace_event_get_state_dynamic(ev));
+ }
+}
+
+static void trace_init_events(const char *fname)
{
if (fname == NULL) {
return;
@@ -130,3 +149,29 @@ void trace_backend_init_events(const char *fname)
exit(1);
}
}
+
+bool trace_init_backends(const char *events, const char *file)
+{
+#ifdef CONFIG_TRACE_SIMPLE
+ if (!st_init(file)) {
+ fprintf(stderr, "failed to initialize simple tracing backend.\n");
+ return false;
+ }
+#else
+ if (file) {
+ fprintf(stderr, "error: -trace file=...: "
+ "option not supported by the selected tracing backends\n");
+ return false;
+ }
+#endif
+
+#ifdef CONFIG_TRACE_FTRACE
+ if (!ftrace_init()) {
+ fprintf(stderr, "failed to initialize ftrace backend.\n");
+ return false;
+ }
+#endif
+
+ trace_init_events(events);
+ return true;
+}
diff --git a/trace/control.h b/trace/control.h
index cde8260..e1ec033 100644
--- a/trace/control.h
+++ b/trace/control.h
@@ -1,7 +1,7 @@
/*
* Interface for configuring and controlling the state of tracing events.
*
- * Copyright (C) 2011-2012 Lluís Vilanova <vilanova@ac.upc.edu>
+ * Copyright (C) 2011-2014 Lluís Vilanova <vilanova@ac.upc.edu>
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
@@ -146,26 +146,17 @@ static bool trace_event_get_state_dynamic(TraceEvent *ev);
*/
static void trace_event_set_state_dynamic(TraceEvent *ev, bool state);
-/**
- * trace_event_set_state_dynamic_backend:
- *
- * Warning: This function must be implemented by each tracing backend.
- */
-void trace_event_set_state_dynamic_backend(TraceEvent *ev, bool state);
-
/**
* trace_print_events:
*
* Print the state of all events.
- *
- * Warning: This function must be implemented by each tracing backend.
*/
void trace_print_events(FILE *stream, fprintf_function stream_printf);
/**
- * trace_backend_init:
+ * trace_init_backends:
* @events: Name of file with events to be enabled at startup; may be NULL.
* Corresponds to commandline option "-trace events=...".
* @file: Name of trace output file; may be NULL.
@@ -173,19 +164,9 @@ void trace_print_events(FILE *stream, fprintf_function stream_printf);
*
* Initialize the tracing backend.
*
- * Warning: This function must be implemented by each tracing backend.
- *
- * Returns: Whether the backend could be successfully initialized.
- */
-bool trace_backend_init(const char *events, const char *file);
-
-/**
- * trace_backend_init_events:
- * @fname: Name of file with events to enable; may be NULL.
- *
- * Generic function to initialize the state of events.
+ * Returns: Whether the backends could be successfully initialized.
*/
-void trace_backend_init_events(const char *fname);
+bool trace_init_backends(const char *events, const char *file);
#include "trace/control-internal.h"
diff --git a/trace/default.c b/trace/default.c
deleted file mode 100644
index 6e07a47..0000000
--- a/trace/default.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Default implementation for backend initialization from commandline.
- *
- * Copyright (C) 2011-2012 Lluís Vilanova <vilanova@ac.upc.edu>
- *
- * This work is licensed under the terms of the GNU GPL, version 2. See
- * the COPYING file in the top-level directory.
- */
-
-#include "trace/control.h"
-
-
-void trace_print_events(FILE *stream, fprintf_function stream_printf)
-{
- fprintf(stderr, "warning: "
- "cannot print the trace events with the current backend\n");
- stream_printf(stream, "error: "
- "operation not supported with the current backend\n");
-}
-
-void trace_event_set_state_dynamic_backend(TraceEvent *ev, bool state)
-{
- fprintf(stderr, "warning: "
- "cannot set the state of a trace event with the current backend\n");
-}
-
-bool trace_backend_init(const char *events, const char *file)
-{
- if (events) {
- fprintf(stderr, "error: -trace events=...: "
- "option not supported by the selected tracing backend\n");
- return false;
- }
- if (file) {
- fprintf(stderr, "error: -trace file=...: "
- "option not supported by the selected tracing backend\n");
- return false;
- }
- return true;
-}
diff --git a/trace/ftrace.c b/trace/ftrace.c
index 46b7fdb..a7ae371 100644
--- a/trace/ftrace.c
+++ b/trace/ftrace.c
@@ -42,35 +42,13 @@ static int find_debugfs(char *debugfs)
return 1;
}
-void trace_print_events(FILE *stream, fprintf_function stream_printf)
-{
- TraceEventID i;
-
- for (i = 0; i < trace_event_count(); i++) {
- TraceEvent *ev = trace_event_id(i);
- stream_printf(stream, "%s [Event ID %u] : state %u\n",
- trace_event_get_name(ev), i, trace_event_get_state_dynamic(ev));
- }
-}
-
-void trace_event_set_state_dynamic_backend(TraceEvent *ev, bool state)
-{
- ev->dstate = state;
-}
-
-bool trace_backend_init(const char *events, const char *file)
+bool ftrace_init(void)
{
char debugfs[PATH_MAX];
char path[PATH_MAX];
int debugfs_found;
int trace_fd = -1;
- if (file) {
- fprintf(stderr, "error: -trace file=...: "
- "option not supported by the selected tracing backend\n");
- return false;
- }
-
debugfs_found = find_debugfs(debugfs);
if (debugfs_found) {
snprintf(path, PATH_MAX, "%s/tracing/tracing_on", debugfs);
@@ -97,6 +75,5 @@ bool trace_backend_init(const char *events, const char *file)
return false;
}
- trace_backend_init_events(events);
return true;
}
diff --git a/trace/ftrace.h b/trace/ftrace.h
index 94cb8d5..863e052 100644
--- a/trace/ftrace.h
+++ b/trace/ftrace.h
@@ -1,10 +1,15 @@
#ifndef TRACE_FTRACE_H
#define TRACE_FTRACE_H
+#include <stdbool.h>
+
+
#define MAX_TRACE_STRLEN 512
#define _STR(x) #x
#define STR(x) _STR(x)
extern int trace_marker_fd;
+bool ftrace_init(void);
+
#endif /* ! TRACE_FTRACE_H */
diff --git a/trace/simple.c b/trace/simple.c
index 5a2e188..a8f923c 100644
--- a/trace/simple.c
+++ b/trace/simple.c
@@ -368,22 +368,6 @@ void st_flush_trace_buffer(void)
flush_trace_file(true);
}
-void trace_print_events(FILE *stream, fprintf_function stream_printf)
-{
- unsigned int i;
-
- for (i = 0; i < trace_event_count(); i++) {
- TraceEvent *ev = trace_event_id(i);
- stream_printf(stream, "%s [Event ID %u] : state %u\n",
- trace_event_get_name(ev), i, trace_event_get_state_dynamic(ev));
- }
-}
-
-void trace_event_set_state_dynamic_backend(TraceEvent *ev, bool state)
-{
- ev->dstate = state;
-}
-
/* Helper function to create a thread with signals blocked. Use glib's
* portable threads since QEMU abstractions cannot be used due to reentrancy in
* the tracer. Also note the signal masking on POSIX hosts so that the thread
@@ -412,7 +396,7 @@ static GThread *trace_thread_create(GThreadFunc fn)
return thread;
}
-bool trace_backend_init(const char *events, const char *file)
+bool st_init(const char *file)
{
GThread *thread;
@@ -430,7 +414,6 @@ bool trace_backend_init(const char *events, const char *file)
}
atexit(st_flush_trace_buffer);
- trace_backend_init_events(events);
st_set_trace_file(file);
return true;
}
diff --git a/trace/simple.h b/trace/simple.h
index 5260d9a..6997996 100644
--- a/trace/simple.h
+++ b/trace/simple.h
@@ -21,6 +21,7 @@
void st_print_trace_file_status(FILE *stream, fprintf_function stream_printf);
void st_set_trace_file_enabled(bool enable);
bool st_set_trace_file(const char *file);
+bool st_init(const char *file);
void st_flush_trace_buffer(void);
typedef struct {
diff --git a/trace/stderr.c b/trace/stderr.c
deleted file mode 100644
index e212efd..0000000
--- a/trace/stderr.c
+++ /dev/null
@@ -1,30 +0,0 @@
-#include "trace.h"
-#include "trace/control.h"
-
-
-void trace_print_events(FILE *stream, fprintf_function stream_printf)
-{
- TraceEventID i;
-
- for (i = 0; i < trace_event_count(); i++) {
- TraceEvent *ev = trace_event_id(i);
- stream_printf(stream, "%s [Event ID %u] : state %u\n",
- trace_event_get_name(ev), i, trace_event_get_state_dynamic(ev));
- }
-}
-
-void trace_event_set_state_dynamic_backend(TraceEvent *ev, bool state)
-{
- ev->dstate = state;
-}
-
-bool trace_backend_init(const char *events, const char *file)
-{
- if (file) {
- fprintf(stderr, "error: -trace file=...: "
- "option not supported by the selected tracing backend\n");
- return false;
- }
- trace_backend_init_events(events);
- return true;
-}
diff --git a/vl.c b/vl.c
index a3def97..ac0e3d7 100644
--- a/vl.c
+++ b/vl.c
@@ -4039,7 +4039,7 @@ int main(int argc, char **argv, char **envp)
}
if (!is_daemonized()) {
- if (!trace_backend_init(trace_events, trace_file)) {
+ if (!trace_init_backends(trace_events, trace_file)) {
exit(1);
}
}
@@ -4559,7 +4559,7 @@ int main(int argc, char **argv, char **envp)
os_setup_post();
if (is_daemonized()) {
- if (!trace_backend_init(trace_events, trace_file)) {
+ if (!trace_init_backends(trace_events, trace_file)) {
exit(1);
}
}
--
1.9.3
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [Qemu-devel] [PULL 4/9] trace: [tracetool] Cosmetic changes
2014-06-09 13:45 [Qemu-devel] [PULL 0/5] Tracing patches Stefan Hajnoczi
` (6 preceding siblings ...)
2014-06-09 13:45 ` [Qemu-devel] [PULL 4/5] trace: Multi-backend tracing Stefan Hajnoczi
@ 2014-06-09 13:45 ` Stefan Hajnoczi
2014-06-09 13:45 ` [Qemu-devel] [PULL 5/5] trace: Replace fprintf with error_report and print location Stefan Hajnoczi
` (6 subsequent siblings)
14 siblings, 0 replies; 21+ messages in thread
From: Stefan Hajnoczi @ 2014-06-09 13:45 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Lluís Vilanova, Stefan Hajnoczi
From: Lluís Vilanova <vilanova@ac.upc.edu>
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
scripts/tracetool/__init__.py | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
index 3cf7a4e..7abffb6 100644
--- a/scripts/tracetool/__init__.py
+++ b/scripts/tracetool/__init__.py
@@ -256,18 +256,18 @@ def generate(fevents, format, backend,
format = str(format)
if len(format) is 0:
raise TracetoolError("format not set")
- mformat = format.replace("-", "_")
- if not tracetool.format.exists(mformat):
+ if not tracetool.format.exists(format):
raise TracetoolError("unknown format: %s" % format)
+ format = format.replace("-", "_")
backend = str(backend)
if len(backend) is 0:
raise TracetoolError("backend not set")
- mbackend = backend.replace("-", "_")
- if not tracetool.backend.exists(mbackend):
+ if not tracetool.backend.exists(backend):
raise TracetoolError("unknown backend: %s" % backend)
+ backend = backend.replace("-", "_")
- if not tracetool.backend.compatible(mbackend, mformat):
+ if not tracetool.backend.compatible(backend, format):
raise TracetoolError("backend '%s' not compatible with format '%s'" %
(backend, format))
@@ -280,7 +280,7 @@ def generate(fevents, format, backend,
if backend == "nop":
( e.properies.add("disable") for e in events )
- tracetool.format.generate_begin(mformat, events)
+ tracetool.format.generate_begin(format, events)
tracetool.backend.generate("nop", format,
[ e
for e in events
@@ -289,4 +289,4 @@ def generate(fevents, format, backend,
[ e
for e in events
if "disable" not in e.properties ])
- tracetool.format.generate_end(mformat, events)
+ tracetool.format.generate_end(format, events)
--
1.9.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [Qemu-devel] [PULL 5/5] trace: Replace fprintf with error_report and print location
2014-06-09 13:45 [Qemu-devel] [PULL 0/5] Tracing patches Stefan Hajnoczi
` (7 preceding siblings ...)
2014-06-09 13:45 ` [Qemu-devel] [PULL 4/9] trace: [tracetool] Cosmetic changes Stefan Hajnoczi
@ 2014-06-09 13:45 ` Stefan Hajnoczi
2014-06-09 13:45 ` [Qemu-devel] [PULL 5/9] trace: [tracetool] Show list of frontends and backends sorted by name Stefan Hajnoczi
` (5 subsequent siblings)
14 siblings, 0 replies; 21+ messages in thread
From: Stefan Hajnoczi @ 2014-06-09 13:45 UTC (permalink / raw)
To: qemu-devel; +Cc: Alexey Kardashevskiy, Peter Maydell, Stefan Hajnoczi
From: Alexey Kardashevskiy <aik@ozlabs.ru>
This replaces fprintf(stderr) with error_report.
This moves local variables to the beginning of the function to comply
with QEMU's coding style.
Suggested-by: Lluís Vilanova <vilanova@ac.upc.edu>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
trace/control.c | 31 ++++++++++++++++++-------------
1 file changed, 18 insertions(+), 13 deletions(-)
diff --git a/trace/control.c b/trace/control.c
index 45e6604..9631a40 100644
--- a/trace/control.c
+++ b/trace/control.c
@@ -14,7 +14,7 @@
#ifdef CONFIG_TRACE_FTRACE
#include "trace/ftrace.h"
#endif
-
+#include "qemu/error-report.h"
TraceEvent *trace_event_name(const char *name)
{
@@ -100,18 +100,24 @@ void trace_print_events(FILE *stream, fprintf_function stream_printf)
static void trace_init_events(const char *fname)
{
+ Location loc;
+ FILE *fp;
+ char line_buf[1024];
+ size_t line_idx = 0;
+
if (fname == NULL) {
return;
}
- FILE *fp = fopen(fname, "r");
+ loc_push_none(&loc);
+ loc_set_file(fname, 0);
+ fp = fopen(fname, "r");
if (!fp) {
- fprintf(stderr, "error: could not open trace events file '%s': %s\n",
- fname, strerror(errno));
+ error_report("%s", strerror(errno));
exit(1);
}
- char line_buf[1024];
while (fgets(line_buf, sizeof(line_buf), fp)) {
+ loc_set_file(fname, ++line_idx);
size_t len = strlen(line_buf);
if (len > 1) { /* skip empty lines */
line_buf[len - 1] = '\0';
@@ -130,13 +136,11 @@ static void trace_init_events(const char *fname)
} else {
TraceEvent *ev = trace_event_name(line_ptr);
if (ev == NULL) {
- fprintf(stderr,
- "WARNING: trace event '%s' does not exist\n",
- line_ptr);
+ error_report("WARNING: trace event '%s' does not exist",
+ line_ptr);
} else if (!trace_event_get_state_static(ev)) {
- fprintf(stderr,
- "WARNING: trace event '%s' is not traceable\n",
- line_ptr);
+ error_report("WARNING: trace event '%s' is not traceable\n",
+ line_ptr);
} else {
trace_event_set_state_dynamic(ev, enable);
}
@@ -144,10 +148,11 @@ static void trace_init_events(const char *fname)
}
}
if (fclose(fp) != 0) {
- fprintf(stderr, "error: closing file '%s': %s\n",
- fname, strerror(errno));
+ loc_set_file(fname, 0);
+ error_report("%s", strerror(errno));
exit(1);
}
+ loc_pop(&loc);
}
bool trace_init_backends(const char *events, const char *file)
--
1.9.3
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [Qemu-devel] [PULL 5/9] trace: [tracetool] Show list of frontends and backends sorted by name
2014-06-09 13:45 [Qemu-devel] [PULL 0/5] Tracing patches Stefan Hajnoczi
` (8 preceding siblings ...)
2014-06-09 13:45 ` [Qemu-devel] [PULL 5/5] trace: Replace fprintf with error_report and print location Stefan Hajnoczi
@ 2014-06-09 13:45 ` Stefan Hajnoczi
2014-06-09 13:45 ` [Qemu-devel] [PULL 6/9] trace: [tracetool] Change format docs to point to the generated file Stefan Hajnoczi
` (4 subsequent siblings)
14 siblings, 0 replies; 21+ messages in thread
From: Stefan Hajnoczi @ 2014-06-09 13:45 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Lluís Vilanova, Stefan Hajnoczi
From: Lluís Vilanova <vilanova@ac.upc.edu>
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
scripts/tracetool/backend/__init__.py | 2 +-
scripts/tracetool/format/__init__.py | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/scripts/tracetool/backend/__init__.py b/scripts/tracetool/backend/__init__.py
index f0314ee..88f94fd 100644
--- a/scripts/tracetool/backend/__init__.py
+++ b/scripts/tracetool/backend/__init__.py
@@ -59,7 +59,7 @@ def get_list(only_public = False):
for filename in os.listdir(tracetool.backend.__path__[0]):
if filename.endswith('.py') and filename != '__init__.py':
modnames.append(filename.rsplit('.', 1)[0])
- for modname in modnames:
+ for modname in sorted(modnames):
module = tracetool.try_import("tracetool.backend." + modname)
# just in case; should never fail unless non-module files are put there
diff --git a/scripts/tracetool/format/__init__.py b/scripts/tracetool/format/__init__.py
index 3c2a0d8..2bbbba7 100644
--- a/scripts/tracetool/format/__init__.py
+++ b/scripts/tracetool/format/__init__.py
@@ -34,7 +34,7 @@ nop Called to generate the per-event contents when the event is disabled or
"""
__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
-__copyright__ = "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>"
+__copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
__license__ = "GPL version 2 or (at your option) any later version"
__maintainer__ = "Stefan Hajnoczi"
@@ -53,7 +53,7 @@ def get_list():
for filename in os.listdir(tracetool.format.__path__[0]):
if filename.endswith('.py') and filename != '__init__.py':
modnames.append(filename.rsplit('.', 1)[0])
- for modname in modnames:
+ for modname in sorted(modnames):
module = tracetool.try_import("tracetool.format." + modname)
# just in case; should never fail unless non-module files are put there
--
1.9.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [Qemu-devel] [PULL 6/9] trace: [tracetool] Change format docs to point to the generated file
2014-06-09 13:45 [Qemu-devel] [PULL 0/5] Tracing patches Stefan Hajnoczi
` (9 preceding siblings ...)
2014-06-09 13:45 ` [Qemu-devel] [PULL 5/9] trace: [tracetool] Show list of frontends and backends sorted by name Stefan Hajnoczi
@ 2014-06-09 13:45 ` Stefan Hajnoczi
2014-06-09 13:45 ` [Qemu-devel] [PULL 7/9] trace: [simple] Bump up log version number Stefan Hajnoczi
` (3 subsequent siblings)
14 siblings, 0 replies; 21+ messages in thread
From: Stefan Hajnoczi @ 2014-06-09 13:45 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Lluís Vilanova, Stefan Hajnoczi
From: Lluís Vilanova <vilanova@ac.upc.edu>
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
scripts/tracetool/format/c.py | 4 ++--
scripts/tracetool/format/d.py | 4 ++--
scripts/tracetool/format/events_c.py | 4 ++--
scripts/tracetool/format/events_h.py | 4 ++--
scripts/tracetool/format/h.py | 2 +-
scripts/tracetool/format/ust_events_c.py | 2 +-
scripts/tracetool/format/ust_events_h.py | 2 +-
7 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/scripts/tracetool/format/c.py b/scripts/tracetool/format/c.py
index 35555ae..930140b 100644
--- a/scripts/tracetool/format/c.py
+++ b/scripts/tracetool/format/c.py
@@ -2,11 +2,11 @@
# -*- coding: utf-8 -*-
"""
-Generate .c file.
+trace/generated-tracers.c
"""
__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
-__copyright__ = "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>"
+__copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
__license__ = "GPL version 2 or (at your option) any later version"
__maintainer__ = "Stefan Hajnoczi"
diff --git a/scripts/tracetool/format/d.py b/scripts/tracetool/format/d.py
index a2d5947..74ee0d3 100644
--- a/scripts/tracetool/format/d.py
+++ b/scripts/tracetool/format/d.py
@@ -2,11 +2,11 @@
# -*- coding: utf-8 -*-
"""
-Generate .d file (DTrace only).
+trace/generated-tracers.dtrace (DTrace only).
"""
__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
-__copyright__ = "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>"
+__copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
__license__ = "GPL version 2 or (at your option) any later version"
__maintainer__ = "Stefan Hajnoczi"
diff --git a/scripts/tracetool/format/events_c.py b/scripts/tracetool/format/events_c.py
index d670ec8..ea668ee 100644
--- a/scripts/tracetool/format/events_c.py
+++ b/scripts/tracetool/format/events_c.py
@@ -2,11 +2,11 @@
# -*- coding: utf-8 -*-
"""
-Generate .c for event description.
+trace/generated-events.c
"""
__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
-__copyright__ = "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>"
+__copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
__license__ = "GPL version 2 or (at your option) any later version"
__maintainer__ = "Stefan Hajnoczi"
diff --git a/scripts/tracetool/format/events_h.py b/scripts/tracetool/format/events_h.py
index d30ccea..f3febae 100644
--- a/scripts/tracetool/format/events_h.py
+++ b/scripts/tracetool/format/events_h.py
@@ -2,11 +2,11 @@
# -*- coding: utf-8 -*-
"""
-Generate .h for event description.
+trace/generated-events.h
"""
__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
-__copyright__ = "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>"
+__copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
__license__ = "GPL version 2 or (at your option) any later version"
__maintainer__ = "Stefan Hajnoczi"
diff --git a/scripts/tracetool/format/h.py b/scripts/tracetool/format/h.py
index 9b0903d..85f011f 100644
--- a/scripts/tracetool/format/h.py
+++ b/scripts/tracetool/format/h.py
@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
"""
-Generate .h file.
+trace/generated-tracers.h
"""
__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
diff --git a/scripts/tracetool/format/ust_events_c.py b/scripts/tracetool/format/ust_events_c.py
index 116e713..d048b0a 100644
--- a/scripts/tracetool/format/ust_events_c.py
+++ b/scripts/tracetool/format/ust_events_c.py
@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
"""
-Generate .c for LTTng ust event description.
+trace/generated-ust.c
"""
__author__ = "Mohamad Gebai <mohamad.gebai@polymtl.ca>"
diff --git a/scripts/tracetool/format/ust_events_h.py b/scripts/tracetool/format/ust_events_h.py
index f206eca..a3ef785 100644
--- a/scripts/tracetool/format/ust_events_h.py
+++ b/scripts/tracetool/format/ust_events_h.py
@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
"""
-Generate .h for LTTng ust event description.
+trace/generated-ust-provider.h
"""
__author__ = "Mohamad Gebai <mohamad.gebai@polymtl.ca>"
--
1.9.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [Qemu-devel] [PULL 7/9] trace: [simple] Bump up log version number
2014-06-09 13:45 [Qemu-devel] [PULL 0/5] Tracing patches Stefan Hajnoczi
` (10 preceding siblings ...)
2014-06-09 13:45 ` [Qemu-devel] [PULL 6/9] trace: [tracetool] Change format docs to point to the generated file Stefan Hajnoczi
@ 2014-06-09 13:45 ` Stefan Hajnoczi
2014-06-09 13:45 ` [Qemu-devel] [PULL 8/9] trace: [tracetool] Minimize the amount of per-backend code Stefan Hajnoczi
` (2 subsequent siblings)
14 siblings, 0 replies; 21+ messages in thread
From: Stefan Hajnoczi @ 2014-06-09 13:45 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Lluís Vilanova, Stefan Hajnoczi
From: Lluís Vilanova <vilanova@ac.upc.edu>
The following tracetool cleanup changes the event numbering policy.
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
scripts/simpletrace.py | 10 +++++-----
trace/simple.c | 2 +-
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py
index 8bbcb42..b9aeb56 100755
--- a/scripts/simpletrace.py
+++ b/scripts/simpletrace.py
@@ -65,13 +65,13 @@ def read_trace_file(edict, fobj):
header[0] != header_event_id or \
header[1] != header_magic:
raise ValueError('Not a valid trace file!')
- if header[2] != 0 and \
- header[2] != 2:
- raise ValueError('Unknown version of tracelog format!')
log_version = header[2]
- if log_version == 0:
- raise ValueError('Older log format, not supported with this QEMU release!')
+ if log_version not in [0, 2, 3]:
+ raise ValueError('Unknown version of tracelog format!')
+ if log_version != 3:
+ raise ValueError('Log format %d not supported with this QEMU release!'
+ % log_version)
while True:
rec = read_record(edict, fobj)
diff --git a/trace/simple.c b/trace/simple.c
index aaa010e..bb0b52c 100644
--- a/trace/simple.c
+++ b/trace/simple.c
@@ -28,7 +28,7 @@
#define HEADER_MAGIC 0xf2b177cb0aa429b4ULL
/** Trace file version number, bump if format changes */
-#define HEADER_VERSION 2
+#define HEADER_VERSION 3
/** Records were dropped event ID */
#define DROPPED_EVENT_ID (~(uint64_t)0 - 1)
--
1.9.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [Qemu-devel] [PULL 8/9] trace: [tracetool] Minimize the amount of per-backend code
2014-06-09 13:45 [Qemu-devel] [PULL 0/5] Tracing patches Stefan Hajnoczi
` (11 preceding siblings ...)
2014-06-09 13:45 ` [Qemu-devel] [PULL 7/9] trace: [simple] Bump up log version number Stefan Hajnoczi
@ 2014-06-09 13:45 ` Stefan Hajnoczi
2014-06-09 13:45 ` [Qemu-devel] [PULL 9/9] configure: Show trace output file conditionally Stefan Hajnoczi
2014-06-09 14:24 ` [Qemu-devel] [PULL 0/5] Tracing patches Stefan Hajnoczi
14 siblings, 0 replies; 21+ messages in thread
From: Stefan Hajnoczi @ 2014-06-09 13:45 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Lluís Vilanova, Stefan Hajnoczi
From: Lluís Vilanova <vilanova@ac.upc.edu>
Backends now only contain the essential backend-specific code, and most of the work is moved to frontend code.
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
scripts/simpletrace.py | 6 +-
scripts/tracetool/__init__.py | 19 +----
scripts/tracetool/backend/__init__.py | 72 ++++++++---------
scripts/tracetool/backend/dtrace.py | 79 ++-----------------
scripts/tracetool/backend/events.py | 23 ------
scripts/tracetool/backend/ftrace.py | 56 ++++++-------
scripts/tracetool/backend/simple.py | 130 +++++++++++++++----------------
scripts/tracetool/backend/stderr.py | 42 ++++------
scripts/tracetool/backend/ust.py | 64 ++-------------
scripts/tracetool/format/__init__.py | 46 ++++-------
scripts/tracetool/format/c.py | 12 ++-
scripts/tracetool/format/d.py | 26 ++++++-
scripts/tracetool/format/events_c.py | 11 +--
scripts/tracetool/format/events_h.py | 11 +--
scripts/tracetool/format/h.py | 24 +++---
scripts/tracetool/format/stap.py | 42 +++++++++-
scripts/tracetool/format/ust_events_c.py | 5 +-
scripts/tracetool/format/ust_events_h.py | 40 +++++++++-
trace/Makefile.objs | 4 +-
19 files changed, 310 insertions(+), 402 deletions(-)
delete mode 100644 scripts/tracetool/backend/events.py
diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py
index b9aeb56..800835a 100755
--- a/scripts/simpletrace.py
+++ b/scripts/simpletrace.py
@@ -109,14 +109,10 @@ def process(events, log, analyzer):
if isinstance(log, str):
log = open(log, 'rb')
- enabled_events = []
dropped_event = Event.build("Dropped_Event(uint64_t num_events_dropped)")
edict = {dropped_event_id: dropped_event}
- for e in events:
- if 'disable' not in e.properties:
- enabled_events.append(e)
- for num, event in enumerate(enabled_events):
+ for num, event in enumerate(events):
edict[num] = event
def build_fn(analyzer, event):
diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
index 7abffb6..eccf552 100644
--- a/scripts/tracetool/__init__.py
+++ b/scripts/tracetool/__init__.py
@@ -266,10 +266,7 @@ def generate(fevents, format, backend,
if not tracetool.backend.exists(backend):
raise TracetoolError("unknown backend: %s" % backend)
backend = backend.replace("-", "_")
-
- if not tracetool.backend.compatible(backend, format):
- raise TracetoolError("backend '%s' not compatible with format '%s'" %
- (backend, format))
+ backend = tracetool.backend.Wrapper(backend, format)
import tracetool.backend.dtrace
tracetool.backend.dtrace.BINARY = binary
@@ -277,16 +274,4 @@ def generate(fevents, format, backend,
events = _read_events(fevents)
- if backend == "nop":
- ( e.properies.add("disable") for e in events )
-
- tracetool.format.generate_begin(format, events)
- tracetool.backend.generate("nop", format,
- [ e
- for e in events
- if "disable" in e.properties ])
- tracetool.backend.generate(backend, format,
- [ e
- for e in events
- if "disable" not in e.properties ])
- tracetool.format.generate_end(format, events)
+ tracetool.format.generate(events, format, backend)
diff --git a/scripts/tracetool/backend/__init__.py b/scripts/tracetool/backend/__init__.py
index 88f94fd..5e36f04 100644
--- a/scripts/tracetool/backend/__init__.py
+++ b/scripts/tracetool/backend/__init__.py
@@ -30,17 +30,24 @@ PUBLIC If exists and is set to 'True', the backend is considered "public".
Backend functions
-----------------
-======== =======================================================================
-Function Description
-======== =======================================================================
-<format> Called to generate the format- and backend-specific code for each of
- the specified events. If the function does not exist, the backend is
- considered not compatible with the given format.
-======== =======================================================================
+All the following functions are optional, and no output will be generated if
+they do not exist.
+
+=============================== ==============================================
+Function Description
+=============================== ==============================================
+generate_<format>_begin(events) Generate backend- and format-specific file
+ header contents.
+generate_<format>_end(events) Generate backend- and format-specific file
+ footer contents.
+generate_<format>(event) Generate backend- and format-specific contents
+ for the given event.
+=============================== ==============================================
+
"""
__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
-__copyright__ = "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>"
+__copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
__license__ = "GPL version 2 or (at your option) any later version"
__maintainer__ = "Stefan Hajnoczi"
@@ -91,39 +98,24 @@ def exists(name):
return tracetool.try_import("tracetool.backend." + name)[1]
-def compatible(backend, format):
- """Whether a backend is compatible with the given format."""
- if not exists(backend):
- raise ValueError("unknown backend: %s" % backend)
-
- backend = backend.replace("-", "_")
- format = format.replace("-", "_")
-
- if backend == "nop":
- return True
- else:
- func = tracetool.try_import("tracetool.backend." + backend,
- format, None)[1]
- return func is not None
-
-
-def _empty(events):
- pass
+class Wrapper:
+ def __init__(self, backend, format):
+ self._backend = backend.replace("-", "_")
+ self._format = format.replace("-", "_")
+ assert exists(self._backend)
+ assert tracetool.format.exists(self._format)
-def generate(backend, format, events):
- """Generate the per-event output for the given (backend, format) pair."""
- if not compatible(backend, format):
- raise ValueError("backend '%s' not compatible with format '%s'" %
- (backend, format))
+ def _run_function(self, name, *args, **kwargs):
+ func = tracetool.try_import("tracetool.backend." + self._backend,
+ name % self._format, None)[1]
+ if func is not None:
+ func(*args, **kwargs)
- backend = backend.replace("-", "_")
- format = format.replace("-", "_")
+ def generate_begin(self, events):
+ self._run_function("generate_%s_begin", events)
- if backend == "nop":
- func = tracetool.try_import("tracetool.format." + format,
- "nop", _empty)[1]
- else:
- func = tracetool.try_import("tracetool.backend." + backend,
- format, None)[1]
+ def generate(self, event):
+ self._run_function("generate_%s", event)
- func(events)
+ def generate_end(self, events):
+ self._run_function("generate_%s_end", events)
diff --git a/scripts/tracetool/backend/dtrace.py b/scripts/tracetool/backend/dtrace.py
index 3c369c4..fabfe99 100644
--- a/scripts/tracetool/backend/dtrace.py
+++ b/scripts/tracetool/backend/dtrace.py
@@ -21,7 +21,7 @@ PUBLIC = True
PROBEPREFIX = None
-def _probeprefix():
+def probeprefix():
if PROBEPREFIX is None:
raise ValueError("you must set PROBEPREFIX")
return PROBEPREFIX
@@ -29,81 +29,18 @@ def _probeprefix():
BINARY = None
-def _binary():
+def binary():
if BINARY is None:
raise ValueError("you must set BINARY")
return BINARY
-def c(events):
- pass
-
-
-def h(events):
+def generate_h_begin(events):
out('#include "trace/generated-tracers-dtrace.h"',
'')
- for e in events:
- out('static inline void %(api)s(%(args)s) {',
- ' QEMU_%(uppername)s(%(argnames)s);',
- '}',
- api = e.api(),
- args = e.args,
- uppername = e.name.upper(),
- argnames = ", ".join(e.args.names()),
- )
-
-
-def d(events):
- out('provider qemu {')
-
- for e in events:
- args = str(e.args)
-
- # DTrace provider syntax expects foo() for empty
- # params, not foo(void)
- if args == 'void':
- args = ''
-
- # Define prototype for probe arguments
- out('',
- 'probe %(name)s(%(args)s);',
- name = e.name,
- args = args,
- )
-
- out('',
- '};')
-
-
-# Technically 'self' is not used by systemtap yet, but
-# they recommended we keep it in the reserved list anyway
-RESERVED_WORDS = (
- 'break', 'catch', 'continue', 'delete', 'else', 'for',
- 'foreach', 'function', 'global', 'if', 'in', 'limit',
- 'long', 'next', 'probe', 'return', 'self', 'string',
- 'try', 'while'
- )
-
-def stap(events):
- for e in events:
- # Define prototype for probe arguments
- out('probe %(probeprefix)s.%(name)s = process("%(binary)s").mark("%(name)s")',
- '{',
- probeprefix = _probeprefix(),
- name = e.name,
- binary = _binary(),
- )
-
- i = 1
- if len(e.args) > 0:
- for name in e.args.names():
- # Append underscore to reserved keywords
- if name in RESERVED_WORDS:
- name += '_'
- out(' %s = $arg%d;' % (name, i))
- i += 1
-
- out('}')
-
- out()
+
+def generate_h(event):
+ out(' QEMU_%(uppername)s(%(argnames)s);',
+ uppername=event.name.upper(),
+ argnames=", ".join(event.args.names()))
diff --git a/scripts/tracetool/backend/events.py b/scripts/tracetool/backend/events.py
deleted file mode 100644
index 5afce3e..0000000
--- a/scripts/tracetool/backend/events.py
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-"""
-Generic event description.
-
-This is a dummy backend to establish appropriate frontend/backend compatibility
-checks.
-"""
-
-__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
-__copyright__ = "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>"
-__license__ = "GPL version 2 or (at your option) any later version"
-
-__maintainer__ = "Stefan Hajnoczi"
-__email__ = "stefanha@linux.vnet.ibm.com"
-
-
-def events_h(events):
- pass
-
-def events_c(events):
- pass
diff --git a/scripts/tracetool/backend/ftrace.py b/scripts/tracetool/backend/ftrace.py
index 888c361..d798c71 100644
--- a/scripts/tracetool/backend/ftrace.py
+++ b/scripts/tracetool/backend/ftrace.py
@@ -19,36 +19,30 @@ from tracetool import out
PUBLIC = True
-def c(events):
- pass
-
-def h(events):
+def generate_h_begin(events):
out('#include "trace/ftrace.h"',
'#include "trace/control.h"',
- '',
- )
-
- for e in events:
- argnames = ", ".join(e.args.names())
- if len(e.args) > 0:
- argnames = ", " + argnames
-
- out('static inline void trace_%(name)s(%(args)s)',
- '{',
- ' char ftrace_buf[MAX_TRACE_STRLEN];',
- ' int unused __attribute__ ((unused));',
- ' int trlen;',
- ' bool _state = trace_event_get_state(%(event_id)s);',
- ' if (_state) {',
- ' trlen = snprintf(ftrace_buf, MAX_TRACE_STRLEN,',
- ' "%(name)s " %(fmt)s "\\n" %(argnames)s);',
- ' trlen = MIN(trlen, MAX_TRACE_STRLEN - 1);',
- ' unused = write(trace_marker_fd, ftrace_buf, trlen);',
- ' }',
- '}',
- name = e.name,
- args = e.args,
- event_id = "TRACE_" + e.name.upper(),
- fmt = e.fmt.rstrip("\n"),
- argnames = argnames,
- )
+ '')
+
+
+def generate_h(event):
+ argnames = ", ".join(event.args.names())
+ if len(event.args) > 0:
+ argnames = ", " + argnames
+
+ out(' {',
+ ' char ftrace_buf[MAX_TRACE_STRLEN];',
+ ' int unused __attribute__ ((unused));',
+ ' int trlen;',
+ ' if (trace_event_get_state(%(event_id)s)) {',
+ ' trlen = snprintf(ftrace_buf, MAX_TRACE_STRLEN,',
+ ' "%(name)s " %(fmt)s "\\n" %(argnames)s);',
+ ' trlen = MIN(trlen, MAX_TRACE_STRLEN - 1);',
+ ' unused = write(trace_marker_fd, ftrace_buf, trlen);',
+ ' }',
+ ' }',
+ name=event.name,
+ args=event.args,
+ event_id="TRACE_" + event.name.upper(),
+ fmt=event.fmt.rstrip("\n"),
+ argnames=argnames)
diff --git a/scripts/tracetool/backend/simple.py b/scripts/tracetool/backend/simple.py
index ca48e12..e8c2cd5 100644
--- a/scripts/tracetool/backend/simple.py
+++ b/scripts/tracetool/backend/simple.py
@@ -26,76 +26,74 @@ def is_string(arg):
else:
return False
-def c(events):
+
+def generate_h_begin(events):
+ for event in events:
+ out('void _simple_%(api)s(%(args)s);',
+ api=event.api(),
+ args=event.args)
+ out('')
+
+
+def generate_h(event):
+ out(' _simple_%(api)s(%(args)s);',
+ api=event.api(),
+ args=", ".join(event.args.names()))
+
+
+def generate_c_begin(events):
out('#include "trace.h"',
'#include "trace/control.h"',
'#include "trace/simple.h"',
+ '')
+
+
+def generate_c(event):
+ out('void _simple_%(api)s(%(args)s)',
+ '{',
+ ' TraceBufferRecord rec;',
+ api=event.api(),
+ args=event.args)
+ sizes = []
+ for type_, name in event.args:
+ if is_string(type_):
+ out(' size_t arg%(name)s_len = %(name)s ? MIN(strlen(%(name)s), MAX_TRACE_STRLEN) : 0;',
+ name=name)
+ strsizeinfo = "4 + arg%s_len" % name
+ sizes.append(strsizeinfo)
+ else:
+ sizes.append("8")
+ sizestr = " + ".join(sizes)
+ if len(event.args) == 0:
+ sizestr = '0'
+
+
+ out('',
+ ' if (!trace_event_get_state(%(event_id)s)) {',
+ ' return;',
+ ' }',
'',
- )
-
- for num, event in enumerate(events):
- out('void %(api)s(%(args)s)',
- '{',
- ' TraceBufferRecord rec;',
- api = event.api(),
- args = event.args,
- )
- sizes = []
+ ' if (trace_record_start(&rec, %(event_id)s, %(size_str)s)) {',
+ ' return; /* Trace Buffer Full, Event Dropped ! */',
+ ' }',
+ event_id='TRACE_' + event.name.upper(),
+ size_str=sizestr)
+
+ if len(event.args) > 0:
for type_, name in event.args:
+ # string
if is_string(type_):
- out(' size_t arg%(name)s_len = %(name)s ? MIN(strlen(%(name)s), MAX_TRACE_STRLEN) : 0;',
- name = name,
- )
- strsizeinfo = "4 + arg%s_len" % name
- sizes.append(strsizeinfo)
+ out(' trace_record_write_str(&rec, %(name)s, arg%(name)s_len);',
+ name=name)
+ # pointer var (not string)
+ elif type_.endswith('*'):
+ out(' trace_record_write_u64(&rec, (uintptr_t)(uint64_t *)%(name)s);',
+ name=name)
+ # primitive data type
else:
- sizes.append("8")
- sizestr = " + ".join(sizes)
- if len(event.args) == 0:
- sizestr = '0'
-
-
- out('',
- ' TraceEvent *eventp = trace_event_id(%(event_enum)s);',
- ' bool _state = trace_event_get_state_dynamic(eventp);',
- ' if (!_state) {',
- ' return;',
- ' }',
- '',
- ' if (trace_record_start(&rec, %(event_id)s, %(size_str)s)) {',
- ' return; /* Trace Buffer Full, Event Dropped ! */',
- ' }',
- event_enum = 'TRACE_' + event.name.upper(),
- event_id = num,
- size_str = sizestr,
- )
-
- if len(event.args) > 0:
- for type_, name in event.args:
- # string
- if is_string(type_):
- out(' trace_record_write_str(&rec, %(name)s, arg%(name)s_len);',
- name = name,
- )
- # pointer var (not string)
- elif type_.endswith('*'):
- out(' trace_record_write_u64(&rec, (uintptr_t)(uint64_t *)%(name)s);',
- name = name,
- )
- # primitive data type
- else:
- out(' trace_record_write_u64(&rec, (uint64_t)%(name)s);',
- name = name,
- )
-
- out(' trace_record_finish(&rec);',
- '}',
- '')
-
-
-def h(events):
- for event in events:
- out('void %(api)s(%(args)s);',
- api = event.api(),
- args = event.args,
- )
+ out(' trace_record_write_u64(&rec, (uint64_t)%(name)s);',
+ name=name)
+
+ out(' trace_record_finish(&rec);',
+ '}',
+ '')
diff --git a/scripts/tracetool/backend/stderr.py b/scripts/tracetool/backend/stderr.py
index 6681e26..2a1e906 100644
--- a/scripts/tracetool/backend/stderr.py
+++ b/scripts/tracetool/backend/stderr.py
@@ -19,31 +19,21 @@ from tracetool import out
PUBLIC = True
-def c(events):
- pass
-
-def h(events):
+def generate_h_begin(events):
out('#include <stdio.h>',
'#include "trace/control.h"',
- '',
- )
-
- for e in events:
- argnames = ", ".join(e.args.names())
- if len(e.args) > 0:
- argnames = ", " + argnames
-
- out('static inline void %(api)s(%(args)s)',
- '{',
- ' bool _state = trace_event_get_state(%(event_id)s);',
- ' if (_state) {',
- ' fprintf(stderr, "%(name)s " %(fmt)s "\\n" %(argnames)s);',
- ' }',
- '}',
- api = e.api(),
- name = e.name,
- args = e.args,
- event_id = "TRACE_" + e.name.upper(),
- fmt = e.fmt.rstrip("\n"),
- argnames = argnames,
- )
+ '')
+
+
+def generate_h(event):
+ argnames = ", ".join(event.args.names())
+ if len(event.args) > 0:
+ argnames = ", " + argnames
+
+ out(' if (trace_event_get_state(%(event_id)s)) {',
+ ' fprintf(stderr, "%(name)s " %(fmt)s "\\n" %(argnames)s);',
+ ' }',
+ event_id="TRACE_" + event.name.upper(),
+ name=event.name,
+ fmt=event.fmt.rstrip("\n"),
+ argnames=argnames)
diff --git a/scripts/tracetool/backend/ust.py b/scripts/tracetool/backend/ust.py
index 2fca4d2..2f8f44a 100644
--- a/scripts/tracetool/backend/ust.py
+++ b/scripts/tracetool/backend/ust.py
@@ -18,66 +18,18 @@ from tracetool import out
PUBLIC = True
-def c(events):
- pass
-
-def h(events):
+def generate_h_begin(events):
out('#include <lttng/tracepoint.h>',
'#include "trace/generated-ust-provider.h"',
'')
- for e in events:
- argnames = ", ".join(e.args.names())
- if len(e.args) > 0:
- argnames = ", " + argnames
-
- out('static inline void %(api)s(%(args)s)',
- '{',
- ' tracepoint(qemu, %(name)s%(tp_args)s);',
- '}',
- '',
- api = e.api()
- name = e.name,
- args = e.args,
- tp_args = argnames,
- )
-
-def ust_events_c(events):
- pass
-
-def ust_events_h(events):
- for e in events:
- if len(e.args) > 0:
- out('TRACEPOINT_EVENT(',
- ' qemu,',
- ' %(name)s,',
- ' TP_ARGS(%(args)s),',
- ' TP_FIELDS(',
- name = e.name,
- args = ", ".join(", ".join(i) for i in e.args),
- )
- for t,n in e.args:
- if ('int' in t) or ('long' in t) or ('unsigned' in t) or ('size_t' in t):
- out(' ctf_integer(' + t + ', ' + n + ', ' + n + ')')
- elif ('double' in t) or ('float' in t):
- out(' ctf_float(' + t + ', ' + n + ', ' + n + ')')
- elif ('char *' in t) or ('char*' in t):
- out(' ctf_string(' + n + ', ' + n + ')')
- elif ('void *' in t) or ('void*' in t):
- out(' ctf_integer_hex(unsigned long, ' + n + ', ' + n + ')')
- out(' )',
- ')',
- '')
+def generate_h(event):
+ argnames = ", ".join(event.args.names())
+ if len(event.args) > 0:
+ argnames = ", " + argnames
- else:
- out('TRACEPOINT_EVENT(',
- ' qemu,',
- ' %(name)s,',
- ' TP_ARGS(void),',
- ' TP_FIELDS()',
- ')',
- '',
- name = e.name,
- )
+ out(' tracepoint(qemu, %(name)s%(tp_args)s);',
+ name=event.name,
+ tp_args=argnames)
diff --git a/scripts/tracetool/format/__init__.py b/scripts/tracetool/format/__init__.py
index 2bbbba7..812570f 100644
--- a/scripts/tracetool/format/__init__.py
+++ b/scripts/tracetool/format/__init__.py
@@ -20,17 +20,12 @@ All formats must generate their contents through the 'tracetool.out' routine.
Format functions
----------------
-All the following functions are optional, and no output will be generated if
-they do not exist.
-
-======== =======================================================================
+======== ==================================================================
Function Description
-======== =======================================================================
-begin Called to generate the format-specific file header.
-end Called to generate the format-specific file footer.
-nop Called to generate the per-event contents when the event is disabled or
- the selected backend is 'nop'.
-======== =======================================================================
+======== ==================================================================
+generate Called to generate a format-specific file.
+======== ==================================================================
+
"""
__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
@@ -79,25 +74,12 @@ def exists(name):
return tracetool.try_import("tracetool.format." + name)[1]
-def _empty(events):
- pass
-
-def generate_begin(name, events):
- """Generate the header of the format-specific file."""
- if not exists(name):
- raise ValueError("unknown format: %s" % name)
-
- name = name.replace("-", "_")
- func = tracetool.try_import("tracetool.format." + name,
- "begin", _empty)[1]
- func(events)
-
-def generate_end(name, events):
- """Generate the footer of the format-specific file."""
- if not exists(name):
- raise ValueError("unknown format: %s" % name)
-
- name = name.replace("-", "_")
- func = tracetool.try_import("tracetool.format." + name,
- "end", _empty)[1]
- func(events)
+def generate(events, format, backend):
+ if not exists(format):
+ raise ValueError("unknown format: %s" % format)
+ format = format.replace("-", "_")
+ func = tracetool.try_import("tracetool.format." + format,
+ "generate")[1]
+ if func is None:
+ raise AttributeError("format has no 'generate': %s" % format)
+ func(events, backend)
diff --git a/scripts/tracetool/format/c.py b/scripts/tracetool/format/c.py
index 930140b..699598f 100644
--- a/scripts/tracetool/format/c.py
+++ b/scripts/tracetool/format/c.py
@@ -16,5 +16,13 @@ __email__ = "stefanha@linux.vnet.ibm.com"
from tracetool import out
-def begin(events):
- out('/* This file is autogenerated by tracetool, do not edit. */')
+def generate(events, backend):
+ events = [e for e in events
+ if "disable" not in e.properties]
+
+ out('/* This file is autogenerated by tracetool, do not edit. */',
+ '')
+ backend.generate_begin(events)
+ for event in events:
+ backend.generate(event)
+ backend.generate_end(events)
diff --git a/scripts/tracetool/format/d.py b/scripts/tracetool/format/d.py
index 74ee0d3..46eebb1 100644
--- a/scripts/tracetool/format/d.py
+++ b/scripts/tracetool/format/d.py
@@ -16,5 +16,27 @@ __email__ = "stefanha@linux.vnet.ibm.com"
from tracetool import out
-def begin(events):
- out('/* This file is autogenerated by tracetool, do not edit. */')
+def generate(events, backend):
+ events = [e for e in events
+ if "disable" not in e.properties]
+
+ out('/* This file is autogenerated by tracetool, do not edit. */'
+ '',
+ 'provider qemu {')
+
+ for e in events:
+ args = str(e.args)
+
+ # DTrace provider syntax expects foo() for empty
+ # params, not foo(void)
+ if args == 'void':
+ args = ''
+
+ # Define prototype for probe arguments
+ out('',
+ 'probe %(name)s(%(args)s);',
+ name=e.name,
+ args=args)
+
+ out('',
+ '};')
diff --git a/scripts/tracetool/format/events_c.py b/scripts/tracetool/format/events_c.py
index ea668ee..2d97fa3 100644
--- a/scripts/tracetool/format/events_c.py
+++ b/scripts/tracetool/format/events_c.py
@@ -16,14 +16,13 @@ __email__ = "stefanha@linux.vnet.ibm.com"
from tracetool import out
-def begin(events):
+def generate(events, backend):
out('/* This file is autogenerated by tracetool, do not edit. */',
'',
'#include "trace.h"',
'#include "trace/generated-events.h"',
'#include "trace/control.h"',
- '',
- )
+ '')
out('TraceEvent trace_events[TRACE_EVENT_COUNT] = {')
@@ -31,9 +30,7 @@ def begin(events):
out(' { .id = %(id)s, .name = \"%(name)s\", .sstate = %(sstate)s, .dstate = 0 },',
id = "TRACE_" + e.name.upper(),
name = e.name,
- sstate = "TRACE_%s_ENABLED" % e.name.upper(),
- )
+ sstate = "TRACE_%s_ENABLED" % e.name.upper())
out('};',
- '',
- )
+ '')
diff --git a/scripts/tracetool/format/events_h.py b/scripts/tracetool/format/events_h.py
index f3febae..25d913b 100644
--- a/scripts/tracetool/format/events_h.py
+++ b/scripts/tracetool/format/events_h.py
@@ -16,15 +16,14 @@ __email__ = "stefanha@linux.vnet.ibm.com"
from tracetool import out
-def begin(events):
+def generate(events, backend):
out('/* This file is autogenerated by tracetool, do not edit. */',
'',
'#ifndef TRACE__GENERATED_EVENTS_H',
'#define TRACE__GENERATED_EVENTS_H',
'',
'#include <stdbool.h>',
- ''
- )
+ '')
# event identifiers
out('typedef enum {')
@@ -33,8 +32,7 @@ def begin(events):
out(' TRACE_%s,' % e.name.upper())
out(' TRACE_EVENT_COUNT',
- '} TraceEventID;',
- )
+ '} TraceEventID;')
# static state
for e in events:
@@ -46,5 +44,4 @@ def begin(events):
out('#include "trace/event-internal.h"',
'',
- '#endif /* TRACE__GENERATED_EVENTS_H */',
- )
+ '#endif /* TRACE__GENERATED_EVENTS_H */')
diff --git a/scripts/tracetool/format/h.py b/scripts/tracetool/format/h.py
index 85f011f..9b39430 100644
--- a/scripts/tracetool/format/h.py
+++ b/scripts/tracetool/format/h.py
@@ -16,23 +16,29 @@ __email__ = "stefanha@linux.vnet.ibm.com"
from tracetool import out
-def begin(events):
+def generate(events, backend):
out('/* This file is autogenerated by tracetool, do not edit. */',
'',
'#ifndef TRACE__GENERATED_TRACERS_H',
'#define TRACE__GENERATED_TRACERS_H',
'',
- '#include "qemu-common.h"')
+ '#include "qemu-common.h"',
+ '')
-def end(events):
- out('#endif /* TRACE__GENERATED_TRACERS_H */')
+ backend.generate_begin(events)
-def nop(events):
for e in events:
out('',
'static inline void %(api)s(%(args)s)',
'{',
- '}',
- api = e.api(),
- args = e.args,
- )
+ api=e.api(),
+ args=e.args)
+
+ if "disable" not in e.properties:
+ backend.generate(e)
+
+ out('}')
+
+ backend.generate_end(events)
+
+ out('#endif /* TRACE__GENERATED_TRACERS_H */')
diff --git a/scripts/tracetool/format/stap.py b/scripts/tracetool/format/stap.py
index 50a4c69..e24abf7 100644
--- a/scripts/tracetool/format/stap.py
+++ b/scripts/tracetool/format/stap.py
@@ -6,7 +6,7 @@ Generate .stp file (DTrace with SystemTAP only).
"""
__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
-__copyright__ = "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>"
+__copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
__license__ = "GPL version 2 or (at your option) any later version"
__maintainer__ = "Stefan Hajnoczi"
@@ -14,7 +14,43 @@ __email__ = "stefanha@linux.vnet.ibm.com"
from tracetool import out
+from tracetool.backend.dtrace import binary, probeprefix
-def begin(events):
- out('/* This file is autogenerated by tracetool, do not edit. */')
+# Technically 'self' is not used by systemtap yet, but
+# they recommended we keep it in the reserved list anyway
+RESERVED_WORDS = (
+ 'break', 'catch', 'continue', 'delete', 'else', 'for',
+ 'foreach', 'function', 'global', 'if', 'in', 'limit',
+ 'long', 'next', 'probe', 'return', 'self', 'string',
+ 'try', 'while'
+ )
+
+
+def generate(events, backend):
+ events = [e for e in events
+ if "disable" not in e.properties]
+
+ out('/* This file is autogenerated by tracetool, do not edit. */',
+ '')
+
+ for e in events:
+ # Define prototype for probe arguments
+ out('probe %(probeprefix)s.%(name)s = process("%(binary)s").mark("%(name)s")',
+ '{',
+ probeprefix=probeprefix(),
+ name=e.name,
+ binary=binary())
+
+ i = 1
+ if len(e.args) > 0:
+ for name in e.args.names():
+ # Append underscore to reserved keywords
+ if name in RESERVED_WORDS:
+ name += '_'
+ out(' %s = $arg%d;' % (name, i))
+ i += 1
+
+ out('}')
+
+ out()
diff --git a/scripts/tracetool/format/ust_events_c.py b/scripts/tracetool/format/ust_events_c.py
index d048b0a..bc97093 100644
--- a/scripts/tracetool/format/ust_events_c.py
+++ b/scripts/tracetool/format/ust_events_c.py
@@ -16,7 +16,10 @@ __email__ = "stefanha@redhat.com"
from tracetool import out
-def begin(events):
+def generate(events, backend):
+ events = [e for e in events
+ if "disabled" not in e.properties]
+
out('/* This file is autogenerated by tracetool, do not edit. */',
'',
'#define TRACEPOINT_DEFINE',
diff --git a/scripts/tracetool/format/ust_events_h.py b/scripts/tracetool/format/ust_events_h.py
index a3ef785..5102565 100644
--- a/scripts/tracetool/format/ust_events_h.py
+++ b/scripts/tracetool/format/ust_events_h.py
@@ -16,7 +16,10 @@ __email__ = "stefanha@redhat.com"
from tracetool import out
-def begin(events):
+def generate(events, backend):
+ events = [e for e in events
+ if "disabled" not in e.properties]
+
out('/* This file is autogenerated by tracetool, do not edit. */',
'',
'#undef TRACEPOINT_PROVIDER',
@@ -50,7 +53,40 @@ def begin(events):
'#endif',
'')
-def end(events):
+ for e in events:
+ if len(e.args) > 0:
+ out('TRACEPOINT_EVENT(',
+ ' qemu,',
+ ' %(name)s,',
+ ' TP_ARGS(%(args)s),',
+ ' TP_FIELDS(',
+ name=e.name,
+ args=", ".join(", ".join(i) for i in e.args))
+
+ for t, n in e.args:
+ if ('int' in t) or ('long' in t) or ('unsigned' in t) or ('size_t' in t):
+ out(' ctf_integer(' + t + ', ' + n + ', ' + n + ')')
+ elif ('double' in t) or ('float' in t):
+ out(' ctf_float(' + t + ', ' + n + ', ' + n + ')')
+ elif ('char *' in t) or ('char*' in t):
+ out(' ctf_string(' + n + ', ' + n + ')')
+ elif ('void *' in t) or ('void*' in t):
+ out(' ctf_integer_hex(unsigned long, ' + n + ', ' + n + ')')
+
+ out(' )',
+ ')',
+ '')
+
+ else:
+ out('TRACEPOINT_EVENT(',
+ ' qemu,',
+ ' %(name)s,',
+ ' TP_ARGS(void),',
+ ' TP_FIELDS()',
+ ')',
+ '',
+ name=e.name)
+
out('#endif /* TRACE__GENERATED_UST_H */',
'',
'/* This part must be outside ifdef protection */',
diff --git a/trace/Makefile.objs b/trace/Makefile.objs
index d321946..6a30467 100644
--- a/trace/Makefile.objs
+++ b/trace/Makefile.objs
@@ -31,7 +31,7 @@ $(obj)/generated-events.h: $(obj)/generated-events.h-timestamp
$(obj)/generated-events.h-timestamp: $(SRC_PATH)/trace-events
$(call quiet-command,$(TRACETOOL) \
--format=events-h \
- --backend=events \
+ --backend=$(TRACE_BACKEND) \
< $< > $@," GEN $(patsubst %-timestamp,%,$@)")
@cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@)
@@ -39,7 +39,7 @@ $(obj)/generated-events.c: $(obj)/generated-events.c-timestamp $(BUILD_DIR)/conf
$(obj)/generated-events.c-timestamp: $(SRC_PATH)/trace-events
$(call quiet-command,$(TRACETOOL) \
--format=events-c \
- --backend=events \
+ --backend=$(TRACE_BACKEND) \
< $< > $@," GEN $(patsubst %-timestamp,%,$@)")
@cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp,%,$@)
--
1.9.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [Qemu-devel] [PULL 9/9] configure: Show trace output file conditionally
2014-06-09 13:45 [Qemu-devel] [PULL 0/5] Tracing patches Stefan Hajnoczi
` (12 preceding siblings ...)
2014-06-09 13:45 ` [Qemu-devel] [PULL 8/9] trace: [tracetool] Minimize the amount of per-backend code Stefan Hajnoczi
@ 2014-06-09 13:45 ` Stefan Hajnoczi
2014-06-09 14:24 ` [Qemu-devel] [PULL 0/5] Tracing patches Stefan Hajnoczi
14 siblings, 0 replies; 21+ messages in thread
From: Stefan Hajnoczi @ 2014-06-09 13:45 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Stefan Hajnoczi, Stefan Weil
From: Stefan Weil <sw@weilnetz.de>
It is only used with the simple trace backend.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
configure | 2 ++
1 file changed, 2 insertions(+)
diff --git a/configure b/configure
index 8c50d78..1c6e64b 100755
--- a/configure
+++ b/configure
@@ -4145,7 +4145,9 @@ echo "libcap-ng support $cap_ng"
echo "vhost-net support $vhost_net"
echo "vhost-scsi support $vhost_scsi"
echo "Trace backend $trace_backend"
+if test "$trace_backend" = "simple"; then
echo "Trace output file $trace_file-<pid>"
+fi
if test "$spice" = "yes"; then
echo "spice support $spice ($spice_protocol_version/$spice_server_version)"
else
--
1.9.0
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [Qemu-devel] [PULL 0/5] Tracing patches
2014-06-09 13:45 [Qemu-devel] [PULL 0/5] Tracing patches Stefan Hajnoczi
` (13 preceding siblings ...)
2014-06-09 13:45 ` [Qemu-devel] [PULL 9/9] configure: Show trace output file conditionally Stefan Hajnoczi
@ 2014-06-09 14:24 ` Stefan Hajnoczi
14 siblings, 0 replies; 21+ messages in thread
From: Stefan Hajnoczi @ 2014-06-09 14:24 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: Peter Maydell, qemu-devel
On Mon, Jun 9, 2014 at 3:45 PM, Stefan Hajnoczi <stefanha@redhat.com> wrote:
> The following changes since commit 959e41473f2179850578482052fb73b913bc4e42:
Please ignore. This pull request email thread also includes patch
emails from the last tracing pull request.
I will resend the 5 patches from this week's pull request properly.
Stefan
^ permalink raw reply [flat|nested] 21+ messages in thread