def load_file(traceID, typeID, sizerate=0.1, p=1, mode='w'): readReq = 0 size = int(sizerate * uclnDict[traceID]) ssd = PLRU(size, p) fin = open(getPath(traceID, typeID), 'r') lines = fin.readlines() req = 0 myupdate = 0 minTime = None maxTime = None print("load file finished") for line in lines: items = line.strip().split(' ') reqtype = int(items[0]) blockid = int(items[2]) if mode == 'r': if reqtype == 1: ssd.delete_cache(blockid) else: readReq += 1 if readReq % 1000000 == 0: print(readReq) req += 1 ssd.is_hit(blockid) ssd.update_cache(blockid) else: req += 1 hit = ssd.is_hit(blockid) if reqtype == 0: readReq += 1 if reqtype == 1 and hit: ssd.add_update() myupdate += 1 ssd.update_cache(blockid) if not hit and ssd.get_top_n(1) == [blockid]: myupdate += 1 fin.close() print(traceID, "size", size, p, "myupdate", myupdate) print("total hit rate", 1.0 * ssd.hit / req, ssd.update) logFile = open(logFilename, "a") print(traceID, p, sizerate, size, 1.0 * ssd.hit / req, ssd.update, req, round(1.0 * readReq / req, 3), minTime, maxTime, sep=',', file=logFile) logFile.close()
def mtc_test_size_p(path, traceID, totalTimeLength, timeStart, sizerate, p): lines = [] uclnDict = {} req = 0 readReq = 0 load_lines(path, traceID, totalTimeLength, timeStart, lines, uclnDict) size = int(sizerate * len(uclnDict)) # 稀疏周期,size过小 if size <= 100: return print("size=", size) ssd = PLRU(size, p) for line in lines: (time, rw, blockid) = parse_line(line, "gen") req += 1 hit = ssd.is_hit(blockid) if rw == 0: readReq += 1 if rw == 1 and hit: ssd.add_update() ssd.update_cache(blockid) print(traceID, "size", size, p) print("total hit rate", 1.0 * ssd.hit / req, "update", ssd.update) global g if ssd.update > 1.0 * size * g * totalTimeLength: cost = 1.0 * ssd.update / g / totalTimeLength else: cost = size print(ssd.update, size, g * totalTimeLength, 1.0 * size * g * totalTimeLength, 1.0 * ssd.update / size, cost) logFile = open(logFilename, "a") print(traceID, timeStart / totalTimeLength, totalTimeLength / danwei, sizerate, size, p, 1.0 * ssd.hit / req, ssd.update, req, round(1.0 * readReq / req, 3), cost, sep=',', file=logFile) logFile.close()
def handle_csv_time(fileid, filename, order, time, pattern, ssd, fileIdx): print("enter handle_csv_time", fileid, order, time, fileIdx) flag = False readcount = 1 writecount = 1 readsize = 1 writesize = 1 # outname = filename +'.req' count = fileIdx totalDict = {} readDict = {} writeDict = {} lba = [[sys.maxsize, 0], [sys.maxsize, 0], [sys.maxsize, 0]] infile = open(filename, 'r') # outfile = open(outname, 'w') nrreq = 0 lines = infile.readlines() if pattern == "warm": if fileIdx == 0: timeStart = -1 timeEnd = 10**25 else: line = lines[fileIdx] timeBase = get_time(line) timeStart = timeBase + order * time timeEnd = timeStart + time if ssd == None: ssd = PLRU(int(0.1 * uclnDict[fileid]), 1) oldhit = -1 oldupdate = -1 else: oldhit = ssd.hit oldupdate = ssd.update else: if order < 0 and fileIdx == 0: line = lines[-1] else: line = lines[fileIdx] line = line.strip().split(',') timeBase = int(line[0]) if fileIdx > 0: timeStart = timeBase else: timeStart = timeBase + order * time timeEnd = timeStart + time print("time", timeBase / danwei, timeStart / danwei, timeEnd / danwei) for line in lines[fileIdx:]: count += 1 line = line.strip().split(',') timestamp = int(line[0]) # print(timestamp, timestamp < timeStart, timestamp > timeEnd) if timestamp < timeStart: continue elif timestamp > timeEnd: break # first coming if not flag: lineStart = count flag = True block_id = int((float(line[4])) / block_size) block_end = int((float(line[4]) + float(line[5]) - 1) / block_size) # if count % 100000 == 0: # print(count) if line[3] == 'Write': rw = 1 writecount += 1 writesize += block_end - block_id + 1 elif line[3] == 'Read': rw = 0 readcount += 1 readsize += block_end - block_id + 1 else: rw = 2 if lba[2][0] > block_id: lba[2][0] = block_id if lba[2][1] < block_end: lba[2][1] = block_end if lba[rw][0] > block_id: lba[rw][0] = block_id if lba[rw][1] < block_end: lba[rw][1] = block_end for i in range(block_id, block_end + 1): # print('{0} {1} {2}'.format(rw,line[2],i),file=outfile) # print>>outfile, '{0} {1} {2}'.format(rw,line[2],i) totalDict[i] = True if rw == 0: readDict[i] = True elif rw == 1: writeDict[i] = True if pattern == "warm": nrreq += 1 hit = ssd.is_hit(i) if line[3] == 'Write' and hit: ssd.add_update() ssd.update_cache(i) if pattern == "warm" and oldhit < 0 and ssd.is_full(): timeBase = timestamp timeStart = timeBase + order * time timeEnd = timeStart + time nrreq = 0 ssd.oldhit = ssd.hit ssd.oldupdate = ssd.update readsize = 0 writesize = 0 flag = False # print("read write", readcount, writecount, readcount/writecount, readsize, writesize, readsize/writesize, sep=',') # print("ucln", len(totalDict), len(readDict), len(writeDict), # lba[2][1]-lba[2][0]+1, lba[0][1]-lba[0][0]+1, lba[1][1]-lba[1][0]+1, sep=',') lineStop = count print(fileid, pattern, order, time / danwei, readsize, writesize, round(1.0 * readsize / (readsize + writesize), 2), sep=',', end=',', file=logFile) infile.close() # outfile.close() if pattern != "warm": nrreq = 0 assert len(totalDict) > 0 ssd = PLRU(int(0.1 * len(totalDict)), 1) infile = open(filename, 'r') # outfile = open(outname, 'w') lines = infile.readlines() for line in lines[lineStart - 1:lineStop]: line = line.strip().split(',') timestamp = int(line[0]) # if timestamp < timeStart: # continue # elif timestamp > timeEnd: # break block_id = int((float(line[4])) / block_size) block_end = int((float(line[4]) + float(line[5]) - 1) / block_size) if count % 100000 == 0: print(count) for req in range(block_id, block_end + 1): nrreq += 1 hit = ssd.is_hit(req) if line[3] == 'Write' and hit: ssd.add_update() ssd.update_cache(req) hit = ssd.hit update = ssd.update else: hit = ssd.hit - oldhit update = ssd.update - oldupdate print(fileid, hit, nrreq, 1.0 * hit / nrreq, update) print(nrreq, ssd.size, hit, 1.0 * hit / nrreq, update, sep=',', file=logFile) logFile.flush() return (ssd, count)