Change in vdsm[master]: virt: sampling: add StatsCache

fromani at redhat.com fromani at redhat.com
Mon Mar 30 08:14:01 UTC 2015


Francesco Romani has uploaded a new change for review.

Change subject: virt: sampling: add StatsCache
......................................................................

virt: sampling: add StatsCache

StatsCache is a small helper class which will be used
by the bulk stats sampling code to properly deal with
blocked calls, to avoid overwriting fresh samples
with stale one and to easiliy retrieve the per-vm
stats from the bulk stats.

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


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

diff --git a/vdsm/virt/sampling.py b/vdsm/virt/sampling.py
index 3206b97..f120a0a 100644
--- a/vdsm/virt/sampling.py
+++ b/vdsm/virt/sampling.py
@@ -401,6 +401,44 @@
         return self._samples.last()
 
 
+class StatsCache(object):
+    def __init__(self, log=None):
+        self._log = (log if log is not None else
+                     logging.getLogger("sampling.StatsCache"))
+        self._samples = SampleWindow(2)
+        self._last_sample_time = 0
+
+    def get(self, vmid):
+        first_batch, last_batch, interval = self._samples.stats()
+        if first_batch is None:
+            return (None, None, interval)
+
+        first_sample = first_batch.get(vmid)
+        last_sample = last_batch.get(vmid)
+        return (first_sample, last_sample, interval)
+
+    def put(self, bulk_stats, monotonic_ts):
+        if monotonic_ts >= self._last_sample_time:
+            self._samples.append(bulk_stats)
+            self._last_sample_time = monotonic_ts
+        else:
+            self._log.warning('dropped stale old sample')
+
+    def _fetch(self, vmid, batch, timestamp):
+        if batch is None:
+            sample = None
+        else:
+            sample = batch.get(vmid)
+
+        if sample is None:
+            return None, 0
+        else:
+            return sample, timestamp
+
+
+stats_cache = StatsCache()
+
+
 class AdvancedStatsThread(threading.Thread):
     """
     A thread that runs the registered AdvancedStatsFunction objects


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I11d5069f49d54bb5f43a7c4914c7e4b9f8093db9
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