parent
1d97eb70fc
commit
3fef70f0d5
1 changed files with 49 additions and 41 deletions
@ -1,64 +1,72 @@ |
|||||||
#!/usr/bin/env python3 |
#!/usr/bin/env python3 |
||||||
|
import argparse |
||||||
|
|
||||||
import numpy as np |
import numpy as np |
||||||
|
|
||||||
from cereal.messaging import SubMaster |
from cereal.messaging import SubMaster |
||||||
|
|
||||||
|
|
||||||
def cputime_total(ct): |
def cputime_total(ct): |
||||||
return ct.user + ct.nice + ct.system + ct.idle + ct.iowait + ct.irq + ct.softirq |
return ct.user + ct.nice + ct.system + ct.idle + ct.iowait + ct.irq + ct.softirq |
||||||
|
|
||||||
|
|
||||||
def cputime_busy(ct): |
def cputime_busy(ct): |
||||||
return ct.user + ct.nice + ct.system + ct.irq + ct.softirq |
return ct.user + ct.nice + ct.system + ct.irq + ct.softirq |
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__": |
||||||
|
parser = argparse.ArgumentParser() |
||||||
|
parser.add_argument('--mem', action='store_true') |
||||||
|
args = parser.parse_args() |
||||||
|
|
||||||
sm = SubMaster(['thermal', 'procLog']) |
sm = SubMaster(['thermal', 'procLog']) |
||||||
|
|
||||||
last_temp = 0.0 |
last_temp = 0.0 |
||||||
last_mem = 0.0 |
last_mem = 0.0 |
||||||
total_times = [0., 0., 0., 0.] |
total_times = [0., 0., 0., 0.] |
||||||
busy_times = [0., 0., 0.0, 0.] |
busy_times = [0., 0., 0.0, 0.] |
||||||
|
|
||||||
|
while True: |
||||||
|
sm.update() |
||||||
|
|
||||||
while True: |
if sm.updated['thermal']: |
||||||
sm.update() |
t = sm['thermal'] |
||||||
|
last_temp = np.mean([t.cpu0, t.cpu1, t.cpu2, t.cpu3]) / 10. |
||||||
|
last_mem = t.memUsedPercent |
||||||
|
|
||||||
if sm.updated['thermal']: |
if sm.updated['procLog']: |
||||||
t = sm['thermal'] |
m = sm['procLog'] |
||||||
last_temp = np.mean([t.cpu0, t.cpu1, t.cpu2, t.cpu3]) / 10. |
|
||||||
last_mem = t.memUsedPercent |
|
||||||
|
|
||||||
if sm.updated['procLog']: |
|
||||||
m = sm['procLog'] |
|
||||||
|
|
||||||
mems = {} |
cores = [0., 0., 0., 0.] |
||||||
for proc in m.procs: |
total_times_new = [0., 0., 0., 0.] |
||||||
name = proc.name |
busy_times_new = [0., 0., 0.0, 0.] |
||||||
if len(proc.cmdline): |
|
||||||
name = proc.cmdline[0] |
|
||||||
if len(proc.exe): |
|
||||||
name = proc.exe + " - " + name |
|
||||||
mems[name] = float(proc.memRss) / 1e6 |
|
||||||
|
|
||||||
cores = [0., 0., 0., 0.] |
for c in m.cpuTimes: |
||||||
total_times_new = [0., 0., 0., 0.] |
n = c.cpuNum |
||||||
busy_times_new = [0., 0., 0.0, 0.] |
total_times_new[n] = cputime_total(c) |
||||||
|
busy_times_new[n] = cputime_busy(c) |
||||||
|
|
||||||
for c in m.cpuTimes: |
for n in range(4): |
||||||
n = c.cpuNum |
t_busy = busy_times_new[n] - busy_times[n] |
||||||
total_times_new[n] = cputime_total(c) |
t_total = total_times_new[n] - total_times[n] |
||||||
busy_times_new[n] = cputime_busy(c) |
cores[n] = t_busy / t_total |
||||||
|
|
||||||
for n in range(4): |
total_times = total_times_new[:] |
||||||
t_busy = busy_times_new[n] - busy_times[n] |
busy_times = busy_times_new[:] |
||||||
t_total = total_times_new[n] - total_times[n] |
|
||||||
cores[n] = t_busy / t_total |
|
||||||
|
|
||||||
total_times = total_times_new[:] |
print("CPU %.2f%% - RAM: %.2f - Temp %.2f" % (100. * np.mean(cores), last_mem, last_temp)) |
||||||
busy_times = busy_times_new[:] |
|
||||||
|
|
||||||
print() |
if args.mem: |
||||||
print("CPU %.2f%% - RAM: %.2f - Temp %.2f" % (100. * np.mean(cores), last_mem, last_temp)) |
mems = {} |
||||||
print("Top memory usage:") |
for proc in m.procs: |
||||||
for k, v in sorted(mems.items(), key=lambda item: item[1], reverse=True)[:10]: |
name = proc.name |
||||||
print(f"{k.rjust(70)} {v:.2f} MB") |
if len(proc.cmdline): |
||||||
|
name = proc.cmdline[0] |
||||||
|
if len(proc.exe): |
||||||
|
name = proc.exe + " - " + name |
||||||
|
mems[name] = float(proc.memRss) / 1e6 |
||||||
|
print("Top memory usage:") |
||||||
|
for k, v in sorted(mems.items(), key=lambda item: item[1], reverse=True)[:10]: |
||||||
|
print(f"{k.rjust(70)} {v:.2f} MB") |
||||||
|
print() |
||||||
|
Loading…
Reference in new issue