mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-07-23 23:02:04 +08:00
e6055d68be
Original commits:
* Sync: `commaai/openpilot:master` into `sunnypilot/sunnypilot:master-new` (#580)
* test_processes: update ref logs to afde277
* # Conflicts:
* # .github/workflows/ui_preview.yaml
* # opendbc_repo
* # panda
* # release/release_files.py
* # selfdrive/test/process_replay/ref_commit
* # selfdrive/ui/tests/test_ui/run.py
* bring back ui.py (#34396)
* * bring back uipy
* * fix it
* * fix
* Log satellite count in GpsLocationData (#34395)
* * Log satellite count in GpsLocationData
* * update refs
* * forgot to build
* Toyota: allow brake hold (#34394)
* toyota okay
* fix uv (#34393)
* uv fix
* Update RELEASES.md
* release this month
* no need
* fix
* unused
* Longitudinal: Distance button hold to toggle Chill/Experimental Mode
* Hyundai: match cancel button panda safety logic (#34390)
* * rising edge
* * should work
* * TODO
* * fix
* card: fix cruise speed initialization w/ buttons (#34386)
* * fix initialize w/ buttons
* * what
* * comment
* VW: switch to common pcmCruise check (#34389)
* Update car_specific.py
* card: vcruise all in one place (#34387)
* * no reason to not be here
* * oh this was off by a frame!
* * ref
* Fix missing visual car dash alerts (#34385)
* * fix missing visual dash alerts
* * update refs
* process_replay: add cast in migrate_longitudinalPlan (#34383)
* * Cast
* * Something
* * Remove newline
* process_replay: ignore unknown members in the migration code (#34382)
* * Fix the migration for the events
* * clean up
* clean up
* clean up
* * no continue
* ---------
* Co-authored-by: Shane Smiskol <shane@smiskol.com>
* Getting rid of openpilot.common.numpy_fast (#34368)
* * Got rid openpilot.common.numpy_fast
* * fixed some data type erros
* * importing numpy instead of importing specific functions
* * fixing some numpy importing mistakes
* * Update selfdrive/car/cruise.py
* ---------
* Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
* Toyota: remove longitudinal derivative (#34378)
* * Update Python packages
* * update refs
* ---------
* Co-authored-by: Vehicle Researcher <user@comma.ai>
* Co-authored-by: Shane Smiskol <shane@smiskol.com>
* PlotJuggler: Layout for debugging locationdTemporaryError (#34381)
* * PlotJuggler: layout for debugging locationd
* * not needed, and codespell doesn't like it
* raylib: revert auto fit screen size (#34380)
* revert auto fit screen size
* Remove release files (conceptually) (#34379)
* * Remove release files (conceptually)
* * fix
* raylib: refactor to implement new App class (#34375)
* refactor to implement new App class
* [bot] Update Python packages (#34376)
* * Update Python packages
* * time -> time_helpers
* ---------
* Co-authored-by: Vehicle Researcher <user@comma.ai>
* Co-authored-by: Maxime Desroches <desroches.maxime@gmail.com>
* CI: Add missing uppercase_keyboard UI view (#34347)
* * add-uppercase-preview
* * testing-UI-on-fork
* * change back
* * add-my-branch
* * needs to see sha from fork for test
* * fix missing sha
* * change back
* * get correct named artifact
* * try this
* * experimenting coordinates
* * try these coordinates
* * try these coordinates
* * draws circles to see touches - changes coordinates
* * try these changes
* * better coordinates
* * click is more centered
* * try again
* * revert back
* * revert these too
* * last revert...
* Keyboard: add missing control btns to uppercase (#34344)
* * add-slash-to uppercase
* * Trigger UI preview workflow
* Move uds.py (#34374)
* * rm uds pt. 1
* * rm uds pt. 2
* * imports
* oops need raw
* third_party: add raygui (#34369)
* swaglog: fix locale dependence (#34367)
* encoderd: refactor VideoEncoder::publisher_publish to standardize member variable access (#34342)
* remove redundant pointer parameter
* modeld: properly release OpenCL context in `__dealloc__` method (#34353)
* release OpenCL context in __dealloc__
* release soon
* loggerd: typing and remove unused default arg (#34349)
* deleter cleanups (#34345)
107 lines
2.9 KiB
Python
Executable File
107 lines
2.9 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import argparse
|
|
import numpy as np
|
|
import capnp
|
|
from collections import defaultdict
|
|
|
|
from cereal.messaging import SubMaster
|
|
|
|
def cputime_total(ct):
|
|
return ct.user + ct.nice + ct.system + ct.idle + ct.iowait + ct.irq + ct.softirq
|
|
|
|
|
|
def cputime_busy(ct):
|
|
return ct.user + ct.nice + ct.system + ct.irq + ct.softirq
|
|
|
|
|
|
def proc_cputime_total(ct):
|
|
return ct.cpuUser + ct.cpuSystem + ct.cpuChildrenUser + ct.cpuChildrenSystem
|
|
|
|
|
|
def proc_name(proc):
|
|
name = proc.name
|
|
if len(proc.cmdline):
|
|
name = proc.cmdline[0]
|
|
if len(proc.exe):
|
|
name = proc.exe + " - " + name
|
|
|
|
return name
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('--mem', action='store_true')
|
|
parser.add_argument('--cpu', action='store_true')
|
|
args = parser.parse_args()
|
|
|
|
sm = SubMaster(['deviceState', 'procLog'])
|
|
|
|
last_temp = 0.0
|
|
last_mem = 0.0
|
|
total_times = [0.]*8
|
|
busy_times = [0.]*8
|
|
|
|
prev_proclog: capnp._DynamicStructReader | None = None
|
|
prev_proclog_t: int | None = None
|
|
|
|
while True:
|
|
sm.update()
|
|
|
|
if sm.updated['deviceState']:
|
|
t = sm['deviceState']
|
|
last_temp = np.mean(t.cpuTempC)
|
|
last_mem = t.memoryUsagePercent
|
|
|
|
if sm.updated['procLog']:
|
|
m = sm['procLog']
|
|
|
|
cores = [0.]*8
|
|
total_times_new = [0.]*8
|
|
busy_times_new = [0.]*8
|
|
|
|
for c in m.cpuTimes:
|
|
n = c.cpuNum
|
|
total_times_new[n] = cputime_total(c)
|
|
busy_times_new[n] = cputime_busy(c)
|
|
|
|
for n in range(8):
|
|
t_busy = busy_times_new[n] - busy_times[n]
|
|
t_total = total_times_new[n] - total_times[n]
|
|
cores[n] = t_busy / t_total
|
|
|
|
total_times = total_times_new[:]
|
|
busy_times = busy_times_new[:]
|
|
|
|
print(f"CPU {100.0 * np.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: dict[str, float] = defaultdict(float)
|
|
dt = (sm.logMonoTime['procLog'] - prev_proclog_t) / 1e9
|
|
for proc in m.procs:
|
|
try:
|
|
name = proc_name(proc)
|
|
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
|
|
except IndexError:
|
|
pass
|
|
|
|
print("Top CPU usage:")
|
|
for k, v in sorted(procs.items(), key=lambda item: item[1], reverse=True)[:10]:
|
|
print(f"{k.rjust(70)} {v:.2f} %")
|
|
print()
|
|
|
|
if args.mem:
|
|
mems = {}
|
|
for proc in m.procs:
|
|
name = proc_name(proc)
|
|
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()
|
|
|
|
prev_proclog = m
|
|
prev_proclog_t = sm.logMonoTime['procLog']
|