Less hardcoded values in profiling script

pull/1447/head
Willem Melching 5 years ago
parent 4301c5efb5
commit 5d69e97281
  1. 7
      selfdrive/car/car_helpers.py
  2. 29
      selfdrive/test/profiling/controlsd.py
  3. 7
      selfdrive/test/profiling/lib.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

@ -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)

@ -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

Loading…
Cancel
Save