Exemplo n.º 1
0
def main():
    if len(sys.argv) != 3:
        print "Usage: ", sys.argv[0], " <protobuf input> <ASCII output>"
        exit(-1)

    # Open the file in read mode
    proto_in = protolib.openFileRd(sys.argv[1])

    try:
        ascii_out = open(sys.argv[2], 'w')
    except IOError:
        print "Failed to open ", sys.argv[2], " for writing"
        exit(-1)

    # Read the magic number in 4-byte Little Endian
    magic_number = proto_in.read(4)

    if magic_number != "gem5":
        print "Unrecognized file", sys.argv[1]
        exit(-1)

    print "Parsing packet header"

    # Add the packet header
    header = packet_pb2.PacketHeader()
    protolib.decodeMessage(proto_in, header)

    print "Object id:", header.obj_id
    print "Tick frequency:", header.tick_freq

    print "Parsing packets"

    num_packets = 0
    packet = packet_pb2.Packet()

    # Decode the packet messages until we hit the end of the file
    while protolib.decodeMessage(proto_in, packet):
        num_packets += 1
        # ReadReq is 1 and WriteReq is 4 in src/mem/packet.hh Command enum
        cmd = 'r' if packet.cmd == 1 else ('w' if packet.cmd == 4 else 'u')
        if packet.HasField('pkt_id'):
            ascii_out.write('%s,' % (packet.pkt_id))
        if packet.HasField('flags'):
            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' %
                            (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

    # We're done
    ascii_out.close()
    proto_in.close()
Exemplo n.º 2
0
def main():
    if len(sys.argv) != 3:
        print "Usage: ", sys.argv[0], " <protobuf input> <ASCII output>"
        exit(-1)

    try:
        proto_in = open(sys.argv[1], 'rb')
    except IOError:
        print "Failed to open ", sys.argv[1], " for reading"
        exit(-1)

    try:
        ascii_out = open(sys.argv[2], 'w')
    except IOError:
        print "Failed to open ", sys.argv[2], " for writing"
        exit(-1)

    # Read the magic number in 4-byte Little Endian
    magic_number = proto_in.read(4)

    if magic_number != "gem5":
        print "Unrecognized file"
        exit(-1)

    print "Parsing packet header"

    # Add the packet header
    header = packet_pb2.PacketHeader()
    decodeMessage(proto_in, header)

    print "Object id:", header.obj_id
    print "Tick frequency:", header.tick_freq

    print "Parsing packets"

    num_packets = 0
    ignored_flags = False
    packet = packet_pb2.Packet()

    # Decode the packet messages until we hit the end of the file
    while decodeMessage(proto_in, packet):
        num_packets += 1
        # ReadReq is 1 and WriteReq is 4 in src/mem/packet.hh Command enum
        cmd = 'r' if packet.cmd == 1 else ('w' if packet.cmd == 4 else 'u')
        if packet.HasField('flags'):
            # Currently not printing flags
            ignored_flags = True
        ascii_out.write('%s,%s,%s,%s\n' %
                        (cmd, packet.addr, packet.size, packet.tick))

    print "Parsed packets:", num_packets
    if ignored_flags:
        print "Encountered packet flags that were ignored"

    # We're done
    ascii_out.close()
    proto_in.close()
Exemplo n.º 3
0
def main():
    if len(sys.argv) != 3:
        print "Usage: ", sys.argv[0], " <ASCII input> <protobuf output>"
        exit(-1)

    try:
        ascii_in = open(sys.argv[1], 'r')
    except IOError:
        print "Failed to open ", sys.argv[1], " for reading"
        exit(-1)

    try:
        proto_out = open(sys.argv[2], 'wb')
    except IOError:
        print "Failed to open ", sys.argv[2], " for writing"
        exit(-1)

    # Write the magic number in 4-byte Little Endian, similar to what
    # is done in src/proto/protoio.cc
    proto_out.write("gem5")

    # Add the packet header
    header = packet_pb2.PacketHeader()
    header.obj_id = "Converted ASCII trace " + sys.argv[1]
    # Assume the default tick rate
    header.tick_freq = 1000000000
    encodeMessage(proto_out, header)

    # For each line in the ASCII trace, create a packet message and
    # write it to the encoded output
    for line in ascii_in:
        cmd, addr, size, tick = line.split(',')
        packet = packet_pb2.Packet()
        packet.tick = long(tick)
        # ReadReq is 1 and WriteReq is 4 in src/mem/packet.hh Command enum
        packet.cmd = 1 if cmd == 'r' else 4
        packet.addr = long(addr)
        packet.size = int(size)
        encodeMessage(proto_out, packet)

    # We're done
    ascii_in.close()
    proto_out.close()
Exemplo n.º 4
0
def create_trace(filename, max_addr, burst_size, itt):
    try:
        proto_out = gzip.open(filename, 'wb')
    except IOError:
        print "Failed to open ", filename, " for writing"
        exit(-1)

    # write the magic number in 4-byte Little Endian, similar to what
    # is done in src/proto/protoio.cc
    proto_out.write("gem5")

    # add the packet header
    header = packet_pb2.PacketHeader()
    header.obj_id = "lat_mem_rd for range 0:" + str(max_addr)
    # assume the default tick rate (1 ps)
    header.tick_freq = 1000000000000
    protolib.encodeMessage(proto_out, header)

    # create a list of every single address to touch
    addrs = range(0, max_addr, burst_size)

    import random
    random.shuffle(addrs)

    tick = 0

    # create a packet we can re-use for all the addresses
    packet = packet_pb2.Packet()
    # ReadReq is 1 in src/mem/packet.hh Command enum
    packet.cmd = 1
    packet.size = int(burst_size)

    for addr in addrs:
        packet.tick = long(tick)
        packet.addr = long(addr)
        protolib.encodeMessage(proto_out, packet)
        tick = tick + itt

    proto_out.close()
Exemplo n.º 5
0
#!/usr/bin/env python

import sys, io
import packet_pb2 as packet
import job_pb2 as job
import stream

# Example from https://developers.google.com/protocol-buffers/docs/pythontutorial
if len(sys.argv) != 2:
    print "Usage:", sys.argv[0], "jobs.pb.gz"
    sys.exit(-1)

# Open the file and discard the header
istream = stream.open(sys.argv[1], "rb")

for msg in istream:
    hdr = packet.PacketHeader()
    hdr.ParseFromString(msg)
    print hdr
    #break

for msg in istream:
    jobinfo = job.JobInfo()
    jobinfo.ParseFromString(msg)
    print jobinfo

# Close the file
istream.close()

Exemplo n.º 6
0
def main():
    if len(sys.argv) != 6:
        print "Usage: ", sys.argv[
            0], " <protobuf input> <ASCII output> <starting_tick> <ending_tick> <max_packets>"
        exit(-1)

    print "Command line arguments:", sys.argv

    # Open the file in read mode
    proto_in = protolib.openFileRd(sys.argv[1])

    try:
        ascii_out = open(sys.argv[2], 'w')
    except IOError:
        print "Failed to open ", sys.argv[2], " for writing"
        exit(-1)

    # Read the magic number in 4-byte Little Endian
    magic_number = proto_in.read(4)

    if magic_number != "gem5":
        print "Unrecognized file", sys.argv[1]
        exit(-1)

    print "Parsing packet header"

    # Add the packet header
    header = packet_pb2.PacketHeader()
    protolib.decodeMessage(proto_in, header)

    print "Object id:", header.obj_id
    print "Tick frequency:", header.tick_freq
    starting_tick = long(sys.argv[3])
    ending_tick = long(sys.argv[4])
    max_packets = long(sys.argv[5])

    print "Parsing packets from simulation tick: ", str(
        starting_tick), " to ", str(
            ending_tick), " max packets = ", max_packets

    num_packets = 0
    packet = packet_pb2.Packet()
    currtick = 0

    # Decode the packet messages until we hit the end of the file
    while protolib.decodeMessage(proto_in,
                                 packet) and currtick < starting_tick:
        currtick = long(packet.tick)

    if currtick >= starting_tick and currtick < ending_tick:
        print "Found first packet of interest at tick ", str(currtick)

        while protolib.decodeMessage(
                proto_in, packet
        ) and currtick < ending_tick and num_packets < max_packets:
            num_packets += 1
            currtick = long(packet.tick)

            # ReadReq is 1 and WriteReq is 4 in src/mem/packet.hh Command enum
            #cmd = 'r' if packet.cmd == 1 else ('w' if packet.cmd == 4 else 'u') # MWG commented out
            cmd = packet.cmd  # MWG
            if packet.HasField('pkt_id'):
                ascii_out.write('%s,' % (packet.pkt_id))
            if packet.HasField('flags'):
                if packet.HasField('has_data'):
                    addr = long(packet.addr)
                    size = long(packet.size)
                    flags = long(packet.flags)

                    ascii_out.write('%s,%016X,%016X,%016X,%s,' %
                                    (cmd, addr, size, flags, packet.tick))
                    if packet.has_data == 1:
                        ascii_out.write('1,')
                        ascii_out.write(
                            '%016X,%016X,%016X,%016X,%016X,%016X,%016X,%016X\n'
                            % (packet.data0, packet.data1, packet.data2,
                               packet.data3, packet.data4, packet.data5,
                               packet.data6, packet.data7))
                    else:
                        ascii_out.write('0,')
                        ascii_out.write('0,0,0,0,0,0,0,0\n')
                else:
                    display("uh oh, this should not have happened")
                    exit(1)
            else:
                display("uh oh, this should not have happened")
                exit(1)
            if num_packets % 10000 == 0:
                print "Packet ", num_packets

        print "Found last packet of interest at tick ", str(currtick)
        print "Parsed packets:", num_packets

    else:
        print "No packets found in tick range of interest: [", starting_tick, ",", ending_tick, ")"

    # We're done
    ascii_out.close()
    proto_in.close()
Exemplo n.º 7
0
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)

    try:
        ascii_out = open(sys.argv[2], 'w')
    except IOError:
        print "Failed to open ", sys.argv[2], " for writing"
        exit(-1)

    # Read the magic number in 4-byte Little Endian
    magic_number = proto_in.read(4)

    if magic_number != "gem5":
        print "Unrecognized file", sys.argv[1]
        exit(-1)

    print "Parsing packet header"

    # Add the packet header
    header = packet_pb2.PacketHeader()
    protolib.decodeMessage(proto_in, header)

    print "Object id:", header.obj_id
    print "Tick frequency:", header.tick_freq

    print "Parsing packets"

    num_packets = 0
    packet = packet_pb2.Packet()

    # Decode the packet messages until we hit the end of the file
    while protolib.decodeMessage(proto_in, packet):
        num_packets += 1
        # ReadReq is 1 and WriteReq is 4 in src/mem/packet.hh Command enum
        cmd = 'r' if packet.cmd == 1 else ('w' if packet.cmd == 4 else 'u')
        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,
                            packet.flags, packet.tick))
        else:
            ascii_out.write('%s,%s,%s,%s\n' % (cmd, packet.addr, packet.size,
                                           packet.tick))

    print "Parsed packets:", num_packets

    # We're done
    ascii_out.close()
    proto_in.close()