checkpoint_aggregator.py revision 6821
111420Sdavid.guillen@arm.com# Copyright (c) 2009 The Regents of The University of Michigan 211420Sdavid.guillen@arm.com# All rights reserved. 311420Sdavid.guillen@arm.com# 411420Sdavid.guillen@arm.com# Redistribution and use in source and binary forms, with or without 511420Sdavid.guillen@arm.com# modification, are permitted provided that the following conditions are 611420Sdavid.guillen@arm.com# met: redistributions of source code must retain the above copyright 711420Sdavid.guillen@arm.com# notice, this list of conditions and the following disclaimer; 811420Sdavid.guillen@arm.com# redistributions in binary form must reproduce the above copyright 911420Sdavid.guillen@arm.com# notice, this list of conditions and the following disclaimer in the 1011420Sdavid.guillen@arm.com# documentation and/or other materials provided with the distribution; 1111420Sdavid.guillen@arm.com# neither the name of the copyright holders nor the names of its 1211420Sdavid.guillen@arm.com# contributors may be used to endorse or promote products derived from 1311420Sdavid.guillen@arm.com# this software without specific prior written permission. 1411420Sdavid.guillen@arm.com# 1511420Sdavid.guillen@arm.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1611420Sdavid.guillen@arm.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1711420Sdavid.guillen@arm.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1811420Sdavid.guillen@arm.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1911420Sdavid.guillen@arm.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2011420Sdavid.guillen@arm.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2111420Sdavid.guillen@arm.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2211420Sdavid.guillen@arm.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2311420Sdavid.guillen@arm.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2411420Sdavid.guillen@arm.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2511420Sdavid.guillen@arm.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2611420Sdavid.guillen@arm.com# 2711420Sdavid.guillen@arm.com# Authors: Lisa Hsu 2811420Sdavid.guillen@arm.com 2911420Sdavid.guillen@arm.comfrom ConfigParser import ConfigParser 3011420Sdavid.guillen@arm.comimport gzip 3111420Sdavid.guillen@arm.com 3211420Sdavid.guillen@arm.comimport sys, re, optparse, os 3311420Sdavid.guillen@arm.com 3411420Sdavid.guillen@arm.comclass myCP(ConfigParser): 3511420Sdavid.guillen@arm.com def __init__(self): 3611420Sdavid.guillen@arm.com ConfigParser.__init__(self) 3711420Sdavid.guillen@arm.com 3811420Sdavid.guillen@arm.com def optionxform(self, optionstr): 3911420Sdavid.guillen@arm.com return optionstr 4011420Sdavid.guillen@arm.com 4111420Sdavid.guillen@arm.comdef aggregate(options, args): 4211420Sdavid.guillen@arm.com merged = myCP() 4311420Sdavid.guillen@arm.com page_ptr = 0 4411420Sdavid.guillen@arm.com 4511420Sdavid.guillen@arm.com allfiles = os.listdir(os.getcwd()) 4611420Sdavid.guillen@arm.com cpts = [] 4711420Sdavid.guillen@arm.com for arg in args: 4811420Sdavid.guillen@arm.com found = False 4911420Sdavid.guillen@arm.com for f in allfiles: 5011420Sdavid.guillen@arm.com if re.compile("cpt." + arg + ".\d+").search(f): 5111420Sdavid.guillen@arm.com found = True 5211420Sdavid.guillen@arm.com cpts.append(f) 5311420Sdavid.guillen@arm.com break 5411420Sdavid.guillen@arm.com if not found: 5511420Sdavid.guillen@arm.com print "missing checkpoint: ", arg 5611420Sdavid.guillen@arm.com sys.exit(1) 5711420Sdavid.guillen@arm.com 5811420Sdavid.guillen@arm.com dirname = "-".join([options.prefix, "cpt"]) 5911420Sdavid.guillen@arm.com print dirname 6011420Sdavid.guillen@arm.com agg_name = "-".join(args) 6111420Sdavid.guillen@arm.com print agg_name 6211420Sdavid.guillen@arm.com fullpath = os.path.join("..", dirname, "cpt." + agg_name + ".10000") 6311420Sdavid.guillen@arm.com if not os.path.isdir(fullpath): 6411420Sdavid.guillen@arm.com os.system("mkdir -p " + fullpath) 6511420Sdavid.guillen@arm.com 6611420Sdavid.guillen@arm.com myfile = open(fullpath + "/system.physmem.physmem", "wb+") 6711420Sdavid.guillen@arm.com merged_mem = gzip.GzipFile(fileobj=myfile, mode="wb") 6811420Sdavid.guillen@arm.com 6911420Sdavid.guillen@arm.com max_curtick = 0 7011420Sdavid.guillen@arm.com when = 0 7111420Sdavid.guillen@arm.com for (i, arg) in enumerate(args): 7211420Sdavid.guillen@arm.com config = myCP() 7311420Sdavid.guillen@arm.com config.readfp(open(cpts[i] + "/m5.cpt")) 7411420Sdavid.guillen@arm.com 7511523Sdavid.guillen@arm.com for sec in config.sections(): 7611523Sdavid.guillen@arm.com if re.compile("cpu").search(sec): 7711420Sdavid.guillen@arm.com newsec = re.sub("cpu", "cpu" + str(i), sec) 7811420Sdavid.guillen@arm.com merged.add_section(newsec) 7911420Sdavid.guillen@arm.com if re.compile("workload$").search(sec): 8011420Sdavid.guillen@arm.com merged.set(newsec, "M5_pid", i) 8111420Sdavid.guillen@arm.com 8211420Sdavid.guillen@arm.com items = config.items(sec) 8311420Sdavid.guillen@arm.com for item in items: 8411420Sdavid.guillen@arm.com if item[0] == "ppn": 8511420Sdavid.guillen@arm.com if config.getint(sec, "tag") != 0: 8611420Sdavid.guillen@arm.com merged.set(newsec, item[0], int(item[1]) + page_ptr) 8711420Sdavid.guillen@arm.com continue 8811420Sdavid.guillen@arm.com elif item[0] == "asn": 8911420Sdavid.guillen@arm.com tmp = re.compile("(.*).Entry(\d+)").search(sec).groups() 9011420Sdavid.guillen@arm.com if config.has_option(tmp[0], "nlu"): 9111420Sdavid.guillen@arm.com size = config.getint(tmp[0], "nlu") 9211420Sdavid.guillen@arm.com if int(tmp[1]) < size: 9311420Sdavid.guillen@arm.com merged.set(newsec, item[0], i) 9411420Sdavid.guillen@arm.com continue 9511420Sdavid.guillen@arm.com else: 9611420Sdavid.guillen@arm.com merged.set(newsec, item[0], i) 9711420Sdavid.guillen@arm.com continue 9811420Sdavid.guillen@arm.com merged.set(newsec, item[0], item[1]) 9911420Sdavid.guillen@arm.com elif sec == "system": 10011420Sdavid.guillen@arm.com pass 10111420Sdavid.guillen@arm.com elif sec == "Globals": 10211420Sdavid.guillen@arm.com tick = config.getint(sec, "curTick") 10311420Sdavid.guillen@arm.com if tick > max_curtick: 10411420Sdavid.guillen@arm.com max_curtick = tick 10511420Sdavid.guillen@arm.com when = config.getint("system.cpu.tickEvent", "_when") 10611420Sdavid.guillen@arm.com else: 10711420Sdavid.guillen@arm.com if i == 0: 10811420Sdavid.guillen@arm.com print sec 10911420Sdavid.guillen@arm.com merged.add_section(sec) 11011420Sdavid.guillen@arm.com for item in config.items(sec): 11111420Sdavid.guillen@arm.com merged.set(sec, item[0], item[1]) 11211420Sdavid.guillen@arm.com if item[0] == "curtick": 11311420Sdavid.guillen@arm.com merged.optionxform(str("curTick")) 11411429Sandreas.sandberg@arm.com elif item[0] == "numevents": 11511420Sdavid.guillen@arm.com merged.optionxform(str("numEvents")) 11611420Sdavid.guillen@arm.com 117 page_ptr = page_ptr + int(config.get("system", "page_ptr")) 118 119 ### memory stuff 120 f = open(cpts[i] + "/system.physmem.physmem", "rb") 121 gf = gzip.GzipFile(fileobj=f, mode="rb") 122 bytes = int(config.get("system", "page_ptr")) << 13 123 print "bytes to be read: ", bytes 124 125 bytesRead = gf.read(int(config.get("system", "page_ptr")) << 13) 126 merged_mem.write(bytesRead) 127 128 gf.close() 129 f.close() 130 131 merged.add_section("system") 132 merged.set("system", "page_ptr", page_ptr) 133 print "WARNING: " 134 print "Make sure the simulation using this checkpoint has at least " 135 if page_ptr > (1<<20): 136 print "8G ", 137 elif page_ptr > (1<<19): 138 print "4G ", 139 elif page_ptr > (1<<18): 140 print "2G ", 141 elif page_ptr > (1<<17): 142 print "1G ", 143 elif page_ptr > (1<<16): 144 print "512KB ", 145 else: 146 print "this is a small sim, you're probably fine", 147 print "of memory." 148 149 merged.add_section("Globals") 150 merged.set("Globals", "curTick", max_curtick) 151 152 for i in xrange(len(args)): 153 merged.set("system.cpu" + str(i) + ".tickEvent", "_when", when) 154 155 merged.write(file(fullpath + "/m5.cpt", "wb")) 156 merged_mem.close() 157 myfile.close() 158 159if __name__ == "__main__": 160 161 parser = optparse.OptionParser() 162 parser.add_option("--prefix", type="string", default="agg") 163 164 (options, args) = parser.parse_args() 165 166 aggregate(options, args) 167 168