From b3e7d94303e505917e0079f559cdd0319cd0ecbf Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Thu, 30 Apr 2020 17:39:37 -0700 Subject: [PATCH] run both deterministic and statistical profiler --- Pipfile | 1 + Pipfile.lock | 9 ++++++++- selfdrive/test/profiling/.gitignore | 1 + selfdrive/test/profiling/controlsd.py | 19 +++++++++++++++---- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Pipfile b/Pipfile index 1d150735bb..716922573e 100644 --- a/Pipfile +++ b/Pipfile @@ -70,6 +70,7 @@ aiohttp = "*" lru-dict = "*" scikit-image = "*" pygame = "==2.0.0.dev6" +pprofile = "*" pyprof2calltree = "*" [packages] diff --git a/Pipfile.lock b/Pipfile.lock index 031232be96..aae82b495c 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "d0ad31cf2a829d14b99ac88767488f0c5245a73297466c799102422eaa12eaa2" + "sha256": "bffeedc179051a29c8e5153cf2e72503c8ead081816c47aec7cece0c73cbcb31" }, "pipfile-spec": 6, "requires": { @@ -1968,6 +1968,13 @@ ], "version": "==1.7.0" }, + "pprofile": { + "hashes": [ + "sha256:2036522d201188641ab6766b3fea105ddeb72d3b752a7d6da695be7e7ba21656" + ], + "index": "pypi", + "version": "==2.0.4" + }, "prometheus-client": { "hashes": [ "sha256:71cd24a2b3eb335cb800c7159f423df1bd4dcd5171b234be15e3f31ec9f622da" diff --git a/selfdrive/test/profiling/.gitignore b/selfdrive/test/profiling/.gitignore index 8ef289b2dd..76acac7f93 100644 --- a/selfdrive/test/profiling/.gitignore +++ b/selfdrive/test/profiling/.gitignore @@ -1 +1,2 @@ cachegrind.out.* +*.prof diff --git a/selfdrive/test/profiling/controlsd.py b/selfdrive/test/profiling/controlsd.py index 062b7c0dd1..19e4701337 100755 --- a/selfdrive/test/profiling/controlsd.py +++ b/selfdrive/test/profiling/controlsd.py @@ -1,14 +1,13 @@ #!/usr/bin/env python3 import cProfile - +import pprofile 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 - BASE_URL = "https://commadataci.blob.core.windows.net/openpilotci/" SEGMENT = "99c94dc769b5d96e|2019-08-03--14-19-59/2" @@ -22,10 +21,22 @@ if __name__ == "__main__": sm = SubMaster(msgs, 'can', ['thermal', 'health', 'liveCalibration', 'dMonitoringState', 'plan', 'pathPlan', 'model']) can_sock = SubSocket(msgs, 'can') - with cProfile.Profile() as pr: + # Statistical + with pprofile.StatisticalProfile()(period=0.00001) as pr: try: controlsd_thread(sm, pm, can_sock) except ReplayDone: pass + pr.dump_stats('cachegrind.out.controlsd_statistical') + + # Deterministic + pm = PubMaster(['sendcan', 'controlsState', 'carState', 'carControl', 'carEvents', 'carParams']) + sm = SubMaster(msgs, 'can', ['thermal', 'health', 'liveCalibration', 'dMonitoringState', 'plan', 'pathPlan', 'model']) + can_sock = SubSocket(msgs, 'can') - pyprof2calltree.convert(pr.getstats(), 'cachegrind.out.controlsd') + with cProfile.Profile() as pr: + try: + controlsd_thread(sm, pm, can_sock) + except ReplayDone: + pass + pyprof2calltree.convert(pr.getstats(), 'cachegrind.out.controlsd_deterministic')