From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PULL 03/18] simpletrace: add simpletrace.py --no-header option
Date: Tue, 12 Aug 2014 14:37:40 +0100 [thread overview]
Message-ID: <1407850675-11890-4-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1407850675-11890-1-git-send-email-stefanha@redhat.com>
It can be useful to read simpletrace files that have no header. For
example, a ring buffer may not have a header record but can still be
processed if the user is sure the file format version is compatible.
$ scripts/simpletrace.py --no-header trace-events trace-file
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
scripts/simpletrace.py | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py
index 1aa9460..3916c6d 100755
--- a/scripts/simpletrace.py
+++ b/scripts/simpletrace.py
@@ -58,8 +58,8 @@ def read_record(edict, fobj):
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, pid, arg1, ..., arg6)."""
+def read_trace_header(fobj):
+ """Read and verify trace file header"""
header = read_header(fobj, log_header_fmt)
if header is None or \
header[0] != header_event_id or \
@@ -73,6 +73,8 @@ def read_trace_file(edict, fobj):
raise ValueError('Log format %d not supported with this QEMU release!'
% log_version)
+def read_trace_records(edict, fobj):
+ """Deserialize trace records from a file, yielding record tuples (event_num, timestamp, pid, arg1, ..., arg6)."""
while True:
rec = read_record(edict, fobj)
if rec is None:
@@ -102,13 +104,16 @@ class Analyzer(object):
"""Called at the end of the trace."""
pass
-def process(events, log, analyzer):
+def process(events, log, analyzer, read_header=True):
"""Invoke an analyzer on each event in a log."""
if isinstance(events, str):
events = _read_events(open(events, 'r'))
if isinstance(log, str):
log = open(log, 'rb')
+ if read_header:
+ read_trace_header(log)
+
dropped_event = Event.build("Dropped_Event(uint64_t num_events_dropped)")
edict = {dropped_event_id: dropped_event}
@@ -137,7 +142,7 @@ def process(events, log, analyzer):
analyzer.begin()
fn_cache = {}
- for rec in read_trace_file(edict, log):
+ for rec in read_trace_records(edict, log):
event_num = rec[0]
event = edict[event_num]
if event_num not in fn_cache:
@@ -152,12 +157,17 @@ def run(analyzer):
advanced scripts will want to call process() instead."""
import sys
- if len(sys.argv) != 3:
- sys.stderr.write('usage: %s <trace-events> <trace-file>\n' % sys.argv[0])
+ read_header = True
+ if len(sys.argv) == 4 and sys.argv[1] == '--no-header':
+ read_header = False
+ del sys.argv[1]
+ elif len(sys.argv) != 3:
+ sys.stderr.write('usage: %s [--no-header] <trace-events> ' \
+ '<trace-file>\n' % sys.argv[0])
sys.exit(1)
events = _read_events(open(sys.argv[1], 'r'))
- process(events, sys.argv[2], analyzer)
+ process(events, sys.argv[2], analyzer, read_header=read_header)
if __name__ == '__main__':
class Formatter(Analyzer):
--
1.9.3
next prev parent reply other threads:[~2014-08-12 13:38 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-12 13:37 [Qemu-devel] [PULL 00/18] Tracing patches Stefan Hajnoczi
2014-08-12 13:37 ` [Qemu-devel] [PULL 01/18] trace: extract stap_escape() function for reuse Stefan Hajnoczi
2014-08-12 13:37 ` [Qemu-devel] [PULL 02/18] trace: add tracetool simpletrace_stap format Stefan Hajnoczi
2014-08-12 13:37 ` Stefan Hajnoczi [this message]
2014-08-12 13:37 ` [Qemu-devel] [PULL 04/18] trace: install simpletrace SystemTap tapset Stefan Hajnoczi
2014-08-12 13:37 ` [Qemu-devel] [PULL 05/18] trace: [tcg] Add documentation Stefan Hajnoczi
2014-08-12 13:37 ` [Qemu-devel] [PULL 06/18] trace: [tcg] Argument type transformation rules Stefan Hajnoczi
2014-08-12 13:37 ` [Qemu-devel] [PULL 07/18] trace: [tcg] Argument type transformation machinery Stefan Hajnoczi
2014-08-12 13:37 ` [Qemu-devel] [PULL 08/18] trace: [tcg] Add 'tcg' event property Stefan Hajnoczi
2014-08-12 13:37 ` [Qemu-devel] [PULL 09/18] trace: [tcg] Declare TCG tracing helper routines Stefan Hajnoczi
2014-08-12 13:37 ` [Qemu-devel] [PULL 10/18] trace: [tcg] Define " Stefan Hajnoczi
2014-08-12 13:37 ` [Qemu-devel] [PULL 11/18] trace: [tcg] Define TCG tracing helper routine wrappers Stefan Hajnoczi
2014-08-12 13:37 ` [Qemu-devel] [PULL 12/18] trace: [tcg] Include TCG-tracing helpers Stefan Hajnoczi
2014-08-12 13:37 ` [Qemu-devel] [PULL 13/18] trace: [tcg] Generate TCG tracing routines Stefan Hajnoczi
2014-08-12 13:37 ` [Qemu-devel] [PULL 14/18] trace: [tcg] Include event definitions in "trace.h" Stefan Hajnoczi
2014-08-12 13:37 ` [Qemu-devel] [PULL 15/18] trace: [tcg] Include TCG-tracing header on all targets Stefan Hajnoczi
2014-08-12 13:37 ` [Qemu-devel] [PULL 16/18] trace: teach lttng backend to use format strings Stefan Hajnoczi
2014-08-12 13:37 ` [Qemu-devel] [PULL 17/18] trace: add some tcg tracing support Stefan Hajnoczi
2014-08-12 13:37 ` [Qemu-devel] [PULL 18/18] virtio-rng: add some trace events Stefan Hajnoczi
2014-08-15 16:43 ` [Qemu-devel] [PULL 00/18] Tracing patches Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1407850675-11890-4-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).