From ad7f0207ac9c587c2e1740c61bddad5fbba11296 Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Tue, 29 Jun 2021 22:55:18 +0200 Subject: [PATCH] Log gpu usage (#21404) * Log gpu usage * 100 total * bump cereal Co-authored-by: Adeeb Shihadeh --- cereal | 2 +- selfdrive/hardware/base.py | 4 ++++ selfdrive/hardware/eon/hardware.py | 3 +++ selfdrive/hardware/pc/hardware.py | 3 +++ selfdrive/hardware/tici/hardware.py | 7 +++++++ selfdrive/thermald/thermald.py | 1 + 6 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cereal b/cereal index 232e28c2bb..e1793a1854 160000 --- a/cereal +++ b/cereal @@ -1 +1 @@ -Subproject commit 232e28c2bb049fa8b7c2da0a2add27645b5a6bc2 +Subproject commit e1793a1854eb5f76a304b30ee96dee5a0f0b2cc4 diff --git a/selfdrive/hardware/base.py b/selfdrive/hardware/base.py index d155f63b5d..9ed66bb3b1 100644 --- a/selfdrive/hardware/base.py +++ b/selfdrive/hardware/base.py @@ -113,3 +113,7 @@ class HardwareBase: @abstractmethod def set_power_save(self, enabled): pass + + @abstractmethod + def get_gpu_usage_percent(self): + pass diff --git a/selfdrive/hardware/eon/hardware.py b/selfdrive/hardware/eon/hardware.py index 744b0ae398..9670d1f172 100644 --- a/selfdrive/hardware/eon/hardware.py +++ b/selfdrive/hardware/eon/hardware.py @@ -377,3 +377,6 @@ class Android(HardwareBase): def set_power_save(self, enabled): pass + + def get_gpu_usage_percent(self): + return 0 diff --git a/selfdrive/hardware/pc/hardware.py b/selfdrive/hardware/pc/hardware.py index 0240f98bb1..7a0f8ff088 100644 --- a/selfdrive/hardware/pc/hardware.py +++ b/selfdrive/hardware/pc/hardware.py @@ -85,3 +85,6 @@ class Pc(HardwareBase): def set_power_save(self, enabled): pass + + def get_gpu_usage_percent(self): + return 0 diff --git a/selfdrive/hardware/tici/hardware.py b/selfdrive/hardware/tici/hardware.py index e47e924af7..2d8b873c5a 100644 --- a/selfdrive/hardware/tici/hardware.py +++ b/selfdrive/hardware/tici/hardware.py @@ -262,3 +262,10 @@ class Tici(HardwareBase): # TODO: fix permissions with udev val = "0" if enabled else "1" os.system(f"sudo su -c 'echo {val} > /sys/devices/system/cpu/cpu{i}/online'") + + def get_gpu_usage_percent(self): + try: + used, total = open('/sys/class/kgsl/kgsl-3d0/gpubusy').read().strip().split() + return 100.0 * int(used) / int(total) + except Exception: + return 0 diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index c02820a830..46f6773227 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -265,6 +265,7 @@ def thermald_thread(): msg.deviceState.freeSpacePercent = get_available_percent(default=100.0) msg.deviceState.memoryUsagePercent = int(round(psutil.virtual_memory().percent)) msg.deviceState.cpuUsagePercent = int(round(psutil.cpu_percent())) + msg.deviceState.gpuUsagePercent = int(round(HARDWARE.get_gpu_usage_percent())) msg.deviceState.networkType = network_type msg.deviceState.networkStrength = network_strength if network_info is not None: