Exemplo n.º 1
0
    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()
Exemplo n.º 2
0
    def _dump(self):
        """
        Dumps the profiling stats.
        Also manages clearing stats if clearing each interval.

        """
        # If clearing each interval, stop profiler
        if self._config.clear_each_interval:
            profiler.stop()
            self._ended = utils.utc_seconds()

        # Dump the stats
        stats = profiler.get_func_stats()
        ctx = ProfilingContext(
            started=self._started, ended=utils.utc_seconds(),
            topic=self._topic
        )
        for o in self._outputs:
            try:
                o.write(ctx, stats)
            except Exception:
                # @TODO - Possibly do something with logging
                pass

        # If clearing each interval, clear stats and restart profiler
        if self._config.clear_each_interval:
            profiler.clear_stats()
            profiler.start()
            self.started = utils.utc_seconds()