Example #1
0
    def stats_collection_start(self):
        self.monitor = ResourceMonitor(("[Job %s]" % self.name),
                                       JOB_MONITOR_TIME)

        self.start_time = time.time()

        if self.mean_time != -1:
            log.debug(
                "Starting job [%s] expecting an execution time of %.2f [low: %.2f, high: %.2f]"
                % (self.name, self.mean_time, self.low_time, self.high_time))
        else:
            log.debug("Starting job [%s]" % self.name)
Example #2
0
    def stats_collection_start(self):
        self.monitor = ResourceMonitor(("[Job %s]" % self.name), JOB_MONITOR_TIME)

        self.start_time = time.time()

        if self.mean_time != -1:
            log.time_debug("Starting job [%s] expecting an execution time of %.2f [low: %.2f, high: %.2f]" %
                      (self.name, self.mean_time, self.low_time, self.high_time))
        else:
            log.time_debug("Starting job [%s]" % self.name)
Example #3
0
class GLJob(task.LoopingCall):
    iterations = 0
    start_time = 0
    mean_time = -1
    low_time = -1
    high_time = -1
    name = "unnamed"

    monitor = None

    def __init__(self):
        task.LoopingCall.__init__(self, self._operation)

    def stats_collection_start(self):
        self.monitor = ResourceMonitor(("[Job %s]" % self.name), JOB_MONITOR_TIME)

        self.start_time = time.time()

        if self.mean_time != -1:
            log.time_debug("Starting job [%s] expecting an execution time of %.2f [low: %.2f, high: %.2f]" %
                      (self.name, self.mean_time, self.low_time, self.high_time))
        else:
            log.time_debug("Starting job [%s]" % self.name)

    def stats_collection_end(self):
        if self.monitor is not None:
            self.monitor.stop()
            self.monitor = None

        current_run_time = time.time() - self.start_time

        # discard empty cicles from stats
        if current_run_time > 0.00:
            self.mean_time = ((self.mean_time * self.iterations) + current_run_time) / (self.iterations + 1)

        if self.low_time == -1 or current_run_time < self.low_time:
            self.low_time = current_run_time

        if self.high_time == -1 or current_run_time > self.high_time:
            self.high_time = current_run_time

        log.time_debug("Ended job [%s] with an execution time of %.2f seconds" % (self.name, current_run_time))

        self.iterations += 1

        TimingStatsHandler.log_measured_timing("JOB", self.name, self.start_time, current_run_time)

    @defer.inlineCallbacks
    def _operation(self):
        try:
            self.stats_collection_start()

            yield self.operation()

            self.stats_collection_end()
        except Exception as e:
            log.err("Exception while performing scheduled operation %s: %s" % \
                    (type(self).__name__, e))

            try:
                if isinstance(e, Failure):
                    exc_type = e.type
                    exc_value = e.value
                    exc_tb = e.getTracebackObject()
                else:
                    exc_type, exc_value, exc_tb = sys.exc_info()

                mail_exception_handler(exc_type, exc_value, exc_tb)
            except Exception:
                pass

    def operation(self):
        pass # dummy skel for GLJob objects
Example #4
0
class GLJob(task.LoopingCall):
    iterations = 0
    start_time = 0
    mean_time = -1
    low_time = -1
    high_time = -1
    name = "unnamed"

    monitor = None

    def __init__(self):
        task.LoopingCall.__init__(self, self._operation)

    def stats_collection_start(self):
        self.monitor = ResourceMonitor(("[Job %s]" % self.name),
                                       JOB_MONITOR_TIME)

        self.start_time = time.time()

        if self.mean_time != -1:
            log.debug(
                "Starting job [%s] expecting an execution time of %.2f [low: %.2f, high: %.2f]"
                % (self.name, self.mean_time, self.low_time, self.high_time))
        else:
            log.debug("Starting job [%s]" % self.name)

    def stats_collection_end(self):
        if self.monitor is not None:
            self.monitor.stop()
            self.monitor = None

        current_run_time = time.time() - self.start_time

        # discard empty cicles from stats
        if current_run_time > 0.00:
            self.mean_time = ((self.mean_time * self.iterations) +
                              current_run_time) / (self.iterations + 1)

        if self.low_time == -1 or current_run_time < self.low_time:
            self.low_time = current_run_time

        if self.high_time == -1 or current_run_time > self.high_time:
            self.high_time = current_run_time

        log.debug("Ended job [%s] with an execution time of %.2f seconds" %
                  (self.name, current_run_time))

        self.iterations += 1

    @defer.inlineCallbacks
    def _operation(self):
        try:
            self.stats_collection_start()

            yield self.operation()

            self.stats_collection_end()
        except Exception as e:
            log.err("Exception while performin scheduled operation %s: %s" % \
                    (type(self).__name__, e))

            try:
                if isinstance(e, Failure):
                    exc_type = e.type
                    exc_value = e.value
                    exc_tb = e.getTracebackObject()
                else:
                    exc_type, exc_value, exc_tb = sys.exc_info()

                mail_exception_handler(exc_type, exc_value, exc_tb)
            except Exception:
                pass

    def operation(self):
        pass  # dummy skel for GLJob objects