cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-simpletrace-add-simpletrace.py-no-header-option.patch

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