]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Move duration calculation to an internal task
authorJosh Durgin <josh.durgin@dreamhost.com>
Tue, 21 Feb 2012 23:01:45 +0000 (15:01 -0800)
committerJosh Durgin <josh.durgin@dreamhost.com>
Tue, 21 Feb 2012 23:12:26 +0000 (15:12 -0800)
This excludes all generic start up costs, like waiting for locks,
rebooting into a new kernel, etc.

teuthology/run.py
teuthology/task/internal.py

index 815e73d44459cc99989ebdc5bf7dfc1a98cf5168..ca31c79606586c54b4a9c4799a31eae6ac50df6e 100644 (file)
@@ -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:
index e376066cb740670ecd17e60ab826e7225d9035c1..12ec183386117c359ca93d166b8dbb2dd28f4456 100644 (file)
@@ -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