|
|
|
@ -1,10 +1,11 @@ |
|
|
|
|
#!/usr/bin/env python3 |
|
|
|
|
import argparse |
|
|
|
|
import capnp |
|
|
|
|
from collections import defaultdict |
|
|
|
|
|
|
|
|
|
from cereal.messaging import SubMaster |
|
|
|
|
from common.numpy_fast import mean |
|
|
|
|
from typing import Optional |
|
|
|
|
from typing import Optional, Dict |
|
|
|
|
|
|
|
|
|
def cputime_total(ct): |
|
|
|
|
return ct.user + ct.nice + ct.system + ct.idle + ct.iowait + ct.irq + ct.softirq |
|
|
|
@ -75,7 +76,7 @@ if __name__ == "__main__": |
|
|
|
|
print(f"CPU {100.0 * mean(cores):.2f}% - RAM: {last_mem:.2f}% - Temp {last_temp:.2f}C") |
|
|
|
|
|
|
|
|
|
if args.cpu and prev_proclog is not None and prev_proclog_t is not None: |
|
|
|
|
procs = {} |
|
|
|
|
procs: Dict[str, float] = defaultdict(float) |
|
|
|
|
dt = (sm.logMonoTime['procLog'] - prev_proclog_t) / 1e9 |
|
|
|
|
for proc in m.procs: |
|
|
|
|
try: |
|
|
|
@ -83,12 +84,12 @@ if __name__ == "__main__": |
|
|
|
|
prev_proc = [p for p in prev_proclog.procs if proc.pid == p.pid][0] |
|
|
|
|
cpu_time = proc_cputime_total(proc) - proc_cputime_total(prev_proc) |
|
|
|
|
cpu_usage = cpu_time / dt * 100. |
|
|
|
|
procs[name] = cpu_usage |
|
|
|
|
procs[name] += cpu_usage |
|
|
|
|
except IndexError: |
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
print("Top CPU usage:") |
|
|
|
|
for k, v in sorted(procs.items(), key=lambda item: item[1], reverse=True)[:10]: # type: ignore |
|
|
|
|
for k, v in sorted(procs.items(), key=lambda item: item[1], reverse=True)[:10]: |
|
|
|
|
print(f"{k.rjust(70)} {v:.2f} %") |
|
|
|
|
print() |
|
|
|
|
|
|
|
|
|