def work(self): """ Long running loop that periodically dumps the stats. """ if profiler.is_running(): raise NovaServiceProfilingException("Profiling already enabled.") # Set clock type self.set_clock_type() # Start profiler profiler.start() self._started = utils.utc_seconds() last_dumped = time.time() while not self.should_stop(): # Sleep for less than whole interval for faster interrupts sleep(self._sub_interval) checked = time.time() # Only take action if we have exceeded the interval period if (checked - last_dumped) > self._config.interval: self._dump() # Update last dumped last_dumped = checked # Finally stop the profiler profiler.stop() self._ended = utils.utc_seconds()