Skip to content
Permalink
Browse files

fix(frontend): fix progressbar and route table

  • Loading branch information...
hanxiao committed Sep 24, 2019
1 parent 9a65e4f commit 84e67792b5b6e60b5833d49b8fe77c64dac479d4
Showing with 13 additions and 11 deletions.
  1. +7 −6 gnes/client/cli.py
  2. +3 −3 gnes/helper.py
  3. +1 −1 gnes/service/frontend.py
  4. +2 −1 tests/test_progressbar.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

@@ -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
@@ -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()
@@ -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)

0 comments on commit 84e6779

Please sign in to comment.
You can’t perform that action at this time.