From 413d7a4243d2965030c2d558142060c82730bfa9 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Mon, 5 Oct 2020 20:40:32 -0700 Subject: [PATCH] paramsd profiling old-commit-hash: 0d11acf34ea7cf23d00d206fcd284bdf8b9f5d54 --- selfdrive/test/profiling/locationd.py | 49 --------------------------- selfdrive/test/profiling/profiler.py | 29 ++++++++++------ 2 files changed, 19 insertions(+), 59 deletions(-) delete mode 100755 selfdrive/test/profiling/locationd.py diff --git a/selfdrive/test/profiling/locationd.py b/selfdrive/test/profiling/locationd.py deleted file mode 100755 index 4c478cf778..0000000000 --- a/selfdrive/test/profiling/locationd.py +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env python3 - -import cProfile # pylint: disable=import-error -import pprofile # pylint: disable=import-error -import pyprof2calltree # pylint: disable=import-error - -from tools.lib.logreader import LogReader -from selfdrive.locationd.locationd import locationd_thread -from selfdrive.test.profiling.lib import SubMaster, PubMaster, ReplayDone - -BASE_URL = "https://commadataci.blob.core.windows.net/openpilotci/" - -CARS = { - 'toyota': ("77611a1fac303767|2020-02-29--13-29-33/3", "TOYOTA COROLLA TSS2 2019"), -} - - -def get_inputs(msgs, process): - sub_socks = ['gpsLocationExternal', 'sensorEvents', 'cameraOdometry', 'liveCalibration', 'carState'] - trigger = 'cameraOdometry' - - sm = SubMaster(msgs, trigger, sub_socks) - pm = PubMaster() - return sm, pm - - -if __name__ == "__main__": - segment, fingerprint = CARS['toyota'] - segment = segment.replace('|', '/') - rlog_url = f"{BASE_URL}{segment}/rlog.bz2" - msgs = list(LogReader(rlog_url)) - - # Statistical - sm, pm = get_inputs(msgs, 'locationd') - with pprofile.StatisticalProfile()(period=0.00001) as pr: - try: - locationd_thread(sm, pm) - except ReplayDone: - pass - pr.dump_stats('cachegrind.out.locationd_statistical') - - # Deterministic - sm, pm = get_inputs(msgs, 'controlsd') - with cProfile.Profile() as pr: - try: - locationd_thread(sm, pm) - except ReplayDone: - pass - pyprof2calltree.convert(pr.getstats(), 'cachegrind.out.locationd_deterministic') diff --git a/selfdrive/test/profiling/profiler.py b/selfdrive/test/profiling/profiler.py index c4bfe15957..54f722af2b 100755 --- a/selfdrive/test/profiling/profiler.py +++ b/selfdrive/test/profiling/profiler.py @@ -27,7 +27,10 @@ def get_inputs(msgs, process): sm = SubMaster(msgs, trigger, sub_socks) pm = PubMaster() - can_sock = SubSocket(msgs, 'can') + if 'can' in sub_socks: + can_sock = SubSocket(msgs, 'can') + else: + can_sock = None return sm, pm, can_sock @@ -39,32 +42,38 @@ def profile(proc, func, car='toyota'): os.environ['FINGERPRINT'] = fingerprint - # Statistical - sm, pm, can_sock = get_inputs(msgs, proc) - with pprofile.StatisticalProfile()(period=0.00001) as pr: + def run(): + sm, pm, can_sock = get_inputs(msgs, proc) try: - func(sm, pm, can_sock) + if can_sock is not None: + func(sm, pm, can_sock) + else: + func(sm, pm) except ReplayDone: pass + + # Statistical + with pprofile.StatisticalProfile()(period=0.00001) as pr: + run() pr.dump_stats(f'cachegrind.out.{proc}_statistical') # Deterministic - sm, pm, can_sock = get_inputs(msgs, proc) with cProfile.Profile() as pr: - try: - func(sm, pm, can_sock) - except ReplayDone: - pass + run() pyprof2calltree.convert(pr.getstats(), f'cachegrind.out.{proc}_deterministic') if __name__ == '__main__': from selfdrive.controls.controlsd import main as controlsd_thread from selfdrive.controls.radard import radard_thread + from selfdrive.locationd.locationd import locationd_thread + from selfdrive.locationd.paramsd import main as paramsd_thread procs = { 'radard': radard_thread, 'controlsd': controlsd_thread, + 'locationd': locationd_thread, + 'paramsd': paramsd_thread, } proc = sys.argv[1]