From: Tan, Li <[EMAIL PROTECTED]>

Currently kvmtrace is not portable, and prevent from copying
a trace file from big-endian target to little-endian
workstation for analysis.
In the patch, kvmtrace_format reads and checks the magic
number from trace log. if needed, then change bytes order
of all fields in records followed.

Signed-off-by: Tan Li <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>

diff --git a/user/kvmtrace_format b/user/kvmtrace_format
index 9e7cfd4..e6ec4e8 100755
--- a/user/kvmtrace_format
+++ b/user/kvmtrace_format
@@ -93,13 +93,14 @@ defs = read_defs(arg[0])
 # tsc_in means TSC data exists(1) or not(0).
 # if tsc_in == 0, TSC(Q) does not exists.
 #
-HDRREC = "III"
-TSCREC = "Q"
-D1REC  = "I"
-D2REC  = "II"
-D3REC  = "III"
-D4REC  = "IIII"
-D5REC  = "IIIII"
+HDRREC = "<III"
+TSCREC = "<Q"
+D1REC  = "<I"
+D2REC  = "<II"
+D3REC  = "<III"
+D4REC  = "<IIII"
+D5REC  = "<IIIII"
+KMAGIC  = "<I"
 
 last_tsc = 0
 
@@ -108,6 +109,30 @@ i=0
 while not interrupted:
     try:
         i=i+1
+
+        if i == 1:
+            line = sys.stdin.read(struct.calcsize(KMAGIC))
+            if not line:
+                break
+            kmgc = struct.unpack(KMAGIC, line)[0]
+
+            #firstly try to parse data file as little endian
+            # if "kvmtrace-metadata".kmagic != kmagic
+            # then data file must be big endian"
+            if kmgc != 0x12345678:
+                if kmgc != 0x78563412:
+                    print >> sys.stderr, "Bad data file: magic number error."
+                    break;
+                else:
+                    HDRREC = ">III"
+                    TSCREC = ">Q"
+                    D1REC  = ">I"
+                    D2REC  = ">II"
+                    D3REC  = ">III"
+                    D4REC  = ">IIII"
+                    D5REC  = ">IIIII"
+            continue
+
         line = sys.stdin.read(struct.calcsize(HDRREC))
         if not line:
             break
--
To unsubscribe from this list: send the line "unsubscribe kvm-commits" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to