def __init__(self, interval, smoothingWindow=8, **kwargs): AutoFetcher.AutoFetcher.__init__(self, interval, **kwargs) self.__window = smoothingWindow self.__ave = 0.0 self.__values = {} numCpus = len(psutil.cpu_percent(percpu=True)) empty = [0.0,]*self.__window for key in range(numCpus): self.__values[key] = list(empty)
def __init__(self, interval, smoothing_window=8, **kwargs): auto_fetcher.AutoFetcher.__init__(self, interval, **kwargs) self.__window = smoothing_window self.__ave = 0.0 self.__values = {} num_cpus = len(psutil.cpu_percent(percpu=True)) empty = [ 0.0, ] * self.__window for key in range(num_cpus): self.__values[key] = list(empty)
def _update(self): # per-core list of [0, 100] values perCpu = psutil.cpu_percent(percpu=True) sumOfAverages = 0.0 with self._lockGuard(): for i, decPercent in enumerate(perCpu): # Add the new value, drop the oldest. values = self.__values[i][1:] values.append(decPercent/100.0) self.__values[i] = values sumOfAverages += sum(values)/self.__window self.__ave = sumOfAverages/len(self.__values) self._callChangeCallback()
def _Update(self): # per-core list of [0, 100] values per_cpu = psutil.cpu_percent(percpu=True) sum_of_averages = 0.0 with self._LockGuard(): for i, dec_percent in enumerate(per_cpu): # Add the new value, drop the oldest. values = self.__values[i][1:] values.append(dec_percent / 100.0) self.__values[i] = values sum_of_averages += sum(values) / self.__window self.__ave = sum_of_averages / len(self.__values) self._CallChangeCallback()