Francesco Romani has uploaded a new change for review.

Change subject: sampling: hoststats: switch to SampleWindow
......................................................................

sampling: hoststats: switch to SampleWindow

HostStatsThread has its own sampling storage code,
remniscent of VmStatsThread before the switch
of SampleWindow.

The requirements and the use cases are already almost
completely covered by SampleWindow, so this patch
ports HostStatsThread to it, to reduce duplication.

Change-Id: I5ec5712ee1fb69ed3d8dbc28ca4e6511998270c9
Signed-off-by: Francesco Romani <from...@redhat.com>
---
M vdsm/virt/sampling.py
1 file changed, 4 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/28/40428/1

diff --git a/vdsm/virt/sampling.py b/vdsm/virt/sampling.py
index d59ce2c..cbe53ef 100644
--- a/vdsm/virt/sampling.py
+++ b/vdsm/virt/sampling.py
@@ -555,7 +555,6 @@
     """
     A thread that periodically samples host statistics.
     """
-    AVERAGING_WINDOW = 5
     _CONNLOG = logging.getLogger('connectivity')
 
     def __init__(self, log):
@@ -565,7 +564,7 @@
         self.daemon = True
         self._log = log
         self._stopEvent = threading.Event()
-        self._samples = []
+        self._samples = SampleWindow(size=5)
 
         self._pid = os.getpid()
         self._ncpus = max(os.sysconf('SC_NPROCESSORS_ONLN'), 1)
@@ -584,15 +583,13 @@
                 try:
                     sample = HostSample(self._pid)
                     self._samples.append(sample)
-                    if len(self._samples) == 1:
+                    prev, last = self._samples.last_pair()
+                    if prev is None:
                         self._CONNLOG.debug('%s', sample.to_connlog())
                     else:
-                        diff = sample.connlog_diff(self._samples[-2])
+                        diff = sample.connlog_diff(prev)
                         if diff:
                             self._CONNLOG.debug('%s', diff)
-
-                    if len(self._samples) > self.AVERAGING_WINDOW:
-                        self._samples.pop(0)
                 except TimeoutError:
                     self._log.exception("Timeout while sampling stats")
                 self._stopEvent.wait(self._sampleInterval)


-- 
To view, visit https://gerrit.ovirt.org/40428
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5ec5712ee1fb69ed3d8dbc28ca4e6511998270c9
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <from...@redhat.com>
_______________________________________________
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to