def cpu_times(self): try: ret = cext.proc_cpu_times(self.pid) except OSError as err: if err.errno in ACCESS_DENIED_SET: ret = cext.proc_cpu_times_2(self.pid) else: raise return _common.pcputimes(*ret)
def cpu_times(self): with open("/proc/%s/stat" % self.pid, 'rb') as f: st = f.read().strip() # ignore the first two values ("pid (exe)") st = st[st.find(b')') + 2:] values = st.split(b' ') utime = float(values[11]) / CLOCK_TICKS stime = float(values[12]) / CLOCK_TICKS return _common.pcputimes(utime, stime)
def cpu_times(self): f = open("/proc/%s/stat" % self.pid) try: st = f.read().strip() finally: f.close() # ignore the first two values ("pid (exe)") st = st[st.find(')') + 2:] values = st.split(' ') utime = float(values[11]) / CLOCK_TICKS stime = float(values[12]) / CLOCK_TICKS return _common.pcputimes(utime, stime)
def test_run_negative_last_cpu_times(caplog): cpu = Cpu() cpu.last_cpu_times = pcputimes(user=1e12, system=1e12, children_user=0.0, children_system=0.0) result = cpu.run() assert result is None record_tuples = [ r for r in caplog.record_tuples if r[0] == "scout_apm.core.samplers.cpu" ] assert len(record_tuples) == 1 _, level, message = record_tuples[0] assert level == logging.DEBUG assert message.startswith( "Process CPU: Negative process time elapsed. utime: ") assert message.endswith( "This is normal to see when starting a forking web server.")
def cpu_times(self): user, system = cext.proc_cpu_times(self.pid) return _common.pcputimes(user, system)
def cpu_times(self): """return a tuple containing process user/kernel time.""" user, system = cext.proc_cpu_times(self.pid) return _common.pcputimes(user, system)