Blame SOURCES/kvm-simpletrace-add-support-for-trace-record-pid-field.patch

958e1b
From c319a5160a1b86c5cfa288cdf36e7473f8c38515 Mon Sep 17 00:00:00 2001
958e1b
From: Stefan Hajnoczi <stefanha@redhat.com>
958e1b
Date: Tue, 7 Oct 2014 14:06:52 +0200
958e1b
Subject: [PATCH 34/43] simpletrace: add support for trace record pid field
958e1b
958e1b
Message-id: <1412690820-31016-4-git-send-email-stefanha@redhat.com>
958e1b
Patchwork-id: 61608
958e1b
O-Subject: [RHEL7.1 qemu-kvm PATCH 03/11] simpletrace: add support for trace record pid field
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
Extract the pid field from the trace record and print it.
958e1b
958e1b
Change the trace record tuple from:
958e1b
  (event_num, timestamp, arg1, ..., arg6)
958e1b
to:
958e1b
  (event_num, timestamp, pid, arg1, ..., arg6)
958e1b
958e1b
Trace event methods now support 3 prototypes:
958e1b
1. <event-name>(arg1, arg2, arg3)
958e1b
2. <event-name>(timestamp, arg1, arg2, arg3)
958e1b
3. <event-name>(timestamp, pid, arg1, arg2, arg3)
958e1b
958e1b
Existing script continue to work without changes, they only know about
958e1b
prototypes 1 and 2.
958e1b
958e1b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
958e1b
(cherry picked from commit 80ff35cd3ff451e8f200413ddf27816058630c1f)
958e1b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
958e1b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
958e1b
---
958e1b
 scripts/simpletrace.py | 26 +++++++++++++++-----------
958e1b
 1 file changed, 15 insertions(+), 11 deletions(-)
958e1b
958e1b
diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py
958e1b
index 3cb2cf0..682ec66 100755
958e1b
--- a/scripts/simpletrace.py
958e1b
+++ b/scripts/simpletrace.py
958e1b
@@ -32,10 +32,10 @@ def read_header(fobj, hfmt):
958e1b
     return struct.unpack(hfmt, hdr)
958e1b
 
958e1b
 def get_record(edict, rechdr, fobj):
958e1b
-    """Deserialize a trace record from a file into a tuple (event_num, timestamp, arg1, ..., arg6)."""
958e1b
+    """Deserialize a trace record from a file into a tuple (event_num, timestamp, pid, arg1, ..., arg6)."""
958e1b
     if rechdr is None:
958e1b
         return None
958e1b
-    rec = (rechdr[0], rechdr[1])
958e1b
+    rec = (rechdr[0], rechdr[1], rechdr[3])
958e1b
     if rechdr[0] != dropped_event_id:
958e1b
         event_id = rechdr[0]
958e1b
         event = edict[event_id]
958e1b
@@ -55,12 +55,12 @@ def get_record(edict, rechdr, fobj):
958e1b
 
958e1b
 
958e1b
 def read_record(edict, fobj):
958e1b
-    """Deserialize a trace record from a file into a tuple (event_num, timestamp, arg1, ..., arg6)."""
958e1b
+    """Deserialize a trace record from a file into a tuple (event_num, timestamp, pid, arg1, ..., arg6)."""
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, arg1, ..., arg6)."""
958e1b
+    """Deserialize trace records from a file, yielding record tuples (event_num, timestamp, pid, arg1, ..., arg6)."""
958e1b
     header = read_header(fobj, log_header_fmt)
958e1b
     if header is None or \
958e1b
        header[0] != header_event_id or \
958e1b
@@ -132,10 +132,13 @@ def process(events, log, analyzer):
958e1b
         fn_argcount = len(inspect.getargspec(fn)[0]) - 1
958e1b
         if fn_argcount == event_argcount + 1:
958e1b
             # Include timestamp as first argument
958e1b
-            return lambda _, rec: fn(*rec[1:2 + event_argcount])
958e1b
+            return lambda _, rec: fn(*((rec[1:2],) + rec[3:3 + event_argcount]))
958e1b
+        elif fn_argcount == event_argcount + 2:
958e1b
+            # Include timestamp and pid
958e1b
+            return lambda _, rec: fn(*rec[1:3 + event_argcount])
958e1b
         else:
958e1b
-            # Just arguments, no timestamp
958e1b
-            return lambda _, rec: fn(*rec[2:2 + event_argcount])
958e1b
+            # Just arguments, no timestamp or pid
958e1b
+            return lambda _, rec: fn(*rec[3:3 + event_argcount])
958e1b
 
958e1b
     analyzer.begin()
958e1b
     fn_cache = {}
958e1b
@@ -167,19 +170,20 @@ if __name__ == '__main__':
958e1b
             self.last_timestamp = None
958e1b
 
958e1b
         def catchall(self, event, rec):
958e1b
-            i = 1
958e1b
             timestamp = rec[1]
958e1b
             if self.last_timestamp is None:
958e1b
                 self.last_timestamp = timestamp
958e1b
             delta_ns = timestamp - self.last_timestamp
958e1b
             self.last_timestamp = timestamp
958e1b
 
958e1b
-            fields = [event.name, '%0.3f' % (delta_ns / 1000.0)]
958e1b
+            fields = [event.name, '%0.3f' % (delta_ns / 1000.0),
958e1b
+                      'pid=%d' % rec[2]]
958e1b
+            i = 3
958e1b
             for type, name in event.args:
958e1b
                 if is_string(type):
958e1b
-                    fields.append('%s=%s' % (name, rec[i + 1]))
958e1b
+                    fields.append('%s=%s' % (name, rec[i]))
958e1b
                 else:
958e1b
-                    fields.append('%s=0x%x' % (name, rec[i + 1]))
958e1b
+                    fields.append('%s=0x%x' % (name, rec[i]))
958e1b
                 i += 1
958e1b
             print ' '.join(fields)
958e1b
 
958e1b
-- 
958e1b
1.8.3.1
958e1b