def start (self, name): self._isWorking = True self._realStartTime = monotonic_clock.monotonicTimeNano() self._alignedStartTime = self._realStartTime self._totalNanoSecondsCounterRefernenceTime = self._realStartTime self._activeNanoSecondsCounterRefernenceTime = self._realStartTime self._specificName = name self._startCounter.inc() #no kickTimeCount as we just starting or getting out of "disabled" self._log("start").debug5("start. time '%d', name %s", self._realStartTime, self._specificName)
def restart(self): self._log("start-again").debug5("start-again") name = self._specificName if name is None: name = "" else: name = "(%s)" % name if self._alignedStartTime is None: self._log("start-again-start").error( "called the 'restart' function with no 'start' function call") return if self._interval is None: self._log("start-again-no-interval").error( "calling start-again with no repeatition set") return self._startCounter.inc() now = monotonic_clock.monotonicTimeNano() deltaT = now - self._alignedStartTime if self._latencyErrorThresholdNanoSeconds > 0 and ( deltaT - self._interval) >= self._latencyErrorThresholdNanoSeconds: self._reportingLog("latency-error-th-reached").error( "Reached the latency error threshold for %s%s: total time passed: %.03f sec >= %.03f sec", self._logString, name, deltaT * 1.0 / 1000 / 1000 / 1000, self._latencyErrorThresholdNanoSeconds * 1.0 / 1000 / 1000 / 1000) self._latencyErrorCounter.inc() elif self._latencyWarningThresholdNanoSeconds > 0 and ( deltaT - self._interval) >= self._latencyWarningThresholdNanoSeconds: self._reportingLog("latency-warning-th-reached").warning( "Reached the latency warning threshold for %s%s: total time passed: %.03f sec >= %.03f sec", self._logString, name, deltaT * 1.0 / 1000 / 1000 / 1000, self._latencyWarningThresholdNanoSeconds * 1.0 / 1000 / 1000 / 1000) self._latencyWarningCounter.inc() passCycles = int(deltaT / self._interval) if passCycles > 1: self._reportingLog("miss").warning("Missed %d cycles", passCycles - 1) self._missCounter.inc(passCycles - 1) self.kickTimeCount( now) #before changing _isWorking to True as it uses it self._isWorking = True self._alignedStartTime = self._alignedStartTime + passCycles * self._interval self._realStartTime = now self._log("restart").debug5("started again - new base time %d", self._alignedStartTime)
def start(self, name): self._isWorking = True self._realStartTime = monotonic_clock.monotonicTimeNano() self._alignedStartTime = self._realStartTime self._totalNanoSecondsCounterRefernenceTime = self._realStartTime self._activeNanoSecondsCounterRefernenceTime = self._realStartTime self._specificName = name self._startCounter.inc() #no kickTimeCount as we just starting or getting out of "disabled" self._log("start").debug5("start. time '%d', name %s", self._realStartTime, self._specificName)
def kickTimeCount (self, now = None): if now is None: now = monotonic_clock.monotonicTimeNano() #update the total time counter here for the "smoothness' of the counter. #We do not do it on the "get counter" as we don't have enough information maybe we are disabled) #and we are maybe in another thread... self._totalNanoSecondsCounter.inc(now-self._totalNanoSecondsCounterRefernenceTime) self._totalNanoSecondsCounterRefernenceTime = now if self._isWorking: self._activeNanoSecondsCounter.inc(now-self._activeNanoSecondsCounterRefernenceTime) self._activeNanoSecondsCounterRefernenceTime = now
def kickTimeCount(self, now=None): if now is None: now = monotonic_clock.monotonicTimeNano() #update the total time counter here for the "smoothness' of the counter. #We do not do it on the "get counter" as we don't have enough information maybe we are disabled) #and we are maybe in another thread... self._totalNanoSecondsCounter.inc( now - self._totalNanoSecondsCounterRefernenceTime) self._totalNanoSecondsCounterRefernenceTime = now if self._isWorking: self._activeNanoSecondsCounter.inc( now - self._activeNanoSecondsCounterRefernenceTime) self._activeNanoSecondsCounterRefernenceTime = now
def hasReachedRestartTime (self): if self._alignedStartTime is None: self._log("try-reach-no-start").error("called the 'hasReachedRestartTime' function with no 'start' function call") return False if self._interval is None: self._log("try-reach-no-interval").error("calling 'hasReachedRestartTime' with no interval set") return False now = monotonic_clock.monotonicTimeNano() #update the total time counter here for the "smoothness' of the counter. #We do not do it on the "get counter" as we don't have enough information maybe we are disabled) #and we are maybe in another thread... self.kickTimeCount(now) return now >= self._alignedStartTime+self._interval
def end(self, returnCode): now = monotonic_clock.monotonicTimeNano() name = self._specificName if name is None: name = "" else: name = "(%s)" % name if not self._isWorking: self._log("end-no-start").error( "called the 'end' function with no 'start' function call") return if not returnCode.success(): self._reportingLog("failure").error("Failure in %s%s: %s", self._logString, name, returnCode) self._failuresCounter.inc() else: self._successCounter.inc() deltaT = now - self._realStartTime if self._durationErrorThresholdNanoSeconds > 0 and deltaT >= self._durationErrorThresholdNanoSeconds: self._reportingLog("dur-error-th-reached").error( "Reached the duration error threshold for %s%s: total time passed: %.03f sec >= %.03f sec", self._logString, name, deltaT * 1.0 / 1000 / 1000 / 1000, self._durationErrorThresholdNanoSeconds * 1.0 / 1000 / 1000 / 1000) self._durationErrorCounter.inc() elif self._durationWarningThresholdNanoSeconds > 0 and deltaT >= self._durationWarningThresholdNanoSeconds: self._reportingLog("dur-warning-th-reached").warning( "Reached the duration warning threshold for %s%s: total time passed: %.03f sec >= %.03f sec", self._logString, name, deltaT * 1.0 / 1000 / 1000 / 1000, self._durationWarningThresholdNanoSeconds * 1.0 / 1000 / 1000 / 1000) self._durationWarningCounter.inc() self.kickTimeCount( now) #before changing _isWorking to False as it uses it self._isWorking = False self._realStartTime = None if self._interval is None: self._log("end").debug5("end") self._clearStart()
def hasReachedRestartTime(self): if self._alignedStartTime is None: self._log("try-reach-no-start").error( "called the 'hasReachedRestartTime' function with no 'start' function call" ) return False if self._interval is None: self._log("try-reach-no-interval").error( "calling 'hasReachedRestartTime' with no interval set") return False now = monotonic_clock.monotonicTimeNano() #update the total time counter here for the "smoothness' of the counter. #We do not do it on the "get counter" as we don't have enough information maybe we are disabled) #and we are maybe in another thread... self.kickTimeCount(now) return now >= self._alignedStartTime + self._interval
def end (self, returnCode): now = monotonic_clock.monotonicTimeNano() name = self._specificName if name is None: name = "" else: name = "(%s)"%name if not self._isWorking: self._log("end-no-start").error("called the 'end' function with no 'start' function call") return if not returnCode.success(): self._reportingLog("failure").error("Failure in %s%s: %s", self._logString, name, returnCode) self._failuresCounter.inc() else: self._successCounter.inc() deltaT = now - self._realStartTime if self._durationErrorThresholdNanoSeconds > 0 and deltaT >= self._durationErrorThresholdNanoSeconds: self._reportingLog("dur-error-th-reached").error("Reached the duration error threshold for %s%s: total time passed: %.03f sec >= %.03f sec", self._logString, name, deltaT*1.0/1000/1000/1000, self._durationErrorThresholdNanoSeconds*1.0/1000/1000/1000) self._durationErrorCounter.inc() elif self._durationWarningThresholdNanoSeconds > 0 and deltaT >= self._durationWarningThresholdNanoSeconds: self._reportingLog("dur-warning-th-reached").warning("Reached the duration warning threshold for %s%s: total time passed: %.03f sec >= %.03f sec", self._logString, name, deltaT*1.0/1000/1000/1000, self._durationWarningThresholdNanoSeconds*1.0/1000/1000/1000) self._durationWarningCounter.inc() self.kickTimeCount(now)#before changing _isWorking to False as it uses it self._isWorking = False self._realStartTime = None if self._interval is None: self._log("end").debug5("end") self._clearStart()
def restart (self): self._log("start-again").debug5("start-again") name = self._specificName if name is None: name = "" else: name = "(%s)"%name if self._alignedStartTime is None: self._log("start-again-start").error("called the 'restart' function with no 'start' function call") return if self._interval is None: self._log("start-again-no-interval").error("calling start-again with no repeatition set") return self._startCounter.inc() now = monotonic_clock.monotonicTimeNano() deltaT = now - self._alignedStartTime if self._latencyErrorThresholdNanoSeconds > 0 and (deltaT-self._interval) >= self._latencyErrorThresholdNanoSeconds: self._reportingLog("latency-error-th-reached").error("Reached the latency error threshold for %s%s: total time passed: %.03f sec >= %.03f sec", self._logString, name, deltaT*1.0/1000/1000/1000, self._latencyErrorThresholdNanoSeconds*1.0/1000/1000/1000) self._latencyErrorCounter.inc() elif self._latencyWarningThresholdNanoSeconds > 0 and (deltaT-self._interval) >= self._latencyWarningThresholdNanoSeconds: self._reportingLog("latency-warning-th-reached").warning("Reached the latency warning threshold for %s%s: total time passed: %.03f sec >= %.03f sec", self._logString, name, deltaT*1.0/1000/1000/1000, self._latencyWarningThresholdNanoSeconds*1.0/1000/1000/1000) self._latencyWarningCounter.inc() passCycles = int(deltaT/self._interval) if passCycles > 1: self._reportingLog("miss").warning("Missed %d cycles", passCycles-1) self._missCounter.inc(passCycles-1) self.kickTimeCount(now)#before changing _isWorking to True as it uses it self._isWorking = True self._alignedStartTime = self._alignedStartTime + passCycles*self._interval self._realStartTime = now self._log("restart").debug5("started again - new base time %d", self._alignedStartTime)