diff options
| author | Mike Frysinger <vapier@google.com> | 2021-02-23 17:34:35 -0500 |
|---|---|---|
| committer | Mike Frysinger <vapier@google.com> | 2021-02-25 20:13:18 +0000 |
| commit | fbb95a43421eb925985223fffa3febc12e5dbe33 (patch) | |
| tree | 176c095911f3cbaf57b82f621fb8702b240c0579 | |
| parent | 4e05f650e0b314fa80ea5811c0abe4b71ea0758c (diff) | |
| download | git-repo-fbb95a43421eb925985223fffa3febc12e5dbe33.tar.gz | |
progress/sync: include active number of jobs
Provide a bit more info to users that things are actively running.
Bug: https://crbug.com/gerrit/11293
Change-Id: Ie8eeaa8804d1ca71cf5c78ad850fa2d17d26208c
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/297904
Reviewed-by: Michael Mortensen <mmortensen@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
| -rw-r--r-- | progress.py | 20 | ||||
| -rw-r--r-- | subcmds/sync.py | 27 |
2 files changed, 35 insertions, 12 deletions
diff --git a/progress.py b/progress.py index 3764b9e2..d19fc5b1 100644 --- a/progress.py +++ b/progress.py | |||
| @@ -34,6 +34,19 @@ class Progress(object): | |||
| 34 | self._show = False | 34 | self._show = False |
| 35 | self._units = units | 35 | self._units = units |
| 36 | self._print_newline = print_newline | 36 | self._print_newline = print_newline |
| 37 | # Only show the active jobs section if we run more than one in parallel. | ||
| 38 | self._show_jobs = False | ||
| 39 | self._active = 0 | ||
| 40 | |||
| 41 | def start(self, name): | ||
| 42 | self._active += 1 | ||
| 43 | if not self._show_jobs: | ||
| 44 | self._show_jobs = self._active > 1 | ||
| 45 | self.update(inc=0, msg='started ' + name) | ||
| 46 | |||
| 47 | def finish(self, name): | ||
| 48 | self.update(msg='finished ' + name) | ||
| 49 | self._active -= 1 | ||
| 37 | 50 | ||
| 38 | def update(self, inc=1, msg=''): | 51 | def update(self, inc=1, msg=''): |
| 39 | self._done += inc | 52 | self._done += inc |
| @@ -55,10 +68,15 @@ class Progress(object): | |||
| 55 | sys.stderr.flush() | 68 | sys.stderr.flush() |
| 56 | else: | 69 | else: |
| 57 | p = (100 * self._done) / self._total | 70 | p = (100 * self._done) / self._total |
| 58 | sys.stderr.write('%s\r%s: %3d%% (%d%s/%d%s)%s%s%s' % ( | 71 | if self._show_jobs: |
| 72 | jobs = '[%d job%s] ' % (self._active, 's' if self._active > 1 else '') | ||
| 73 | else: | ||
| 74 | jobs = '' | ||
| 75 | sys.stderr.write('%s\r%s: %2d%% %s(%d%s/%d%s)%s%s%s' % ( | ||
| 59 | CSI_ERASE_LINE, | 76 | CSI_ERASE_LINE, |
| 60 | self._title, | 77 | self._title, |
| 61 | p, | 78 | p, |
| 79 | jobs, | ||
| 62 | self._done, self._units, | 80 | self._done, self._units, |
| 63 | self._total, self._units, | 81 | self._total, self._units, |
| 64 | ' ' if msg else '', msg, | 82 | ' ' if msg else '', msg, |
diff --git a/subcmds/sync.py b/subcmds/sync.py index 0a3cde7d..b1b6a6ef 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
| @@ -354,6 +354,8 @@ later is required to fix a server side protocol bug. | |||
| 354 | # - We always make sure we unlock the lock if we locked it. | 354 | # - We always make sure we unlock the lock if we locked it. |
| 355 | start = time.time() | 355 | start = time.time() |
| 356 | success = False | 356 | success = False |
| 357 | with lock: | ||
| 358 | pm.start(project.name) | ||
| 357 | try: | 359 | try: |
| 358 | try: | 360 | try: |
| 359 | success = project.Sync_NetworkHalf( | 361 | success = project.Sync_NetworkHalf( |
| @@ -383,7 +385,6 @@ later is required to fix a server side protocol bug. | |||
| 383 | raise _FetchError() | 385 | raise _FetchError() |
| 384 | 386 | ||
| 385 | fetched.add(project.gitdir) | 387 | fetched.add(project.gitdir) |
| 386 | pm.update(msg=project.name) | ||
| 387 | except _FetchError: | 388 | except _FetchError: |
| 388 | pass | 389 | pass |
| 389 | except Exception as e: | 390 | except Exception as e: |
| @@ -392,8 +393,10 @@ later is required to fix a server side protocol bug. | |||
| 392 | err_event.set() | 393 | err_event.set() |
| 393 | raise | 394 | raise |
| 394 | finally: | 395 | finally: |
| 395 | if did_lock: | 396 | if not did_lock: |
| 396 | lock.release() | 397 | lock.acquire() |
| 398 | pm.finish(project.name) | ||
| 399 | lock.release() | ||
| 397 | finish = time.time() | 400 | finish = time.time() |
| 398 | self.event_log.AddSync(project, event_log.TASK_SYNC_NETWORK, | 401 | self.event_log.AddSync(project, event_log.TASK_SYNC_NETWORK, |
| 399 | start, finish, success) | 402 | start, finish, success) |
| @@ -403,7 +406,7 @@ later is required to fix a server side protocol bug. | |||
| 403 | def _Fetch(self, projects, opt, err_event): | 406 | def _Fetch(self, projects, opt, err_event): |
| 404 | fetched = set() | 407 | fetched = set() |
| 405 | lock = _threading.Lock() | 408 | lock = _threading.Lock() |
| 406 | pm = Progress('Fetching projects', len(projects)) | 409 | pm = Progress('Fetching', len(projects)) |
| 407 | 410 | ||
| 408 | objdir_project_map = dict() | 411 | objdir_project_map = dict() |
| 409 | for project in projects: | 412 | for project in projects: |
| @@ -493,6 +496,8 @@ later is required to fix a server side protocol bug. | |||
| 493 | syncbuf = SyncBuffer(self.manifest.manifestProject.config, | 496 | syncbuf = SyncBuffer(self.manifest.manifestProject.config, |
| 494 | detach_head=opt.detach_head) | 497 | detach_head=opt.detach_head) |
| 495 | success = False | 498 | success = False |
| 499 | with lock: | ||
| 500 | pm.start(project.name) | ||
| 496 | try: | 501 | try: |
| 497 | try: | 502 | try: |
| 498 | project.Sync_LocalHalf(syncbuf, force_sync=opt.force_sync) | 503 | project.Sync_LocalHalf(syncbuf, force_sync=opt.force_sync) |
| @@ -508,8 +513,6 @@ later is required to fix a server side protocol bug. | |||
| 508 | print('error: Cannot checkout %s' % (project.name), | 513 | print('error: Cannot checkout %s' % (project.name), |
| 509 | file=sys.stderr) | 514 | file=sys.stderr) |
| 510 | raise _CheckoutError() | 515 | raise _CheckoutError() |
| 511 | |||
| 512 | pm.update(msg=project.name) | ||
| 513 | except _CheckoutError: | 516 | except _CheckoutError: |
| 514 | pass | 517 | pass |
| 515 | except Exception as e: | 518 | except Exception as e: |
| @@ -519,10 +522,12 @@ later is required to fix a server side protocol bug. | |||
| 519 | err_event.set() | 522 | err_event.set() |
| 520 | raise | 523 | raise |
| 521 | finally: | 524 | finally: |
| 522 | if did_lock: | 525 | if not did_lock: |
| 523 | if not success: | 526 | lock.acquire() |
| 524 | err_results.append(project.relpath) | 527 | if not success: |
| 525 | lock.release() | 528 | err_results.append(project.relpath) |
| 529 | pm.finish(project.name) | ||
| 530 | lock.release() | ||
| 526 | finish = time.time() | 531 | finish = time.time() |
| 527 | self.event_log.AddSync(project, event_log.TASK_SYNC_LOCAL, | 532 | self.event_log.AddSync(project, event_log.TASK_SYNC_LOCAL, |
| 528 | start, finish, success) | 533 | start, finish, success) |
| @@ -553,7 +558,7 @@ later is required to fix a server side protocol bug. | |||
| 553 | syncjobs = 1 | 558 | syncjobs = 1 |
| 554 | 559 | ||
| 555 | lock = _threading.Lock() | 560 | lock = _threading.Lock() |
| 556 | pm = Progress('Checking out projects', len(all_projects)) | 561 | pm = Progress('Checking out', len(all_projects)) |
| 557 | 562 | ||
| 558 | threads = set() | 563 | threads = set() |
| 559 | sem = _threading.Semaphore(syncjobs) | 564 | sem = _threading.Semaphore(syncjobs) |
