|
|
9ae3a8 |
From ae603c6d842f7e7f1529f040ca463be2f2edd4c8 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
Date: Tue, 7 Oct 2014 14:06:53 +0200
|
|
|
9ae3a8 |
Subject: [PATCH 35/43] simpletrace: add simpletrace.py --no-header option
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Message-id: <1412690820-31016-5-git-send-email-stefanha@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 61609
|
|
|
9ae3a8 |
O-Subject: [RHEL7.1 qemu-kvm PATCH 04/11] simpletrace: add simpletrace.py --no-header option
|
|
|
9ae3a8 |
Bugzilla: 1088112
|
|
|
9ae3a8 |
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
It can be useful to read simpletrace files that have no header. For
|
|
|
9ae3a8 |
example, a ring buffer may not have a header record but can still be
|
|
|
9ae3a8 |
processed if the user is sure the file format version is compatible.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
$ scripts/simpletrace.py --no-header trace-events trace-file
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit 15327c3df049c9621ff9b542ccbfc3d17203d1f7)
|
|
|
9ae3a8 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Conflicts:
|
|
|
9ae3a8 |
scripts/simpletrace.py
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Context conflict because upstream doesn't have enabled_events[].
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
scripts/simpletrace.py | 25 ++++++++++++++++++-------
|
|
|
9ae3a8 |
1 file changed, 18 insertions(+), 7 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py
|
|
|
9ae3a8 |
index 682ec66..b931dd2 100755
|
|
|
9ae3a8 |
--- a/scripts/simpletrace.py
|
|
|
9ae3a8 |
+++ b/scripts/simpletrace.py
|
|
|
9ae3a8 |
@@ -59,8 +59,8 @@ def read_record(edict, fobj):
|
|
|
9ae3a8 |
rechdr = read_header(fobj, rec_header_fmt)
|
|
|
9ae3a8 |
return get_record(edict, rechdr, fobj) # return tuple of record elements
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-def read_trace_file(edict, fobj):
|
|
|
9ae3a8 |
- """Deserialize trace records from a file, yielding record tuples (event_num, timestamp, pid, arg1, ..., arg6)."""
|
|
|
9ae3a8 |
+def read_trace_header(fobj):
|
|
|
9ae3a8 |
+ """Read and verify trace file header"""
|
|
|
9ae3a8 |
header = read_header(fobj, log_header_fmt)
|
|
|
9ae3a8 |
if header is None or \
|
|
|
9ae3a8 |
header[0] != header_event_id or \
|
|
|
9ae3a8 |
@@ -74,6 +74,8 @@ def read_trace_file(edict, fobj):
|
|
|
9ae3a8 |
raise ValueError('Log format %d not supported with this QEMU release!'
|
|
|
9ae3a8 |
% log_version)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+def read_trace_records(edict, fobj):
|
|
|
9ae3a8 |
+ """Deserialize trace records from a file, yielding record tuples (event_num, timestamp, pid, arg1, ..., arg6)."""
|
|
|
9ae3a8 |
while True:
|
|
|
9ae3a8 |
rec = read_record(edict, fobj)
|
|
|
9ae3a8 |
if rec is None:
|
|
|
9ae3a8 |
@@ -103,7 +105,7 @@ class Analyzer(object):
|
|
|
9ae3a8 |
"""Called at the end of the trace."""
|
|
|
9ae3a8 |
pass
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-def process(events, log, analyzer):
|
|
|
9ae3a8 |
+def process(events, log, analyzer, read_header=True):
|
|
|
9ae3a8 |
"""Invoke an analyzer on each event in a log."""
|
|
|
9ae3a8 |
if isinstance(events, str):
|
|
|
9ae3a8 |
events = _read_events(open(events, 'r'))
|
|
|
9ae3a8 |
@@ -111,6 +113,10 @@ def process(events, log, analyzer):
|
|
|
9ae3a8 |
log = open(log, 'rb')
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
enabled_events = []
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if read_header:
|
|
|
9ae3a8 |
+ read_trace_header(log)
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
dropped_event = Event.build("Dropped_Event(uint64_t num_events_dropped)")
|
|
|
9ae3a8 |
edict = {dropped_event_id: dropped_event}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -142,7 +148,7 @@ def process(events, log, analyzer):
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
analyzer.begin()
|
|
|
9ae3a8 |
fn_cache = {}
|
|
|
9ae3a8 |
- for rec in read_trace_file(edict, log):
|
|
|
9ae3a8 |
+ for rec in read_trace_records(edict, log):
|
|
|
9ae3a8 |
event_num = rec[0]
|
|
|
9ae3a8 |
event = edict[event_num]
|
|
|
9ae3a8 |
if event_num not in fn_cache:
|
|
|
9ae3a8 |
@@ -157,12 +163,17 @@ def run(analyzer):
|
|
|
9ae3a8 |
advanced scripts will want to call process() instead."""
|
|
|
9ae3a8 |
import sys
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- if len(sys.argv) != 3:
|
|
|
9ae3a8 |
- sys.stderr.write('usage: %s <trace-events> <trace-file>\n' % sys.argv[0])
|
|
|
9ae3a8 |
+ read_header = True
|
|
|
9ae3a8 |
+ if len(sys.argv) == 4 and sys.argv[1] == '--no-header':
|
|
|
9ae3a8 |
+ read_header = False
|
|
|
9ae3a8 |
+ del sys.argv[1]
|
|
|
9ae3a8 |
+ elif len(sys.argv) != 3:
|
|
|
9ae3a8 |
+ sys.stderr.write('usage: %s [--no-header] <trace-events> ' \
|
|
|
9ae3a8 |
+ '<trace-file>\n' % sys.argv[0])
|
|
|
9ae3a8 |
sys.exit(1)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
events = _read_events(open(sys.argv[1], 'r'))
|
|
|
9ae3a8 |
- process(events, sys.argv[2], analyzer)
|
|
|
9ae3a8 |
+ process(events, sys.argv[2], analyzer, read_header=read_header)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if __name__ == '__main__':
|
|
|
9ae3a8 |
class Formatter(Analyzer):
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.8.3.1
|
|
|
9ae3a8 |
|