def start_monitoring(process_name, interval=1): while True: # Find PID by the process_name get_pid = [ p.pid for p in psutil.process_iter() if process_name in str(p.name) ] get_pid = int(get_pid[0]) # Fing process by PID for RAM monitoring memory = psutil.Process(get_pid) # Fing process by PID for CPU monitoring cpu = Application().connect(process=get_pid) memory_usage = float(memory.memory_info()[11] / 1048576) # bytes in megabytes cpu_usage = cpu.cpu_usage(1) print str(cpu_usage), str(memory_usage) # Writing data in separate logs for every process with open(r'C:\CPU.log', 'a') as log_file: log_file.write( str(datetime.datetime.now()) + " FgStSearchSvc.exe CPU's Usage = " + str(cpu_usage) + '\n') with open(r'C:\Memory.log', 'a') as log_file: log_file.write( str(datetime.datetime.now()) + " FgStSearchSvc.exe Memory Usage = " + str(memory_usage) + '\n') time.sleep(interval) # data acquisition interval
def test_cpu_usage(self): """Verify that cpu_usage() works correctly""" app = Application() self.assertRaises(AppNotConnected, app.cpu_usage) app.start(_notepad_exe()) self.assertEquals(0.0 <= app.cpu_usage() <= 100.0, True) app.UntitledNotepad.MenuSelect("File->Exit") app.UntitledNotepad.WaitNot('exists')
def test_wait_cpu_usage_lower_uia(self): """Test that wait_cpu_usage_lower() works correctly for UIA""" app = Application(backend='uia') app.start('notepad.exe') try: app.wait_cpu_usage_lower(threshold = 1.5, timeout = 30, usage_interval = 2) finally: app.kill() app.cpu_usage = mock.Mock(return_value=10) self.assertRaises( RuntimeError, app.wait_cpu_usage_lower, threshold = 9.0, timeout = 5, usage_interval = 0.5 )
hm.HookMouse() hm.HookKeyboard() pythoncom.PumpMessages() t = Timer(0.1, fie) # Quit after 5 seconds main_thread_id = win32api.GetCurrentThreadId() t.start() hm = pyHook.HookManager() hm.MouseAll = uMad hm.KeyAll = uMad hm.MouseLeftDown = wegood hm.MouseLeftUp = wegood hm.HookMouse() hm.HookKeyboard() pythoncom.PumpMessages() time.sleep(0.1) n = app.cpu_usage(interval=30) print("CPU usage: " + str(n)) appconnect2 = app2.connect(title='Convert to RINEX') appconnect2.ConverttoRINEX.set_focus() appconnect2.ConverttoRINEX.Button.wait( wait_for="visible enabled ready exists", timeout=10000, retry_interval=5) appconnect2.ConverttoRINEX.set_focus() appconnect2.ConverttoRINEX.Button.click_input() print("Clicked Convert") time.sleep(3) #def fifth(): # try: # print ("hmm")