|
|
@@ -23,7 +23,7 @@ class LogReceiver(object): |
|
|
|
and stores them locally.""" |
|
|
|
def __init__(self, pipe): |
|
|
|
self.pipe = pipe |
|
|
|
self.log = io.StringIO() |
|
|
|
self.log = io.BytesIO() |
|
|
|
self.thread = threading.Thread(target = self.run) |
|
|
|
self.thread.start() |
|
|
|
|
|
|
@@ -39,7 +39,7 @@ class LogReceiver(object): |
|
|
|
return self.log.getvalue() |
|
|
|
|
|
|
|
def clear(self): |
|
|
|
self.log = io.StringIO() |
|
|
|
self.log = io.BytesIO() |
|
|
|
|
|
|
|
class Process(object): |
|
|
|
"""Spawn and manage a subprocess, and capture its output.""" |
|
|
@@ -101,7 +101,7 @@ class Process(object): |
|
|
|
# Find all children |
|
|
|
group = getpgid(self._process.pid) |
|
|
|
main = psutil.Process(self._process.pid) |
|
|
|
allproc = [ main ] + main.get_children(recursive = True) |
|
|
|
allproc = [ main ] + main.children(recursive = True) |
|
|
|
|
|
|
|
# Kill with SIGTERM, if they're still in this process group |
|
|
|
for proc in allproc: |
|
|
@@ -142,9 +142,9 @@ class Process(object): |
|
|
|
Call .get_info() about a second later.""" |
|
|
|
try: |
|
|
|
main = psutil.Process(self._process.pid) |
|
|
|
self._process_list = [ main ] + main.get_children(recursive = True) |
|
|
|
self._process_list = [ main ] + main.children(recursive = True) |
|
|
|
for proc in self._process_list: |
|
|
|
proc.get_cpu_percent(0) |
|
|
|
proc.cpu_percent(0) |
|
|
|
except psutil.Error: # pragma: no cover (race condition) |
|
|
|
self._process_list = [ ] |
|
|
|
|
|
|
@@ -165,14 +165,14 @@ class Process(object): |
|
|
|
d = self.get_empty_info() |
|
|
|
for proc in self._process_list: |
|
|
|
try: |
|
|
|
d["cpu_percent"] += proc.get_cpu_percent(0) |
|
|
|
cpuinfo = proc.get_cpu_times() |
|
|
|
d["cpu_percent"] += proc.cpu_percent(0) |
|
|
|
cpuinfo = proc.cpu_times() |
|
|
|
d["cpu_user"] += cpuinfo.user |
|
|
|
d["cpu_sys"] += cpuinfo.system |
|
|
|
meminfo = proc.get_memory_info() |
|
|
|
meminfo = proc.memory_info() |
|
|
|
d["mem_phys"] += meminfo.rss |
|
|
|
d["mem_virt"] += meminfo.vms |
|
|
|
ioinfo = proc.get_io_counters() |
|
|
|
ioinfo = proc.io_counters() |
|
|
|
d["io_read"] += ioinfo.read_bytes |
|
|
|
d["io_write"] += ioinfo.write_bytes |
|
|
|
d["procs"] += 1 |
|
|
@@ -275,13 +275,11 @@ class ProcessManager(object): |
|
|
|
|
|
|
|
# Retrieve info for system |
|
|
|
info["system"]["cpu_percent"] = sum(psutil.cpu_percent(0, percpu=True)) |
|
|
|
info["system"]["cpu_max"] = 100.0 * psutil.NUM_CPUS |
|
|
|
info["system"]["procs"] = len(psutil.get_pid_list()) |
|
|
|
# psutil > 0.6.0's psutil.virtual_memory() would be better here, |
|
|
|
# but this should give the same info. |
|
|
|
meminfo = psutil.phymem_usage() |
|
|
|
info["system"]["cpu_max"] = 100.0 * psutil.cpu_count() |
|
|
|
info["system"]["procs"] = len(psutil.pids()) |
|
|
|
meminfo = psutil.virtual_memory() |
|
|
|
info["system"]["mem_total"] = meminfo.total |
|
|
|
info["system"]["mem_used"] = int(meminfo.total * meminfo.percent / 100) |
|
|
|
info["system"]["mem_used"] = meminfo.used |
|
|
|
|
|
|
|
# Retrieve info for each PID |
|
|
|
for pid in self: |
|
|
|