From 5d69e9728155e83a013833c7ce32bb9ee97ff6d3 Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Fri, 1 May 2020 11:38:30 -0700 Subject: [PATCH] Less hardcoded values in profiling script --- selfdrive/car/car_helpers.py | 7 ++++--- selfdrive/test/profiling/controlsd.py | 29 ++++++++++++++++++++------- selfdrive/test/profiling/lib.py | 7 +++---- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/selfdrive/car/car_helpers.py b/selfdrive/car/car_helpers.py index 5ffe043734..9c11feb6b2 100644 --- a/selfdrive/car/car_helpers.py +++ b/selfdrive/car/car_helpers.py @@ -71,7 +71,9 @@ def only_toyota_left(candidate_cars): # **** for use live only **** def fingerprint(logcan, sendcan, has_relay): - if has_relay: + fixed_fingerprint = os.environ.get('FINGERPRINT', "") + + if has_relay and not fixed_fingerprint: # Vin query only reliably works thorugh OBDII bus = 1 @@ -146,8 +148,7 @@ def fingerprint(logcan, sendcan, has_relay): car_fingerprint = list(fw_candidates)[0] source = car.CarParams.FingerprintSource.fw - fixed_fingerprint = os.environ.get('FINGERPRINT', "") - if len(fixed_fingerprint): + if fixed_fingerprint: car_fingerprint = fixed_fingerprint source = car.CarParams.FingerprintSource.fixed diff --git a/selfdrive/test/profiling/controlsd.py b/selfdrive/test/profiling/controlsd.py index 3048a497f5..02acf38ec0 100755 --- a/selfdrive/test/profiling/controlsd.py +++ b/selfdrive/test/profiling/controlsd.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +import os import time import cProfile import pprofile @@ -8,25 +9,39 @@ import pyprof2calltree from tools.lib.logreader import LogReader from selfdrive.controls.controlsd import controlsd_thread from selfdrive.test.profiling.lib import SubMaster, PubMaster, SubSocket, ReplayDone +from selfdrive.test.process_replay.process_replay import CONFIGS BASE_URL = "https://commadataci.blob.core.windows.net/openpilotci/" -SEGMENT = "99c94dc769b5d96e|2019-08-03--14-19-59/2" +CARS = { + 'toyota': ("77611a1fac303767|2020-02-29--13-29-33/3", "TOYOTA COROLLA TSS2 2019"), + 'honda': ("99c94dc769b5d96e|2019-08-03--14-19-59/2", "HONDA CIVIC 2016 TOURING"), +} -def get_inputs(msgs): - sm = SubMaster(msgs, 'can', ['thermal', 'health', 'liveCalibration', 'dMonitoringState', 'plan', 'pathPlan', 'model']) - pm = PubMaster(['sendcan', 'controlsState', 'carState', 'carControl', 'carEvents', 'carParams']) + +def get_inputs(msgs, process): + for config in CONFIGS: + if config.proc_name == process: + sub_socks = list(config.pub_sub.keys()) + trigger = sub_socks[0] + break + + sm = SubMaster(msgs, trigger, sub_socks) + pm = PubMaster() can_sock = SubSocket(msgs, 'can') return sm, pm, can_sock if __name__ == "__main__": - segment = SEGMENT.replace('|', '/') + segment, fingerprint = CARS['toyota'] + segment = segment.replace('|', '/') rlog_url = f"{BASE_URL}{segment}/rlog.bz2" msgs = list(LogReader(rlog_url)) + os.environ['FINGERPRINT'] = fingerprint + # Statistical - sm, pm, can_sock = get_inputs(msgs) + sm, pm, can_sock = get_inputs(msgs, 'controlsd') with pprofile.StatisticalProfile()(period=0.00001) as pr: try: controlsd_thread(sm, pm, can_sock) @@ -35,7 +50,7 @@ if __name__ == "__main__": pr.dump_stats('cachegrind.out.controlsd_statistical') # Deterministic - sm, pm, can_sock = get_inputs(msgs) + sm, pm, can_sock = get_inputs(msgs, 'controlsd') with cProfile.Profile() as pr: try: controlsd_thread(sm, pm, can_sock) diff --git a/selfdrive/test/profiling/lib.py b/selfdrive/test/profiling/lib.py index 2112632ed8..a0cdd8bcf5 100644 --- a/selfdrive/test/profiling/lib.py +++ b/selfdrive/test/profiling/lib.py @@ -1,3 +1,4 @@ +from collections import defaultdict import cereal.messaging as messaging import capnp @@ -98,10 +99,8 @@ class SubMaster(): class PubMaster(): - def __init__(self, services): - self.sock = {} - for s in services: - self.sock[s] = PubSocket() + def __init__(self): + self.sock = defaultdict(PubSocket) def send(self, s, dat): pass