Example #1
0
def generate_reqs(traces, totalTimeLength, unitLength, starts):
    print("traces", traces)
    lines = []
    idxlist = []
    uclnDict = []
    global traceFileName
    traceFileName = path + "mix" + "_" + str(time.process_time()) + ".req"
    logfile = open(traceFileName, 'w')
    #混合文件
    for trace in traces:  #初始化
        lines.append([])
        idxlist.append(0)
        uclnDict.append({})
    for i in range(len(traces)):  
        start = starts[i]
        timeUnitEnd = start + unitLength
        timeEnd = start + totalTimeLength       #这两步是否没有意义呢
        load_lines(path, traces[i], totalTimeLength, start, lines[i], uclnDict[i])
#++     计算每个trace的所需磁盘大小并构建对应文件模拟磁盘
        bid = []
        for line in lines[i]:
            items = line.strip().split(' ')
            bid.append(int(items[3]))                    #记录下所有的bid
        mkdir(diskpath + traces[i],max(bid)-min(bid)+1)  #创建文件,模拟磁盘
        trace_block_bigin[traces[i]]=min(bid)            #记录下磁盘的开始块
#
    timeUnitEnd = unitLength
    timeEnd = totalTimeLength
    while True:
        for i in range(len(traces)):
            while True:
                if idxlist[i] >= len(lines[i]):
                    break
                (mytime, rw, blkid) = parse_line(lines[i][idxlist[i]], "gen")
                mytime -= starts[i]
                if mytime > timeUnitEnd:
                    break
                print(traces[i], mytime, rw, blkid, file=logfile)
                idxlist[i] += 1
        # print("time", time, "timeUnitEnd", timeUnitEnd)
        timeUnitEnd += unitLength
        if timeUnitEnd > timeEnd:
            break
        sign = False
        for i in range(len(traces)):
            if idxlist[i] < len(lines[i]):
                sign = True
                break
        if not sign:
            break
    for i in range(len(traces)):
        print(traces[i], len(lines[i]), idxlist[i])
    logfile.close()
    return uclnDict
Example #2
0
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 generate_reqs(traces, totalTimeLength, unitLength, starts):
    print("traces", traces)
    lines = []
    idxlist = []
    uclnDict = []
    global traceFileName
    traceFileName = path + "mix" + "_" + str(time.clock()) + ".req"
    logfile = open(traceFileName, 'w')
    for trace in traces:
        lines.append([])
        idxlist.append(0)
        uclnDict.append({})
    for i in range(len(traces)):
        start = starts[i]
        timeUnitEnd = start + unitLength
        timeEnd = start + totalTimeLength
        load_lines(path, traces[i], totalTimeLength, start, lines[i],
                   uclnDict[i])
    timeUnitEnd = unitLength
    timeEnd = totalTimeLength
    while True:
        for i in range(len(traces)):
            while True:
                if idxlist[i] >= len(lines[i]):
                    break
                (mytime, rw, blkid) = parse_line(lines[i][idxlist[i]], "gen")
                mytime -= starts[i]
                if mytime > timeUnitEnd:
                    break
                print(traces[i], mytime, rw, blkid, file=logfile)
                idxlist[i] += 1
        # print("time", time, "timeUnitEnd", timeUnitEnd)
        timeUnitEnd += unitLength
        if timeUnitEnd > timeEnd:
            break
        sign = False
        for i in range(len(traces)):
            if idxlist[i] < len(lines[i]):
                sign = True
                break
        if not sign:
            break
    for i in range(len(traces)):
        print(traces[i], len(lines[i]), idxlist[i])
    logfile.close()
    return uclnDict