diff --git a/tools/python/jwutils/StopWatch.py b/tools/python/jwutils/StopWatch.py new file mode 100644 index 0000000..1e2f712 --- /dev/null +++ b/tools/python/jwutils/StopWatch.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- + +import datetime +from .log import * + +class StopWatch: # export + + def __init__(self, name=''): + self.__start = datetime.now() + self.__last = self.__start + self.name = name + + def reset(self): + self.__start = datetime.now() + + def logDelta(self, prio, *args, **kwargs): + now = datetime.now() + if args is not None: + msg = ' '.join(args) + else: + msg = '------------------ ' + caller = kwargs['caller'] if 'caller' in kwargs.keys() else get_caller_pos(1) + slog(prio, '{} {} {}'.format(self.name, str(now - self.__last), msg), caller=caller) + self.__last = now