fix startup spinner for non-C2 (#19536)

* limit build progress

* cleanup

* types

* comment
old-commit-hash: 71d317872a
commatwo_master
Adeeb Shihadeh 5 years ago committed by GitHub
parent 2fa44ccbbe
commit eb0fd3eaac
  1. 4
      common/spinner.py
  2. 36
      selfdrive/manager.py

@ -16,7 +16,7 @@ class Spinner():
def __enter__(self): def __enter__(self):
return self return self
def update(self, spinner_text): def update(self, spinner_text: str):
if self.spinner_proc is not None: if self.spinner_proc is not None:
self.spinner_proc.stdin.write(spinner_text.encode('utf8') + b"\n") self.spinner_proc.stdin.write(spinner_text.encode('utf8') + b"\n")
try: try:
@ -24,7 +24,7 @@ class Spinner():
except BrokenPipeError: except BrokenPipeError:
pass pass
def update_progress(self, cur, total): def update_progress(self, cur: int, total: int):
self.update(str(int(100 * cur / total))) self.update(str(int(100 * cur / total)))
def close(self): def close(self):

@ -18,13 +18,17 @@ from typing import Dict, List
from common.basedir import BASEDIR from common.basedir import BASEDIR
from common.spinner import Spinner from common.spinner import Spinner
from common.text_window import TextWindow from common.text_window import TextWindow
import selfdrive.crash as crash
from selfdrive.hardware import HARDWARE, EON, PC from selfdrive.hardware import HARDWARE, EON, PC
from selfdrive.hardware.eon.apk import update_apks, pm_apply_packages, start_offroad
from selfdrive.swaglog import cloudlog, add_logentries_handler from selfdrive.swaglog import cloudlog, add_logentries_handler
from selfdrive.version import version, dirty
os.environ['BASEDIR'] = BASEDIR os.environ['BASEDIR'] = BASEDIR
sys.path.append(os.path.join(BASEDIR, "pyextra")) sys.path.append(os.path.join(BASEDIR, "pyextra"))
TOTAL_SCONS_NODES = 1040 TOTAL_SCONS_NODES = 1040
MAX_BUILD_PROGRESS = 70
WEBCAM = os.getenv("WEBCAM") is not None WEBCAM = os.getenv("WEBCAM") is not None
PREBUILT = os.path.exists(os.path.join(BASEDIR, 'prebuilt')) PREBUILT = os.path.exists(os.path.join(BASEDIR, 'prebuilt'))
@ -61,26 +65,24 @@ def unblock_stdout():
exit_status = os.wait()[1] >> 8 exit_status = os.wait()[1] >> 8
os._exit(exit_status) os._exit(exit_status)
if __name__ == "__main__": if __name__ == "__main__":
unblock_stdout() unblock_stdout()
# Run scons # Start spinner
spinner = Spinner() spinner = Spinner()
spinner.update("0") spinner.update_progress(0, 100)
if __name__ != "__main__": if __name__ != "__main__":
spinner.close() spinner.close()
def build(): def build():
for retry in [True, False]: env = os.environ.copy()
# run scons env['SCONS_PROGRESS'] = "1"
env = os.environ.copy() env['SCONS_CACHE'] = "1"
env['SCONS_PROGRESS'] = "1" nproc = os.cpu_count()
env['SCONS_CACHE'] = "1" j_flag = "" if nproc is None else f"-j{nproc - 1}"
nproc = os.cpu_count() for retry in [True, False]:
j_flag = "" if nproc is None else f"-j{nproc - 1}"
scons = subprocess.Popen(["scons", j_flag], cwd=BASEDIR, env=env, stderr=subprocess.PIPE) scons = subprocess.Popen(["scons", j_flag], cwd=BASEDIR, env=env, stderr=subprocess.PIPE)
compile_output = [] compile_output = []
@ -88,7 +90,7 @@ def build():
# Read progress from stderr and update spinner # Read progress from stderr and update spinner
while scons.poll() is None: while scons.poll() is None:
try: try:
line = scons.stderr.readline() # type: ignore line = scons.stderr.readline()
if line is None: if line is None:
continue continue
line = line.rstrip() line = line.rstrip()
@ -96,7 +98,7 @@ def build():
prefix = b'progress: ' prefix = b'progress: '
if line.startswith(prefix): if line.startswith(prefix):
i = int(line[len(prefix):]) i = int(line[len(prefix):])
spinner.update("%d" % (70.0 * (i / TOTAL_SCONS_NODES))) spinner.update_progress(MAX_BUILD_PROGRESS * min(1., i / TOTAL_SCONS_NODES), 100.)
elif len(line): elif len(line):
compile_output.append(line) compile_output.append(line)
print(line.decode('utf8', 'replace')) print(line.decode('utf8', 'replace'))
@ -105,7 +107,7 @@ def build():
if scons.returncode != 0: if scons.returncode != 0:
# Read remaining output # Read remaining output
r = scons.stderr.read().split(b'\n') # type: ignore r = scons.stderr.read().split(b'\n')
compile_output += r compile_output += r
if retry: if retry:
@ -143,12 +145,9 @@ if __name__ == "__main__" and not PREBUILT:
import cereal.messaging as messaging import cereal.messaging as messaging
from common.params import Params from common.params import Params
import selfdrive.crash as crash
from selfdrive.registration import register from selfdrive.registration import register
from selfdrive.version import version, dirty
from selfdrive.loggerd.config import ROOT from selfdrive.loggerd.config import ROOT
from selfdrive.launcher import launcher from selfdrive.launcher import launcher
from selfdrive.hardware.eon.apk import update_apks, pm_apply_packages, start_offroad
# comment out anything you don't want to run # comment out anything you don't want to run
@ -504,12 +503,11 @@ def manager_prepare():
# build all processes # build all processes
os.chdir(os.path.dirname(os.path.abspath(__file__))) os.chdir(os.path.dirname(os.path.abspath(__file__)))
# Spinner has to start from 70 here total = 100.0 - (0 if PREBUILT else MAX_BUILD_PROGRESS)
total = 100.0 if PREBUILT else 30.0
for i, p in enumerate(managed_processes): for i, p in enumerate(managed_processes):
perc = (100.0 - total) + total * (i + 1) / len(managed_processes) perc = (100.0 - total) + total * (i + 1) / len(managed_processes)
spinner.update(str(int(perc))) spinner.update_progress(perc, 100.)
prepare_managed_process(p) prepare_managed_process(p)
def main(): def main():

Loading…
Cancel
Save