summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Hansson <andreas.hansson@arm.com>2014-03-23 11:11:46 -0400
committerAndreas Hansson <andreas.hansson@arm.com>2014-03-23 11:11:46 -0400
commit4dbffeb9870c77747f5c66add88c979cd40ca576 (patch)
tree6efe01038b7642cc4200dfba29e1145b2b1e41c9
parent9f018d2f5a1a673d04a227b5b28ae0717d50b3ef (diff)
downloadgem5-4dbffeb9870c77747f5c66add88c979cd40ca576.tar.xz
util: Add support for detection of gzipped packet traces
This patch adds support for automatically detecting a gzipped packet trace, thus accepting either a compressed or uncompressed trace.
-rwxr-xr-xutil/decode_packet_trace.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/util/decode_packet_trace.py b/util/decode_packet_trace.py
index 61a4c34ac..e6f36c295 100755
--- a/util/decode_packet_trace.py
+++ b/util/decode_packet_trace.py
@@ -48,6 +48,7 @@
# r,128,64,4000,0
# w,232123,64,500000,0
+import gzip
import protolib
import sys
@@ -81,7 +82,18 @@ def main():
exit(-1)
try:
- proto_in = open(sys.argv[1], 'rb')
+ # First see if this file is gzipped
+ try:
+ # Opening the file works even if it is not a gzip file
+ proto_in = gzip.open(sys.argv[1], 'rb')
+
+ # Force a check of the magic number by seeking in the
+ # file. If we do not do it here the error will occur when
+ # reading the first message.
+ proto_in.seek(1)
+ proto_in.seek(0)
+ except IOError:
+ proto_in = open(sys.argv[1], 'rb')
except IOError:
print "Failed to open ", sys.argv[1], " for reading"
exit(-1)
@@ -96,7 +108,7 @@ def main():
magic_number = proto_in.read(4)
if magic_number != "gem5":
- print "Unrecognized file"
+ print "Unrecognized file", sys.argv[1]
exit(-1)
print "Parsing packet header"