本文整理汇总了Python中memory.Memory.defragment方法的典型用法代码示例。如果您正苦于以下问题:Python Memory.defragment方法的具体用法?Python Memory.defragment怎么用?Python Memory.defragment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类memory.Memory
的用法示例。
在下文中一共展示了Memory.defragment方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CPU
# 需要导入模块: from memory import Memory [as 别名]
# 或者: from memory.Memory import defragment [as 别名]
#.........这里部分代码省略.........
process.resetRemainBurstTime()
if self.processInCPU and self.queueType=="SRT" and self.processInCPU.remain_burst_time - (simulator.time - self.processInCPU.lastTimeInCPU) > process.burst_time :
# Preempted by SRT
self.SRTPreempt(process, simulator)
elif self.processInCPU and self.queueType=="PWA" and self.processInCPU.priority > process.priority:
# Preempted by PWA
process.currentAgingSeq = random.getrandbits(128)
self.processInCPU.currentAgingSeq = random.getrandbits(128)
print "time %dms:"% simulator.time,"Process '%c'"% process.letter, "completed I/O [Q",
sys.stdout.write('')
self.printQueue()
print "]"
self.PWAPreempt(process, simulator)
else:
# NORMAL CASE
process.setInQueueTime(simulator.time)
self.process_queue.appendProcess(process.burst_time, process)
#PWA with aging
if self.queueType=="PWA":
#The trick is: process after re-enter queue, the agingSeq is refreshed
#so that only if a process stay in queue for 3*burst time, the priority changes
process.currentAgingSeq = random.getrandbits(128)
simulator.schedule(simulator.time + 3 * process.burst_time, self.eAging,process, process.currentAgingSeq , simulator)
defragFlag = False
if process.total_num_burst == process.num_burst:
if not self.mem.allocate( process.memory_size, process.letter ):
defragFlag = True
print "time %dms:"% simulator.time,"Process '%c'" %process.letter, " unable to be added; lack of memory"
print "time %dms:" % simulator.time, "Starting defragmentation (suspending all processes)"
print "time %dms:"% simulator.time, "Simulated Memory:"
self.mem.printmem()
moveunits = self.mem.defragment()
self.defragtime += moveunits * self.t_memmove
if self.processInCPU:
simulator.delay(self.processInCPU.remain_burst_time + simulator.time, self.processInCPU.ID, moveunits * self.t_memmove)
self.processInCPU.remain_burst_time += moveunits * self.t_memmove
else:
pass
#@TODO block CPU during defragmentation
simulator.schedule(simulator.time + moveunits * self.t_memmove
, self.eDefragDone, process, moveunits, simulator)
else:
if self.processInCPU_tobe:
print "time %dms:"% simulator.time,"Process '%c'"% process.letter, "added to system [Q %c" %( self.processInCPU_tobe.letter) ,
else:
print "time %dms:"% simulator.time,"Process '%c'"% process.letter, "added to system [Q",
sys.stdout.write('')
self.printQueue()
print "]"
print "time %dms:"% simulator.time, "Simulated Memory:"
self.mem.printmem()
else:
print "time %dms:"% simulator.time,"Process '%c'"% process.letter, "completed I/O [Q",
sys.stdout.write('')
self.printQueue()
print "]"
if self.CPUIdle :
# it means 1.queue empty 2.current process has more rounds
next_burst_time, next_process = self.process_queue.nextProcess()
#Schedule directly
示例2: printStatusMessage
# 需要导入模块: from memory import Memory [as 别名]
# 或者: from memory.Memory import defragment [as 别名]
currentTime = 0
print "time 0ms: Simulator started for "+cpu.algorithm.upper() +\
(" (t_slice {0})".format(t_slice) if algorithm == "rr" else "") +" and "+mem_algorithms[mem_algorithm]
#Consider the processes in order, only after we added them to the queues. So we don't mess up fcfs.
processes = copy.deepcopy(origprocesses)
for process in processes:
if (process.starttime == 0):
process.status = "waiting"
if (not mem.allocate(process.id, process.memsize)):
printStatusMessage("Process '{0}' unable to be added; lack of memory".format(process.id))
printStatusMessage("Starting defragmentation (suspending all processes)", cpu.processQueue)
print "time "+str(currentTime)+"ms: Simulated Memory:\n"+str(mem)
#printStatusMessage("Simulated Memory:\n"+str(mem))
cpu.memCooldown, cpu.units_defragged = mem.defragment()
cpu.status = "defragging"
assert(0) #This probably shouldn't happen before we actualy run items.
else:
cpu.processQueue.append(process) #Append instead of cpu.addProcessToQueue to avoid unnecessary preemption at time 0.
printStatusMessage("Process '{0}' added to system".format(process.id), cpu.processQueue)
printStatusMessage("Simulated Memory:\n"+str(mem))
#Initial sort.
if (algorithm == "srt"):
cpu.processQueue.sort(key=lambda x: x.timeremaining)
processes.sort(key=lambda x: (x.timeremaining, x.id))
#Consider the processes in order for srt.
#processes.sort(key=lambda x: x.id) #waittimes.write("Wait times for: {0}\n".format(cpu.algorithm.upper()))