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()
def main(): if len(sys.argv) != 2: print("Usage: ", sys.argv[0], " <protobuf input>") exit(-1) # Open the file on read mode proto_in = protolib.openFileRd(sys.argv[1]) # Read the magic number in 4-byte Little Endian magic_number = proto_in.read(4) if magic_number != b'gem5': print("Unrecognized file") exit(-1) print("Parsing packet header") # Add the packet header header = inst_dep_record_pb2.InstDepRecordHeader() protolib.decodeMessage(proto_in, header) print("Object id:", header.obj_id) print("Tick frequency:", header.tick_freq) print("Parsing packets") num_packets = 0 num_regdeps = 0 num_dep = [0] * (320 * 10**6) packet = inst_dep_record_pb2.InstDepRecord() # Decode the packet messages until we hit the end of the file while protolib.decodeMessage(proto_in, packet): num_packets += 1 # Write to file the repeated field register dependency if num_packets % 10**7 == 0: print(num_packets) if packet.reg_dep: num_regdeps += 1 # No. of packets with atleast 1 register dependency for dep in packet.reg_dep: inst_seq = int(dep) num_dep[inst_seq] += 1 if num_packets == 200 * 10**6: break print("Parsed packets:", num_packets) print("Packets with at least 1 reg dep:", num_regdeps) proto_in.close() print('Counting dependancies') dep_map = {} for n in num_dep: if n in dep_map: dep_map[n] += 1 else: dep_map[n] = 1 print(dep_map)
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()
def main(): if len(sys.argv) != 3: print "Usage: ", sys.argv[0], " <protobuf input> <ASCII output>" exit(-1) # Open the file on 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" exit(-1) print "Parsing packet header" # Add the packet header header = inst_dep_record_pb2.InstDepRecordHeader() protolib.decodeMessage(proto_in, header) print "Object id:", header.obj_id print "Tick frequency:", header.tick_freq print "Parsing packets" print "Creating enum value,name lookup from proto" enumNames = {} desc = inst_dep_record_pb2.InstDepRecord.DESCRIPTOR for namestr, valdesc in desc.enum_values_by_name.items(): print '\t', valdesc.number, namestr enumNames[valdesc.number] = namestr num_packets = 0 num_regdeps = 0 num_robdeps = 0 packet = inst_dep_record_pb2.InstDepRecord() # Decode the packet messages until we hit the end of the file while protolib.decodeMessage(proto_in, packet): num_packets += 1 # Write to file the seq num ascii_out.write('%s' % (packet.seq_num)) # Write to file the pc of the instruction, default is 0 if packet.HasField('pc'): ascii_out.write(',%s' % (packet.pc)) else: ascii_out.write(',0') # Write to file the weight, default is 1 if packet.HasField('weight'): ascii_out.write(',%s' % (packet.weight)) else: ascii_out.write(',1') # Write to file the type of the record try: ascii_out.write(',%s' % enumNames[packet.type]) except KeyError: print "Seq. num", packet.seq_num, "has unsupported type", \ packet.type exit(-1) # Write to file if it has the optional fields physical addr, size, # flags if packet.HasField('p_addr'): ascii_out.write(',%s' % (packet.p_addr)) if packet.HasField('size'): ascii_out.write(',%s' % (packet.size)) if packet.HasField('flags'): ascii_out.write(',%s' % (packet.flags)) # Write to file the comp delay ascii_out.write(',%s' % (packet.comp_delay)) # Write to file the repeated field order dependency ascii_out.write(':') if packet.rob_dep: num_robdeps += 1 for dep in packet.rob_dep: ascii_out.write(',%s' % dep) # Write to file the repeated field register dependency ascii_out.write(':') if packet.reg_dep: num_regdeps += 1 # No. of packets with atleast 1 register dependency for dep in packet.reg_dep: ascii_out.write(',%s' % dep) # New line ascii_out.write('\n') print "Parsed packets:", num_packets print "Packets with at least 1 reg dep:", num_regdeps print "Packets with at least 1 rob dep:", num_robdeps # We're done ascii_out.close() proto_in.close()
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 instruction header" # Add the packet header header = inst_pb2.InstHeader() protolib.decodeMessage(proto_in, header) print "Object id:", header.obj_id print "Tick frequency:", header.tick_freq print "Memory addresses included:", header.has_mem if header.ver != 0: print "Warning: file version newer than decoder:", header.ver print "This decoder may not understand how to decode this file" print "Parsing instructions" num_insts = 0 inst = inst_pb2.Inst() # Decode the inst messages until we hit the end of the file optional_fields = ('tick', 'type', 'inst_flags', 'addr', 'size', 'mem_flags') while protolib.decodeMessage(proto_in, inst): # If we have a tick use it, otherwise count instructions if inst.HasField('tick'): tick = inst.tick else: tick = num_insts if inst.HasField('nodeid'): node_id = inst.nodeid else: node_id = 0 if inst.HasField('cpuid'): cpu_id = inst.cpuid else: cpu_id = 0 ascii_out.write('%-20d: (%03d/%03d) %#010x @ %#016x ' % (tick, node_id, cpu_id, inst.inst, inst.pc)) if inst.HasField('type'): ascii_out.write( ' : %10s' % inst_pb2._INST_INSTTYPE.values_by_number[inst.type].name) for mem_acc in inst.mem_access: ascii_out.write(" %#x-%#x;" % (mem_acc.addr, mem_acc.addr + mem_acc.size)) ascii_out.write('\n') num_insts += 1 print "Parsed instructions:", num_insts # We're done ascii_out.close() proto_in.close()
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()
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 instruction header" # Add the packet header header = inst_pb2.InstHeader() protolib.decodeMessage(proto_in, header) print "Object id:", header.obj_id print "Tick frequency:", header.tick_freq print "Memory addresses included:", header.has_mem if header.ver != 0: print "Warning: file version newer than decoder:", header.ver print "This decoder may not understand how to decode this file" print "Parsing instructions" num_insts = 0 inst = inst_pb2.Inst() # Decode the inst messages until we hit the end of the file optional_fields = ('tick', 'type', 'inst_flags', 'addr', 'size', 'mem_flags') while protolib.decodeMessage(proto_in, inst): # If we have a tick use it, otherwise count instructions if inst.HasField('tick'): tick = inst.tick else: tick = num_insts if inst.HasField('nodeid'): node_id = inst.nodeid else: node_id = 0; if inst.HasField('cpuid'): cpu_id = inst.cpuid else: cpu_id = 0; ascii_out.write('%-20d: (%03d/%03d) %#010x @ %#016x ' % (tick, node_id, cpu_id, inst.inst, inst.pc)) if inst.HasField('type'): ascii_out.write(' : %10s' % inst_pb2._INST_INSTTYPE.values_by_number[inst.type].name) for mem_acc in inst.mem_access: ascii_out.write(" %#x-%#x;" % (mem_acc.addr, mem_acc.addr + mem_acc.size)) ascii_out.write('\n') num_insts += 1 print "Parsed instructions:", num_insts # We're done ascii_out.close() proto_in.close()
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()