diff options
author | Morgan Richomme <morgan.richomme@orange.com> | 2016-12-13 13:16:23 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2016-12-13 13:16:23 +0000 |
commit | 202b6065b9ef13534b40d55e9a7198e23e5c2f99 (patch) | |
tree | c67ca541b80a5edef60370c8f6beb4084f58205c /functest/utils | |
parent | 1ac822083026d42ebe5f1a96e4eb0d34eed613c8 (diff) | |
parent | 13a6297089972c74a0be6030c687d51c8efd2e3f (diff) |
Merge "Add timing decorator utility"
Diffstat (limited to 'functest/utils')
-rw-r--r-- | functest/utils/functest_utils.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/functest/utils/functest_utils.py b/functest/utils/functest_utils.py index 8f816cdf..b1e4d3cd 100644 --- a/functest/utils/functest_utils.py +++ b/functest/utils/functest_utils.py @@ -21,6 +21,9 @@ import requests import yaml from git import Repo +import time +import functools + import functest.utils.functest_logger as ft_logger logger = ft_logger.Logger("functest_utils").getLogger() @@ -431,3 +434,17 @@ def get_functest_yaml(): def print_separator(): logger.info("==============================================") + + +def timethis(func): + """Measure the time it takes for a function to complete""" + @functools.wraps(func) + def timed(*args, **kwargs): + ts = time.time() + result = func(*args, **kwargs) + te = time.time() + elapsed = '{0}'.format(te - ts) + logger.info('{f}(*{a}, **{kw}) took: {t} sec'.format( + f=func.__name__, a=args, kw=kwargs, t=elapsed)) + return result, elapsed + return timed |