-#!/usr/bin/env python
+#!/usr/bin/env python2.7
# Copyright (c) 2013-2014 ARM Limited
# All rights reserved
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-# Authors: Andreas Hansson
# This script is used to dump protobuf packet traces to ASCII
-# format. It assumes that protoc has been executed and already
-# generated the Python package for the packet messages. This can
-# be done manually using:
-# protoc --python_out=. --proto_path=src/proto src/proto/packet.proto
-#
-# The ASCII trace format uses one line per request on the format cmd,
-# addr, size, tick,flags. For example:
-# r,128,64,4000,0
-# w,232123,64,500000,0
+# format.
-import gzip
+import os
import protolib
+import subprocess
import sys
-# Import the packet proto definitions. If they are not found, attempt
-# to generate them automatically. This assumes that the script is
-# executed from the gem5 root.
-try:
- import packet_pb2
-except:
- print "Did not find packet proto definitions, attempting to generate"
- from subprocess import call
- error = call(['protoc', '--python_out=util', '--proto_path=src/proto',
- 'src/proto/packet.proto'])
- if not error:
- print "Generated packet proto definitions"
-
- try:
- import google.protobuf
- except:
- print "Please install Python protobuf module"
- exit(-1)
-
- import packet_pb2
- else:
- print "Failed to import packet proto definitions"
- exit(-1)
+util_dir = os.path.dirname(os.path.realpath(__file__))
+# Make sure the proto definitions are up to date.
+subprocess.check_call(['make', '--quiet', '-C', util_dir, 'packet_pb2.py'])
+import packet_pb2
def main():
if len(sys.argv) != 3:
print "Usage: ", sys.argv[0], " <protobuf input> <ASCII output>"
exit(-1)
- try:
- # 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)
+ # Open the file in read mode
+ proto_in = protolib.openFileRd(sys.argv[1])
try:
ascii_out = open(sys.argv[2], 'w')
print "Object id:", header.obj_id
print "Tick frequency:", header.tick_freq
+ for id_string in header.id_strings:
+ print 'Master id %d: %s' % (id_string.key, id_string.value)
+
print "Parsing packets"
num_packets = 0
if packet.HasField('pkt_id'):
ascii_out.write('%s,' % (packet.pkt_id))
if packet.HasField('flags'):
- ascii_out.write('%s,%s,%s,%s,%s\n' % (cmd, packet.addr, packet.size,
+ ascii_out.write('%s,%s,%s,%s,%s' % (cmd, packet.addr, packet.size,
packet.flags, packet.tick))
else:
- ascii_out.write('%s,%s,%s,%s\n' % (cmd, packet.addr, packet.size,
+ ascii_out.write('%s,%s,%s,%s' % (cmd, packet.addr, packet.size,
packet.tick))
+ if packet.HasField('pc'):
+ ascii_out.write(',%s\n' % (packet.pc))
+ else:
+ ascii_out.write('\n')
print "Parsed packets:", num_packets