mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-08 23:22:04 +08:00
30350f4207
* initial * start to support nav stack in settings panels + fix some navwidget bugs * add deprecation warning and move more to new nav stack * fix overriding NavWidget enabled and do developer panel * fix interactive timeout and do main * more device, not done yet * minor network fixes * dcam dialog * start onboarding * fix onboarding * do mici setup * remove now useless CUSTOM_SOFTWARE * support big ui with old modal overlay * reset can be old modal overlay, but updater needs new since it uses wifiui * flip name truthiness to inspire excitement * all *should* work, but will do pass later * clean up main * clean up settiings * clean up dialog and developer * cleanup mici setup some * rm one more * fix keyboard * revert * might as well but clarify * fix networkinfopage buttons * lint * nice clean up from cursor * animate background fade with position * fix device overlays * cursor fix pt1 cursor fix pt2 * rm print * capital * temp fix from cursor for onboarding not freeing space after reviewing training guide * fix home screen scroller snap not resetting * stash * nice gradient on top * 40 * 20 * no gradient * return unused returns and always show regulatory btn * nice! * clean up * new_modal is always true! * more clean up * clean up * big only renders top 1 * fixup setup and updater * stash * Revert "stash" This reverts commit 3cfb226ccb51869ed1f7d630b5fdd6725ad094d5. * fix mici keys coming in from top * clean up * fix mici dialogs like tici, pop first incase call back pushes * clever way but not not * Revert "clever way but not not" This reverts commit f69d106df61262f049df20cc1a9064ca1e6feeb7. * more setup * mici keyboard: fix not disabling below * cmt * fix wifi callbacks not running in rare case * clean up network * clean up network * clean up dialog * pairing * rm * todo * fix replay * they push themselkves! * clean up ui_state * clean up application * clean up * stash * Revert "stash" This reverts commit 07d3f5f26c99ef891086b6fe03095d53a62b8631. * typing * lint
109 lines
3.7 KiB
Python
Executable File
109 lines
3.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import os
|
|
import time
|
|
import cProfile
|
|
import pyray as rl
|
|
import numpy as np
|
|
|
|
from msgq.visionipc import VisionIpcServer, VisionStreamType
|
|
from openpilot.selfdrive.ui.ui_state import ui_state
|
|
from openpilot.selfdrive.ui.mici.layouts.main import MiciMainLayout
|
|
from openpilot.system.ui.lib.application import gui_app
|
|
from openpilot.tools.lib.logreader import LogReader
|
|
|
|
FPS = 60
|
|
|
|
|
|
def chunk_messages_by_time(messages):
|
|
dt_ns = 1e9 / FPS
|
|
chunks = []
|
|
current_services = {}
|
|
next_time = messages[0].logMonoTime + dt_ns if messages else 0
|
|
|
|
for msg in messages:
|
|
if msg.logMonoTime >= next_time:
|
|
chunks.append(current_services)
|
|
current_services = {}
|
|
next_time += dt_ns * ((msg.logMonoTime - next_time) // dt_ns + 1)
|
|
current_services[msg.which()] = msg
|
|
|
|
if current_services:
|
|
chunks.append(current_services)
|
|
return chunks
|
|
|
|
|
|
def patch_submaster(message_chunks):
|
|
def mock_update(timeout=None):
|
|
sm = ui_state.sm
|
|
sm.updated = dict.fromkeys(sm.services, False)
|
|
current_time = time.monotonic()
|
|
for service, msg in message_chunks[sm.frame].items():
|
|
if service in sm.data:
|
|
sm.seen[service] = True
|
|
sm.updated[service] = True
|
|
|
|
msg_builder = msg.as_builder()
|
|
sm.data[service] = getattr(msg_builder, service)
|
|
sm.logMonoTime[service] = msg.logMonoTime
|
|
sm.recv_time[service] = current_time
|
|
sm.recv_frame[service] = sm.frame
|
|
sm.valid[service] = True
|
|
sm.frame += 1
|
|
ui_state.sm.update = mock_update
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import argparse
|
|
parser = argparse.ArgumentParser(description='Profile openpilot UI rendering and state updates')
|
|
parser.add_argument('route', type=str, nargs='?', default="302bab07c1511180/00000006--0b9a7005f1/3",
|
|
help='Route to use for profiling')
|
|
parser.add_argument('--loop', type=int, default=1,
|
|
help='Number of times to loop the log (default: 1)')
|
|
parser.add_argument('--output', type=str, default='cachegrind.out.ui',
|
|
help='Output file prefix (default: cachegrind.out.ui)')
|
|
parser.add_argument('--max-seconds', type=float, default=None,
|
|
help='Maximum seconds of messages to process (default: all)')
|
|
parser.add_argument('--headless', action='store_true',
|
|
help='Run in headless mode without GPU (for CI/testing)')
|
|
args = parser.parse_args()
|
|
|
|
print(f"Loading log from {args.route}...")
|
|
lr = LogReader(args.route, sort_by_time=True)
|
|
messages = list(lr) * args.loop
|
|
|
|
print("Chunking messages...")
|
|
message_chunks = chunk_messages_by_time(messages)
|
|
if args.max_seconds:
|
|
message_chunks = message_chunks[:int(args.max_seconds * FPS)]
|
|
|
|
print("Initializing UI with GPU rendering...")
|
|
|
|
if args.headless:
|
|
os.environ['SDL_VIDEODRIVER'] = 'dummy'
|
|
|
|
gui_app.init_window("UI Profiling", fps=600)
|
|
main_layout = MiciMainLayout()
|
|
|
|
print("Running...")
|
|
patch_submaster(message_chunks)
|
|
|
|
W, H = 2048, 1216
|
|
vipc = VisionIpcServer("camerad")
|
|
vipc.create_buffers(VisionStreamType.VISION_STREAM_ROAD, 5, W, H)
|
|
vipc.start_listener()
|
|
yuv_buffer_size = W * H + (W // 2) * (H // 2) * 2
|
|
yuv_data = np.random.randint(0, 256, yuv_buffer_size, dtype=np.uint8).tobytes()
|
|
with cProfile.Profile() as pr:
|
|
for _ in gui_app.render():
|
|
if ui_state.sm.frame >= len(message_chunks):
|
|
break
|
|
if ui_state.sm.frame % 3 == 0:
|
|
eof = int((ui_state.sm.frame % 3) * 0.05 * 1e9)
|
|
vipc.send(VisionStreamType.VISION_STREAM_ROAD, yuv_data, ui_state.sm.frame % 3, eof, eof)
|
|
ui_state.update()
|
|
pr.dump_stats(f'{args.output}_deterministic.stats')
|
|
|
|
rl.close_window()
|
|
print("\nProfiling complete!")
|
|
print(f" run: python -m pstats {args.output}_deterministic.stats")
|