def run(): cpu = Cpu() cpu.updateDatabase() mem = Memory() mem.updateDatabase() proc = Processes() proc.updateDatabase()
class Central: def __init__(self, quantum, memoriaReal, memoriaSwap, pageSize): self.memoriaAlloc = MemoriaAlloc(memoriaReal / pageSize, memoriaSwap / pageSize) self.cpu = Cpu(quantum) self.pidContador = 1 self.pageSize = pageSize def cargarPagina(self): if self.cpu.colaListos: self.cpu.colaListos[0].accesos += 1 self.cpu.colaListos[0].pagefaults += self.memoriaAlloc.accessPage(self.cpu.colaListos[0].pid, 0, time.time())[1] def quantum(self): self.cpu.Quantum() self.cargarPagina() def crearProceso(self, tamano): procesoNuevo = Proceso(self.pidContador, tamano, time.time()) self.cpu.anadirProceso(procesoNuevo) if self.cpu.colaListos[0].pid == procesoNuevo.pid: self.cargarPagina() self.pidContador = self.pidContador + 1 def accederMemoria(self, pid, virtual): index = self.memoriaAlloc.accessPage(pid, virtual / self.pageSize, time.time()) self.cpu.colaListos[0].pagefaults += index[1] self.cpu.colaListos[0].accesos += 1 return index[0] * self.pageSize + virtual % self.pageSize def matarProceso(self, pid): has = self.cpu.colaListos[0].pid == pid self.cpu.terminarProceso(pid) self.memoriaAlloc.terminarProceso(pid) if has: self.cargarPagina()
class TestsCpu(unittest.TestCase): def setUp(self): self.clock = Clock(4) self.clock.start() self.disc = Disc() self.program = Programa("a_program_name") self.program2 = Programa("another_program_name") self.program3 = Programa("yes_another_program_name") self.program4 = Programa("Hm.. blah") self.instruction1 = Instruccion("Instruccion 1") self.instruction2 = Instruccion("Instruccion 2") self.instruction3 = Instruccion("Instruccion 3") self.instruction4 = Instruccion("Instruccion 4") self.instruction5 = Instruccion("Instruccion 5") self.instruction6 = Instruccion("Instruccion 6") self.instruction7 = Instruccion("Instruccion 7") self.instruction8 = Instruccion("Instruccion 8") self.instruction9 = Instruccion("Instruccion 9") self.instruction10 = Instruccion("Instruccion 10") self.instruction11 = Instruccion("Instruccion 11") self.instruction12 = Instruccion("Instruccion 12") self.program.agregarInstruccion(self.instruction1) self.program.agregarInstruccion(self.instruction2) self.program.agregarInstruccion(self.instruction3) self.program2.agregarInstruccion(self.instruction4) self.program2.agregarInstruccion(self.instruction5) self.program2.agregarInstruccion(self.instruction6) self.program3.agregarInstruccion(self.instruction7) self.program3.agregarInstruccion(self.instruction8) self.program3.agregarInstruccion(self.instruction9) self.program4.agregarInstruccion(self.instruction10) self.program4.agregarInstruccion(self.instruction11) self.program4.agregarInstruccion(self.instruction12) self.memory = Memory() self.kernel = Kernel(self.memory, FileSystem(self.disc), self.clock) self.kernel.set_scheduler_policy() self.kernel.create_pcb(self.program, 0) self.kernel.create_pcb(self.program2, 1) self.kernel.create_pcb(self.program3, 2) self.kernel.create_pcb(self.program4, 3) self.cpu = Cpu(self.kernel) def test_cpu_run_instruction(self): self.cpu.run() self.assertTrue(self.cpu.output.contains("Instruccion 1"))
def __init__(self): self.dialog = QDialog() self.sysinfo = loadUi('gui/systeminformation.ui', baseinstance=self.dialog) self.buffer_size = 60 # number of seconds self.cpu = Cpu() self.memory = Memory() self.cpu_count = self.cpu.getCpuCount() self.memory_data = np.zeros(self.buffer_size) self.cpu_data = np.zeros((self.cpu_count, self.buffer_size)) self.seconds_elapsed = 0 self.number_of_iterations = 1 self.memory_line = None self.cpu_line = None self.cpu_plot = [] self.memory_plot = self.sysinfo.memoryView.plot(pen=(255, 0, 0))
def run(self): notify_email = properties["notify_email"] cpu = Cpu(properties["cpu_monitor_rate"], properties["cpu_over_max_count"], notify_email) disk = Disk(properties["all_disk_max_capacity"], properties["single_file_max_capacity"], properties["all_disk_warn_capacity"], properties["direct_remove_file_suffix"], properties["mem_warn_capacity"], log, notify_email) ytj = YTJService(log) second = int(properties["check_interval"]) while 1: try: # cpu.monitor() log.info("cpu health") except Exception as e: log.error("cpu检测脚本出错%s", e.with_traceback(sys.exc_info()[2])) try: # disk.cpu_system_info() log.info("disk health") except Exception as e: log.error("磁盘检测脚本出错%s", e.with_traceback(sys.exc_info()[2])) try: ytj.check() log.info("ytj health") except Exception as e: log.error("磁盘ytj脚本出错%s", e.with_traceback(sys.exc_info()[2])) time.sleep(second)
def main(): cpuConcreta = Cpu() tecladoConcreto = Teclado(cpuConcreta) mouseConcreto = Mouse(tecladoConcreto) mouseConcreto.manejaProcesos("Presionar") mouseConcreto.manejaProcesos("Hola1") mouseConcreto.manejaProcesos("Escribir") mouseConcreto.manejaProcesos("Hola2") mouseConcreto.manejaProcesos("Encender") mouseConcreto.manejaProcesos("Hola3")
class Main: server = Server(Cpu(), Ram(), Nics(), Disks()) serverObject = { 'Vendor': server.vendor, 'Model': server.model, 'Cpu': server.serverCpu.cpuObject, 'Ram': server.serverRam.ramObject, 'NICs': server.serverNics.nicsObject, 'Disks': server.serverDisks.disksObject } print(Utils.convert_to_json(serverObject))
class SystemInformationArchive(): def __init__(self): self.dialog = QDialog() self.sysinfo = loadUi('gui/systeminformationarchive.ui', baseinstance=self.dialog) self.buffer_size = 60 # number of seconds self.cpu = Cpu() self.memory = Memory() self.cpu_count = self.cpu.getCpuCount() self.memory_data = np.zeros(self.buffer_size) self.cpu_data = np.zeros(self.buffer_size) self.seconds_elapsed = 0 self.number_of_iterations = 1 self.memory_line = None self.cpu_line = None self.cpu_plot = None self.memory_plot = self.sysinfo.memoryView.plot(pen=(255, 0, 0)) self.cpu_plot = self.sysinfo.cpuView.plot(pen=(255, 0, 0)) self.db = Database() def load_ui(self): # Memory and CPU line shows the current x-axis on the widget self.memory_line = self.sysinfo.memoryView.addLine(x=0) self.cpu_line = self.sysinfo.cpuView.addLine(x=0) self.sysinfo.memoryView.setLabel('left', 'Memory', units='%') self.sysinfo.memoryView.setLabel('bottom', 'Time', units='minutes') self.sysinfo.memoryView.setRange(xRange=[0, self.buffer_size], yRange=[0, 100]) self.sysinfo.memoryView.showGrid(x=True, y=True) self.sysinfo.cpuView.setLabel('left', 'CPU', units='%') self.sysinfo.cpuView.setLabel('bottom', 'Time', units='minutes') self.sysinfo.cpuView.setRange(xRange=[0, self.buffer_size], yRange=[0, 100]) self.sysinfo.cpuView.showGrid(x=True, y=True) def load_data(self): # Plot the memory line based on the memory reported. self.memory_plot.setData(self.memory_data) self.cpu_data = self.db.queryhourCPUAvgTable( self.sysinfo.timeEdit.time().hour(), self.sysinfo.timeEdit.time().minute()) self.memory_data = self.db.queryhourMEMAvgTable( self.sysinfo.timeEdit.time().hour(), self.sysinfo.timeEdit.time().minute()) self.memory_plot.setData(self.memory_data) self.cpu_plot.setData(self.cpu_data)
#! /usr/bin/env python3 # coding=utf-8 """" :author joelcostamagna created on 2018-03-09 14:55 :version 0.1 """ from bus import Bus from Cpu import Cpu from rom import Rom if __name__ == '__main__': # Creation du bus a la base de l ’ ordinateur pour les communications bus = Bus() # Creation du cpu en le reliant au bus cpu = Cpu(bus) # Creation de la rom en la reliant au bus rom = Rom( bus ) # Creation du GUI # Connexion du GUI aux composants # Boucle sans fin du programme
def run(self): logger.debug("Begin Simulator") self.metrics = System.Metrics() self.requestsInSystem = System.RequestsInSystem() events = [] # Min-Heap CPUs = [] idleCPUs = [] n_threads = 0 # Initialize CPUs logger.debug("Initializing CPUs") for _ in range(0, self.system.n_CPUs): cpu = Cpu() idleCPUs.append(cpu) CPUs.append(cpu) requestBuffer = [] threadPool = [] easeInSampler = lambda : Range(0.0, self.system.easeInTime) serviceTimeSampler = lambda : Exp(1.0 / self.system.serviceTimeMean) timeoutSampler = lambda : Range(self.system.requestTimeoutMin, self.system.requestTimeoutMax) thinkTimeSampler = lambda : Norm(self.system.thinkTimeMean, self.system.thinkTimeStdv) retryThinkTimeSampler = lambda : Norm(self.system.retryThinkTimeMean, self.system.retryThinkTimeStdv) for _ in range(0, self.system.n_users): arrivalTS = self.metrics.time + easeInSampler() totalServiceTime = serviceTimeSampler() timeout = timeoutSampler() arrivalEvent, timeoutEvent = newArrival(arrivalTS, totalServiceTime, timeout) heapq.heappush(events, arrivalEvent) heapq.heappush(events, timeoutEvent) iterations = 0 pbar = progressbar.ProgressBar(max_value=self.system.maxIters, redirect_stdout=True) while True: e = None try: e = heapq.heappop(events) except IndexError as ex: logger.info("All events processed") break self.metrics.time = e.timestamp if type(e) == Arrival: logger.debug("Event :: Arrival with Service Time " + str(e.request.remainingServiceTime)) self.metrics.n_arrivals += 1 self.metrics.weightedSumOfRequestsInSystem += (self.metrics.time - self.requestsInSystem.lastModifiedTimestamp) * self.requestsInSystem.count self.requestsInSystem.count += 1 self.requestsInSystem.lastModifiedTimestamp = self.metrics.time if n_threads < self.system.threadpoolSize: try: cpu = idleCPUs.pop() heapq.heappush(events, self.processRequest(e.request, cpu, self.metrics.time, self.system.quantum)) except IndexError as ex: logger.debug("No Idle CPUs. Pushing the request in threadPool") threadPool.append(e.request) n_threads += 1 elif len(requestBuffer) < self.system.bufferCapacity: logger.debug("Number of threads more than threadpoolSize. Pushing the request in requestBuffer") requestBuffer.append(e.request) else: logger.debug("Dropping the request") e.request.timeoutEvent = False self.metrics.n_dropped += 1 self.requestsInSystem.count -= 1 # The client cannot know whether the request was dropped right away # Therefore waits for a timeout and then retry think time # before issuing a new request arrivalTS = self.metrics.time + \ timeoutSampler() + \ clip(retryThinkTimeSampler()) totalServiceTime = serviceTimeSampler() timeout = timeoutSampler() arrivalEvent, timeoutEvent = newArrival(arrivalTS, totalServiceTime, timeout) heapq.heappush(events, arrivalEvent) heapq.heappush(events, timeoutEvent) elif type(e) == Departure: logger.debug("Event :: Departure") self.metrics.weightedSumOfRequestsInSystem += (self.metrics.time - self.requestsInSystem.lastModifiedTimestamp) * self.requestsInSystem.count self.requestsInSystem.count -= 1 self.requestsInSystem.lastModifiedTimestamp = self.metrics.time if e.request.timeoutEvent: # Timeout hasn't occured yet e.request.timeoutEvent = False # Schedule the next request arrivalTS = self.metrics.time + clip(thinkTimeSampler()) totalServiceTime = serviceTimeSampler() timeout = timeoutSampler() arrivalEvent, timeoutEvent = newArrival(arrivalTS, totalServiceTime, timeout) heapq.heappush(events, arrivalEvent) heapq.heappush(events, timeoutEvent) else: self.requestsInSystem.timedOutCount -= 1 self.metrics.totalResponseTime += self.metrics.time - e.request.arrivalTS self.metrics.n_processed += 1 elif type(e) == CtxSwitch: logger.debug("Event :: Context Switch") if e.cpu.state != CpuState.CTXSWITCH: logger.error("CPU is not in Context Switching") break newRequest = e.cpu.newRequest oldRequest = e.cpu.oldRequest ctxStart = e.cpu.ctxStart e.cpu.totalCtxxTime += self.metrics.time - ctxStart remainingServiceTime = oldRequest.remainingServiceTime if isZero(remainingServiceTime): heapq.heappush(events, Departure(self.metrics.time, oldRequest)) else: threadPool.append(oldRequest) heapq.heappush(events, self.processRequest(newRequest, e.cpu, self.metrics.time, self.system.quantum)) elif type(e) == QuantumOver: logger.debug("Event :: Quantum Over") if e.cpu.state == CpuState.BUSY: request = e.cpu.request processedTime = self.metrics.time - e.cpu.quantumStartTS else: logger.error("CPU was not BUSY at Quantum Over") break e.cpu.request.remainingServiceTime -= processedTime e.cpu.totalProcessedTime += processedTime oldRequest = e.cpu.request if len(threadPool) > 0: newRequest = threadPool[0] threadPool.remove(threadPool[0]) e.cpu.ctxSwitch(newRequest, oldRequest, self.metrics.time) heapq.heappush(events, CtxSwitch(self.metrics.time + self.system.ctxxTime, e.cpu)) elif not(isZero(oldRequest.remainingServiceTime)): heapq.heappush(events, self.processRequest(oldRequest, e.cpu, self.metrics.time, self.system.quantum)) elif len(requestBuffer) > 0: newRequest = requestBuffer[0] requestBuffer.remove(requestBuffer[0]) e.cpu.ctxSwitch(newRequest, oldRequest, self.metrics.time) heapq.heappush(events, CtxSwitch(self.metrics.time + self.system.ctxxTime, e.cpu)) else: n_threads -= 1 e.cpu.setIdle() idleCPUs.append(e.cpu) heapq.heappush(events, Departure(self.metrics.time, oldRequest)) elif type(e) == Timeout: if e.request.timeoutEvent: logger.debug("Event :: Timeout") self.metrics.n_timedOut += 1 self.requestsInSystem.timedOutCount += 1 arrivalTS = self.metrics.time + clip(retryThinkTimeSampler()) totalServiceTime = serviceTimeSampler() timeout = timeoutSampler() arrivalEvent, timeoutEvent = newArrival(arrivalTS, totalServiceTime, timeout) heapq.heappush(events, arrivalEvent) heapq.heappush(events, timeoutEvent) else: pass else: logger.error("Invalid Event") break iterations += 1 pbar.update(iterations) if iterations >= self.system.maxIters: logger.info("Maximum iterations reached") break pbar.finish() for cpu in CPUs: self.metrics.totalProcessedTime += cpu.totalProcessedTime self.metrics.totalCtxxTime += cpu.totalCtxxTime self.metrics.n_timedOutInProcess = self.requestsInSystem.timedOutCount self.metrics.calculate(self.system.n_CPUs) return self.metrics
class SystemInformation(): def __init__(self): self.dialog = QDialog() self.sysinfo = loadUi('gui/systeminformation.ui', baseinstance=self.dialog) self.buffer_size = 60 # number of seconds self.cpu = Cpu() self.memory = Memory() self.cpu_count = self.cpu.getCpuCount() self.memory_data = np.zeros(self.buffer_size) self.cpu_data = np.zeros((self.cpu_count, self.buffer_size)) self.seconds_elapsed = 0 self.number_of_iterations = 1 self.memory_line = None self.cpu_line = None self.cpu_plot = [] self.memory_plot = self.sysinfo.memoryView.plot(pen=(255, 0, 0)) def load_ui(self): # Depending on the number of CPUs this loop will create the plots for count in range(0, self.cpu_count): self.cpu_plot.append( self.sysinfo.cpuView.plot(pen=(randint(0, 255), randint(0, 255), randint(0, 255)))) # Memory and CPU line shows the current x-axis on the widget self.memory_line = self.sysinfo.memoryView.addLine(x=0) self.cpu_line = self.sysinfo.cpuView.addLine(x=0) self.sysinfo.memoryView.setLabel('left', 'Memory', units='%') self.sysinfo.memoryView.setLabel('bottom', 'Time', units='seconds') self.sysinfo.memoryView.setRange(xRange=[0, self.buffer_size], yRange=[0, 100]) self.sysinfo.memoryView.showGrid(x=True, y=True) self.sysinfo.cpuView.setLabel('left', 'CPU', units='%') self.sysinfo.cpuView.setLabel('bottom', 'Time', units='seconds') self.sysinfo.cpuView.setRange(xRange=[0, self.buffer_size], yRange=[0, 100]) self.sysinfo.cpuView.showGrid(x=True, y=True) def load_data(self): # Plot the memory line based on the memory reported. self.memory_data[self.seconds_elapsed:self.seconds_elapsed + self.number_of_iterations] = \ self.memory.getAverageSystemMemory() self.memory_plot.setData(self.memory_data) per_cpu_percent = self.cpu.getPerCPUPercent() # Loop to iterate through the number of CPUs in the machine and plot them on the widget for cpu in range(0, self.cpu_count): self.cpu_data[cpu][self.seconds_elapsed:self.seconds_elapsed + self.number_of_iterations] = \ per_cpu_percent[cpu] self.cpu_plot[cpu].setData(self.cpu_data[cpu]) # Increase the seconds based on the number of times update is requested self.seconds_elapsed = (self.seconds_elapsed + self.number_of_iterations) % self.buffer_size # Move the memory and cpu line on x-axis self.memory_line.setValue(self.seconds_elapsed) self.cpu_line.setValue(self.seconds_elapsed) # get virtual memory statistics memory_statistics = self.memory.getSystemMemory() self.sysinfo.totalMemory.setText( str(Pmutils.convertBytes(memory_statistics[0]))) self.sysinfo.availableMemory.setText( str(Pmutils.convertBytes(memory_statistics[1]))) self.sysinfo.usedMemory.setText( str(Pmutils.convertBytes(memory_statistics[3]))) # get swap memory statistics swap_memory_statistics = self.memory.getSwapMemory() self.sysinfo.totalSwap.setText( str(Pmutils.convertBytes(swap_memory_statistics[0]))) self.sysinfo.usedSwap.setText( str(Pmutils.convertBytes(swap_memory_statistics[1]))) self.sysinfo.availableSwap.setText( str(Pmutils.convertBytes(swap_memory_statistics[2])))
from Cpu import Cpu from RSDL import Rsdl if __name__ == '__main__': print("===Rotating Staircase DeadLine Simulator===") rsdl = Rsdl() cpu = Cpu(rsdl) cpu.create_n_randon_tasks(15) cpu.run()
def main(): cartridge = read_file(sys.argv[1]) print(len(cartridge)) cpu = Cpu(cartridge) cpu.process()
from Cpu import Cpu from Pmutils import Pmutils from Processes import Processes # CPU Tests cpu = Cpu() print(cpu.getCpuCount("bad info")) print(cpu.getCpuCount(True)) print(cpu.getCpuCount(False)) print(cpu.getCpuCount()) #Pmtutils Tests pmu = Pmutils() print(pmu.convertBytes(4444.23432)) print(pmu.convertBytes("not a number")) print(pmu.convertBytes(1)) #Process Test proc = Processes()
def __init__(self, quantum, memoriaReal, memoriaSwap, pageSize): self.memoriaAlloc = MemoriaAlloc(memoriaReal / pageSize, memoriaSwap / pageSize) self.cpu = Cpu(quantum) self.pidContador = 1 self.pageSize = pageSize