예제 #1
0
 def restart_timer(self):
     # TODO 重启定时器,返回时间差
     elapsed_time = self.stop_timer()  # TODO 重启之前先暂停
     self._time_started = time.time()
     self._started = default_timer()
     self._stopped = None
     return elapsed_time
예제 #2
0
 def elapsed_time(self):
     if self._stopped is not None:
         return self._stopped - self._started
     return default_timer() - self._started
예제 #3
0
 def restart_timer(self):
     elapsed_time = self.stop_timer()
     self._time_started = time.time()
     self._started = default_timer()
     self._stopped = None
     return elapsed_time
예제 #4
0
 def stop_timer(self):
     if self._stopped is None:
         self._stopped = default_timer()
     return self._stopped - self._started
예제 #5
0
 def __init__(self):
     self._time_started = time.time()
     self._started = default_timer()
     self._stopped = None
예제 #6
0
    # Python 3.3 and later implements PEP 418. Use the
    # performance counter it provides which is monotonically
    # increasing.

    default_timer = time.perf_counter
    timer_implementation = 'time.perf_counter()'

except AttributeError:
    try:
        # Next try our own bundled back port of the monotonic()
        # function. Python 3.3 does on Windows use a different
        # clock for the performance counter, but the standard
        # monotonic clock should suit our requirements okay.

        from newrelic.common._monotonic import monotonic as default_timer
        default_timer()
        timer_implementation = '_monotonic.monotonic()'

    except (ImportError, NotImplementedError, OSError):
        # If neither of the above, fallback to using the default
        # timer from the timeit module. This will use the best
        # resolution clock available on a particular platform,
        # albeit that it isn't monotonically increasing.

        import timeit
        default_timer = timeit.default_timer
        timer_implementation = 'timeit.default_timer()'

# A timer class which deals with remembering the start time based on
# wall clock time and duration based on a monotonic clock where
# available.
예제 #7
0
 def elapsed_time(self):
     # TODO 从过去的固定时间点起,经过的真实时间
     if self._stopped is not None:
         return self._stopped - self._started
     return default_timer() - self._started
예제 #8
0
 def stop_timer(self):
     # TODO 暂停计时器,返回时间差
     if self._stopped is None:
         self._stopped = default_timer()
     return self._stopped - self._started