Change in vdsm[master]: WIP

fromani at redhat.com fromani at redhat.com
Thu Apr 30 08:48:48 UTC 2015


Francesco Romani has uploaded a new change for review.

Change subject: WIP
......................................................................

WIP

Change-Id: I39c2e6e4bca286a513992b7231f1356e8dd871a1
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M vdsm/virt/sampling.py
1 file changed, 47 insertions(+), 37 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/31/40431/1

diff --git a/vdsm/virt/sampling.py b/vdsm/virt/sampling.py
index 45afdfd..eec5ae5 100644
--- a/vdsm/virt/sampling.py
+++ b/vdsm/virt/sampling.py
@@ -551,51 +551,30 @@
         return doms
 
 
-class HostStatsThread(threading.Thread):
-    """
-    A thread that periodically samples host statistics.
-    """
-    _CONNLOG = logging.getLogger('connectivity')
+class HostSampler(object):
+    _connlog = logging.getlogger('connectivity')
 
     def __init__(self, log):
-        self.startTime = time.time()
-
-        threading.Thread.__init__(self)
-        self.daemon = True
         self._log = log
-        self._stopEvent = threading.Event()
+        self._start_time = time.time()
         self._samples = SampleWindow(size=5)
 
         self._pid = os.getpid()
         self._ncpus = max(os.sysconf('SC_NPROCESSORS_ONLN'), 1)
 
-        self._sampleInterval = \
-            config.getint('vars', 'host_sample_stats_interval')
+        self._sample_interval = config.getint(
+            'vars', 'host_sample_stats_interval')
 
-    def stop(self):
-        self._stopEvent.set()
-
-    def run(self):
-        try:
-            # wait a bit before starting to sample
-            time.sleep(self._sampleInterval)
-            while not self._stopEvent.isSet():
-                try:
-                    sample = HostSample(self._pid)
-                    self._samples.append(sample)
-                    prev, last = self._samples.last_pair()
-                    if prev is None:
-                        self._CONNLOG.debug('%s', sample.to_connlog())
-                    else:
-                        diff = sample.connlog_diff(prev)
-                        if diff:
-                            self._CONNLOG.debug('%s', diff)
-                except TimeoutError:
-                    self._log.exception("Timeout while sampling stats")
-                self._stopEvent.wait(self._sampleInterval)
-        except:
-            if not self._stopEvent.isSet():
-                self._log.exception("Error while sampling stats")
+    def __call__(self):
+        sample = HostSample(self._pid)
+        self._samples.append(sample)
+        prev, last = self._samples.last_pair()
+        if prev is None:
+            self._CONNLOG.debug('%s', sample.to_connlog())
+        else:
+            diff = sample.connlog_diff(prev)
+                if diff:
+                    self._CONNLOG.debug('%s', diff)
 
     @utils.memoized
     def _boot_time(self):
@@ -625,7 +604,7 @@
         hs0, hs1, _ = self._samples.stats()
         interval = hs1.timestamp - hs0.timestamp
 
-        stats.update(self._get_interfaces_stats(hs0, hs1, interval))
+        stats.update(_get_interfaces_stats(hs0, hs1, interval))
 
         jiffies = (hs1.pidcpu.user - hs0.pidcpu.user) % (2 ** 32)
         stats['cpuUserVdsmd'] = jiffies / interval
@@ -655,6 +634,37 @@
         return stats
 
 
+
+class HostStatsThread(threading.Thread):
+    """
+    A thread that periodically samples host statistics.
+    """
+    _connlog = logging.getlogger('connectivity')
+
+    def __init__(self, log):
+        threading.Thread.__init__(self)
+        self._sampler = HostSampler(log)
+        self.daemon = True
+        self._stopEvent = threading.Event()
+
+    def stop(self):
+        self._stopEvent.set()
+
+    def run(self):
+        try:
+            # wait a bit before starting to sample
+            time.sleep(self._sampleInterval)
+            while not self._stopEvent.isSet():
+                try:
+                    self._sampler()
+                except TimeoutError:
+                    self._log.exception("Timeout while sampling stats")
+                self._stopEvent.wait(self._sampleInterval)
+        except:
+            if not self._stopEvent.isSet():
+                self._log.exception("Error while sampling stats")
+
+
 def _get_cpu_core_stats(hs0, hs1):
     """
     :returns: a dict that with the following formats:


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I39c2e6e4bca286a513992b7231f1356e8dd871a1
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>


More information about the vdsm-patches mailing list