Skip to content
Snippets Groups Projects
Commit 1560e2ac authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

made CPUProfileBuilderThread use SingleStartThread

Change-Id: Ibb88378f0d807688fefb3270c548ef077395a6ca
parent d88afa20
No related branches found
No related tags found
No related merge requests found
...@@ -3,13 +3,13 @@ from __future__ import annotations ...@@ -3,13 +3,13 @@ from __future__ import annotations
import collections import collections
import multiprocessing import multiprocessing
import os import os
import threading
import time import time
import typing as tp import typing as tp
import psutil import psutil
from satella.coding import for_argument from satella.coding import for_argument
from satella.coding.concurrent import SingleStartThread
from satella.coding.decorators import repeat_forever from satella.coding.decorators import repeat_forever
from satella.coding.transforms import percentile from satella.coding.transforms import percentile
from satella.time import parse_time_string from satella.time import parse_time_string
...@@ -22,13 +22,13 @@ pCPUtimes = collections.namedtuple('pcputimes', ...@@ -22,13 +22,13 @@ pCPUtimes = collections.namedtuple('pcputimes',
'iowait']) 'iowait'])
class _CPUProfileBuilderThread(threading.Thread): class _CPUProfileBuilderThread(SingleStartThread):
""" """
A CPU profile builder thread and a core singleton object to use. A CPU profile builder thread and a core singleton object to use.
:param window_seconds: the amount of seconds for which to collect data. :param window_seconds: the amount of seconds for which to collect data.
Generally, this should be the interval during which your system cycles through all of Generally, this should be the interval during which your system cycles through all of
it's load, eg. if it asks it's devices each 5 minutes, the interval should be 300 seconds. its load, eg. if it asks its devices each 5 minutes, the interval should be 300 seconds.
Or a time string. Or a time string.
:param refresh_each: time of seconds to sleep between rebuilding of profiles, or a time string. :param refresh_each: time of seconds to sleep between rebuilding of profiles, or a time string.
""" """
...@@ -56,12 +56,6 @@ class _CPUProfileBuilderThread(threading.Thread): ...@@ -56,12 +56,6 @@ class _CPUProfileBuilderThread(threading.Thread):
_CPUProfileBuilderThread.thread.start() _CPUProfileBuilderThread.thread.start()
return _CPUProfileBuilderThread.thread return _CPUProfileBuilderThread.thread
def start(self) -> None:
if self.started:
return
self.started = True
super().start()
def save_load(self, times: pCPUtimes) -> None: def save_load(self, times: pCPUtimes) -> None:
while len(self.own_load_average) > 3 and \ while len(self.own_load_average) > 3 and \
self.own_load_average[0][0] < self.own_load_average[-1][0] - self.window_size: self.own_load_average[0][0] < self.own_load_average[-1][0] - self.window_size:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment