From 551285fa35ccd0836513e9cf64ee8d3372e5e3f4 Mon Sep 17 00:00:00 2001 From: Gavin Mak Date: Thu, 4 May 2023 04:48:43 +0000 Subject: sync: Show elapsed time for the longest syncing project "Last synced: X" is printed only after a project finishes syncing. Replace that with a message that shows the longest actively syncing project. Bug: https://crbug.com/gerrit/11293 Change-Id: I84c7873539d84999772cd554f426b44921521e85 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/372674 Reviewed-by: Josip Sokcevic Commit-Queue: Gavin Mak Reviewed-by: Joanna Wang Tested-by: Gavin Mak --- subcmds/sync.py | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'subcmds/sync.py') diff --git a/subcmds/sync.py b/subcmds/sync.py index 8f73d27f..da9918b9 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -66,7 +66,7 @@ from command import ( from error import RepoChangedException, GitError import platform_utils from project import SyncBuffer -from progress import Progress +from progress import Progress, elapsed_str from repo_trace import Trace import ssh from wrapper import Wrapper @@ -596,7 +596,7 @@ later is required to fix a server side protocol bug. The projects we're given share the same underlying git object store, so we have to fetch them in serial. - Delegates most of the work to _FetchHelper. + Delegates most of the work to _FetchOne. Args: opt: Program options returned from optparse. See _Options(). @@ -615,6 +615,8 @@ later is required to fix a server side protocol bug. Whether the fetch was successful. """ start = time.time() + k = f"{project.name} @ {project.relpath}" + self._sync_dict[k] = start success = False remote_fetched = False buf = io.StringIO() @@ -660,15 +662,31 @@ later is required to fix a server side protocol bug. % (project.name, type(e).__name__, str(e)), file=sys.stderr, ) + del self._sync_dict[k] raise finish = time.time() + del self._sync_dict[k] return _FetchOneResult(success, project, start, finish, remote_fetched) @classmethod def _FetchInitChild(cls, ssh_proxy): cls.ssh_proxy = ssh_proxy + def _GetLongestSyncMessage(self): + if len(self._sync_dict) == 0: + return None + + earliest_time = float("inf") + earliest_proj = None + for project, t in self._sync_dict.items(): + if t < earliest_time: + earliest_time = t + earliest_proj = project + + elapsed = time.time() - earliest_time + return f"{elapsed_str(elapsed)} {earliest_proj}" + def _Fetch(self, projects, opt, err_event, ssh_proxy): ret = True @@ -681,8 +699,22 @@ later is required to fix a server side protocol bug. delay=False, quiet=opt.quiet, show_elapsed=True, + elide=True, ) + self._sync_dict = multiprocessing.Manager().dict() + sync_event = _threading.Event() + + def _MonitorSyncLoop(): + while True: + pm.update(inc=0, msg=self._GetLongestSyncMessage()) + if sync_event.wait(timeout=1): + return + + sync_progress_thread = _threading.Thread(target=_MonitorSyncLoop) + sync_progress_thread.daemon = True + sync_progress_thread.start() + objdir_project_map = dict() for project in projects: objdir_project_map.setdefault(project.objdir, []).append(project) @@ -712,7 +744,7 @@ later is required to fix a server side protocol bug. ret = False else: fetched.add(project.gitdir) - pm.update(msg=f"Last synced: {project.name}") + pm.update() if not ret and opt.fail_fast: break return ret @@ -764,6 +796,7 @@ later is required to fix a server side protocol bug. # crash. del Sync.ssh_proxy + sync_event.set() pm.end() self._fetch_times.Save() -- cgit v1.2.3-54-g00ecf