From 2a1c74c5f5925e9c23bdf3fed9c03b32c428f6ae Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Tue, 21 Feb 2012 15:01:45 -0800 Subject: [PATCH] Move duration calculation to an internal task This excludes all generic start up costs, like waiting for locks, rebooting into a new kernel, etc. --- teuthology/run.py | 8 +------- teuthology/task/internal.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/teuthology/run.py b/teuthology/run.py index 815e73d44459c..ca31c79606586 100644 --- a/teuthology/run.py +++ b/teuthology/run.py @@ -69,7 +69,6 @@ def main(): from gevent import monkey; monkey.patch_all() from .orchestra import monkey; monkey.patch_all() - import time import logging log = logging.getLogger(__name__) @@ -141,20 +140,15 @@ def main(): {'internal.archive': None}, {'internal.coredump': None}, {'internal.syslog': None}, + {'internal.timer': None}, ]) ctx.config['tasks'][:0] = init_tasks - start_time = time.time() - from teuthology.run_tasks import run_tasks try: run_tasks(tasks=ctx.config['tasks'], ctx=ctx) finally: - end_time = time.time() - duration = end_time - start_time - ctx.summary['duration'] = duration - log.info("Duration was %f seconds" % duration) if not ctx.summary.get('success') and ctx.config.get('nuke-on-error'): from teuthology.parallel import parallel with parallel() as p: diff --git a/teuthology/task/internal.py b/teuthology/task/internal.py index e376066cb7406..12ec183386117 100644 --- a/teuthology/task/internal.py +++ b/teuthology/task/internal.py @@ -120,6 +120,17 @@ def check_lock(ctx, config): owner=ctx.owner, ) +@contextlib.contextmanager +def timer(ctx, config): + log.info('Starting timer...') + start = time.time() + try: + yield + finally: + duration = time.time() - start + log.info('Duration was %f seconds', duration) + ctx.summary['duration'] = duration + def connect(ctx, config): log.info('Opening connections...') from ..orchestra import connection, remote -- 2.39.5