diff --git a/gnes/client/cli.py b/gnes/client/cli.py index 7546686a..1f7e8231 100644 --- a/gnes/client/cli.py +++ b/gnes/client/cli.py @@ -85,29 +85,30 @@ def __init__(self, bar_len: int = 20, task_name: str = ''): def update(self): self.num_bars += 1 - if (self.num_bars + 1) % self.bar_len == 0: - sys.stdout.write('\n') + sys.stdout.write('\r') elapsed = time.perf_counter() - self.start_time elapsed_str = colored('elapsed', 'yellow') speed_str = colored('speed', 'yellow') + num_bars = self.num_bars % self.bar_len + num_bars = self.bar_len if not num_bars and self.num_bars else max(num_bars, 1) sys.stdout.write( '{:>10} [{:<{}}] {:>8}: {:3.1f}s {:>8}: {:3.1f} batch/s'.format( colored(self.task_name, 'cyan'), - colored('=' * int(self.num_bars % self.bar_len), 'green'), + colored('=' * num_bars, 'green'), self.bar_len + 9, elapsed_str, elapsed, speed_str, self.num_bars / elapsed, )) - + if num_bars == self.bar_len: + sys.stdout.write('\n') sys.stdout.flush() - sys.stdout.write('\r') def __enter__(self): self.start_time = time.perf_counter() - self.num_bars = 0 + self.num_bars = -1 self.update() return self diff --git a/gnes/helper.py b/gnes/helper.py index d4df0a67..450e32e5 100644 --- a/gnes/helper.py +++ b/gnes/helper.py @@ -586,14 +586,14 @@ def _path_import(absolute_path): return module, spec -def make_route_table(routes, exclude_frontend: bool = False, jitter: float = 1e-8): +def make_route_table(routes, include_frontend: bool = False, jitter: float = 1e-8): route_time = [] - if exclude_frontend: + if include_frontend: total_duration = get_duration(routes[0].start_time, routes[0].end_time) + jitter else: total_duration = get_duration(routes[0].start_time, routes[-1].end_time) + jitter sum_duration = 0 - for k in routes[(1 if exclude_frontend else 0):]: + for k in routes: d = get_duration(k.start_time, k.end_time) route_time.append((k.service, d)) sum_duration += d diff --git a/gnes/service/frontend.py b/gnes/service/frontend.py index 1aa3a5f8..d17c956c 100644 --- a/gnes/service/frontend.py +++ b/gnes/service/frontend.py @@ -80,7 +80,7 @@ def remove_envelope(self, m: 'gnes_pb2.Message'): m.envelope.routes[0].end_time.GetCurrentTime() if self.args.route_table: self.logger.info('route: %s' % router2str(m)) - self.logger.info('route table: \n%s' % make_route_table(m.envelope.routes, exclude_frontend=True)) + self.logger.info('route table: \n%s' % make_route_table(m.envelope.routes, include_frontend=True)) if self.args.dump_route: self.args.dump_route.write(MessageToJson(m.envelope, indent=0).replace('\n', '') + '\n') self.args.dump_route.flush() diff --git a/tests/test_progressbar.py b/tests/test_progressbar.py index 53177f98..bade83c7 100644 --- a/tests/test_progressbar.py +++ b/tests/test_progressbar.py @@ -13,10 +13,11 @@ def test_progressbar5(self): with ProgressBar(task_name='test', bar_len=self.bar_len) as pb: for j in range(5 * self.bar_len): pb.update() + time.sleep(.05) def test_progressbar1(self): # should be single line with ProgressBar(task_name='test', bar_len=self.bar_len) as pb: for j in range(self.bar_len): pb.update() - time.sleep(.1) + time.sleep(.05)