From 6315957cf4b79a05a06e03dae93ed17c18d3d234 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sat, 6 Jan 2024 16:20:28 -0800 Subject: [PATCH] remove common.profiler (#30927) * remove common.profiler * cleanup old-commit-hash: f0ccb84ae3ed890fdf5610573a8b8882f4e29d3e --- common/profiler.py | 45 --------------------------------- selfdrive/controls/controlsd.py | 9 ------- 2 files changed, 54 deletions(-) delete mode 100644 common/profiler.py diff --git a/common/profiler.py b/common/profiler.py deleted file mode 100644 index 8b1a7a8cfa..0000000000 --- a/common/profiler.py +++ /dev/null @@ -1,45 +0,0 @@ -import time - -class Profiler(): - def __init__(self, enabled=False): - self.enabled = enabled - self.cp = {} - self.cp_ignored = [] - self.iter = 0 - self.start_time = time.time() - self.last_time = self.start_time - self.tot = 0. - - def reset(self, enabled=False): - self.enabled = enabled - self.cp = {} - self.cp_ignored = [] - self.iter = 0 - self.start_time = time.time() - self.last_time = self.start_time - - def checkpoint(self, name, ignore=False): - # ignore flag needed when benchmarking threads with ratekeeper - if not self.enabled: - return - tt = time.time() - if name not in self.cp: - self.cp[name] = 0. - if ignore: - self.cp_ignored.append(name) - self.cp[name] += tt - self.last_time - if not ignore: - self.tot += tt - self.last_time - self.last_time = tt - - def display(self): - if not self.enabled: - return - self.iter += 1 - print("******* Profiling %d *******" % self.iter) - for n, ms in sorted(self.cp.items(), key=lambda x: -x[1]): - if n in self.cp_ignored: - print("%30s: %9.2f avg: %7.2f percent: %3.0f IGNORED" % (n, ms*1000.0, ms*1000.0/self.iter, ms/self.tot*100)) - else: - print("%30s: %9.2f avg: %7.2f percent: %3.0f" % (n, ms*1000.0, ms*1000.0/self.iter, ms/self.tot*100)) - print(f"Iter clock: {self.tot / self.iter:2.6f} TOTAL: {self.tot:2.2f}") diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index 46a0b7f462..698c149515 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -8,7 +8,6 @@ from typing import SupportsFloat from cereal import car, log from openpilot.common.numpy_fast import clip from openpilot.common.realtime import config_realtime_process, Priority, Ratekeeper, DT_CTRL -from openpilot.common.profiler import Profiler from openpilot.common.params import Params import cereal.messaging as messaging from cereal.visionipc import VisionIpcClient, VisionStreamType @@ -195,7 +194,6 @@ class Controls: # controlsd is driven by can recv, expected at 100Hz self.rk = Ratekeeper(100, print_delay_threshold=None) - self.prof = Profiler(False) # off by default def set_initial_state(self): if REPLAY: @@ -851,12 +849,10 @@ class Controls: def step(self): start_time = time.monotonic() - self.prof.checkpoint("Ratekeeper", ignore=True) # Sample data from sockets and get a carState CS = self.data_sample() cloudlog.timestamp("Data sampled") - self.prof.checkpoint("Sample") self.update_events(CS) cloudlog.timestamp("Events updated") @@ -864,16 +860,12 @@ class Controls: if not self.CP.passive and self.initialized: # Update control state self.state_transition(CS) - self.prof.checkpoint("State transition") # Compute actuators (runs PID loops and lateral MPC) CC, lac_log = self.state_control(CS) - self.prof.checkpoint("State Control") - # Publish data self.publish_logs(CS, start_time, CC, lac_log) - self.prof.checkpoint("Sent") self.CS_prev = CS @@ -893,7 +885,6 @@ class Controls: while True: self.step() self.rk.monitor_time() - self.prof.display() except SystemExit: e.set() t.join()