]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Add timer.py and display summary info in run.py.
authorWarren Usui <wusui@ubuntu.(none)>
Thu, 21 Feb 2013 22:51:54 +0000 (14:51 -0800)
committerWarren Usui <warren.usui@inktank.com>
Tue, 26 Feb 2013 00:02:08 +0000 (16:02 -0800)
Signed-off-by: Warren Usui <warren.usui@inktank.com>
teuthology/run.py
teuthology/task/timer.py [new file with mode: 0644]

index ef9947f4992684ab0ef68e77590a2a97b0869a68..f1955bea2c98f4a5131750711ed74ad015523d2e 100644 (file)
@@ -1,6 +1,8 @@
 import argparse
 import os
 import yaml
+import StringIO
+import contextlib
 
 def config_file(string):
     config = {}
@@ -183,7 +185,10 @@ def main():
         if ctx.archive is not None:
             with file(os.path.join(ctx.archive, 'summary.yaml'), 'w') as f:
                 yaml.safe_dump(ctx.summary, f, default_flow_style=False)
-
+        with contextlib.closing(StringIO.StringIO()) as f:
+            yaml.safe_dump(ctx.summary, f)
+            log.info('Summary data:\n%s' % f.getvalue())
+            
     if ctx.summary.get('success', True):
         log.info('pass')
     else:
diff --git a/teuthology/task/timer.py b/teuthology/task/timer.py
new file mode 100644 (file)
index 0000000..f85ae8c
--- /dev/null
@@ -0,0 +1,50 @@
+import logging
+import contextlib
+import datetime
+
+from ..orchestra import run
+
+log = logging.getLogger(__name__)
+
+@contextlib.contextmanager
+def task(ctx, config):
+    """
+    Timer
+
+    Measure the time that this set of tasks takes and save that value in the summary file.
+    Config is a description of what we are timing.
+
+    example:
+
+    tasks:
+    - ceph:
+    - foo:
+    - timer: "fsx run"
+    - fsx:
+
+    """
+    start = datetime.datetime.now()
+    log.debug("got here in timer")
+    try:
+        yield
+    finally:
+        nowinfo = datetime.datetime.now()
+        elapsed = nowinfo - start
+        datesaved = nowinfo.isoformat(' ')
+        hourz, remainder = divmod(elapsed.seconds, 3600)
+        minutez, secondz = divmod(remainder, 60)
+        elapsedtime = "%02d:%02d:%02d.%06d" % (hourz,minutez,secondz, elapsed.microseconds)
+        dateinfo = (datesaved, elapsedtime)
+        if not 'timer' in ctx.summary:
+            ctx.summary['timer'] = {config : [dateinfo]}
+        else:
+            if config in ctx.summary['timer']:
+                ctx.summary['timer'][config].append(dateinfo)
+            else:
+                ctx.summary['timer'][config] = [dateinfo]
+        log.info('Elapsed time for %s -- %s' % (config,elapsedtime))
+
+
+
+
+        
\ No newline at end of file