Change in vdsm[master]: virt: stats: drop {Advanced,Vm}StatsThread

fromani at redhat.com fromani at redhat.com
Fri Mar 27 16:09:44 UTC 2015


Francesco Romani has uploaded a new change for review.

Change subject: virt: stats: drop {Advanced,Vm}StatsThread
......................................................................

virt: stats: drop {Advanced,Vm}StatsThread

VmStatsThread and AdvancedStatsThread are
not used anymore, so this patch drops them.

Change-Id: Ia724c94867f470d32f063a1b177e73d2382e6525
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M tests/vmTests.py
M tests/vmfakelib.py
M vdsm/clientIF.py
M vdsm/virt/sampling.py
M vdsm/virt/vm.py
5 files changed, 3 insertions(+), 158 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/84/39284/1

diff --git a/tests/vmTests.py b/tests/vmTests.py
index f666aad..bb017a0 100644
--- a/tests/vmTests.py
+++ b/tests/vmTests.py
@@ -1121,7 +1121,7 @@
               'vmType': 'kvm', 'memSize': 1024}
 
 
-class TestVmStatsThread(TestCaseBase):
+class TestVmStats(TestCaseBase):
 
     DEV_BALLOON = [{'type': 'balloon', 'specParams': {'model': 'virtio'}}]
 
diff --git a/tests/vmfakelib.py b/tests/vmfakelib.py
index 271538e..6dfa126 100644
--- a/tests/vmfakelib.py
+++ b/tests/vmfakelib.py
@@ -232,9 +232,3 @@
 
     def getLastSample(self):
         return self._samples
-
-
-class VmStatsThread:
-    def __init__(self, vm):
-        self._vm = vm
-        self.sampleVcpuPinning = AdvancedStatsFunction()
diff --git a/vdsm/clientIF.py b/vdsm/clientIF.py
index 2719101..3ad94af 100644
--- a/vdsm/clientIF.py
+++ b/vdsm/clientIF.py
@@ -239,8 +239,7 @@
             self._enabled = False
             self.channelListener.stop()
             self._hostStats.stop()
-            for vm_obj in self.vmContainer.values():
-                vm_obj.stopVmStats()
+            # periodic operations stopped outside
             if self.mom:
                 self.mom.stop()
             if self.irs:
diff --git a/vdsm/virt/sampling.py b/vdsm/virt/sampling.py
index 7a0fa9f..bb38666 100644
--- a/vdsm/virt/sampling.py
+++ b/vdsm/virt/sampling.py
@@ -503,117 +503,6 @@
         return doms
 
 
-class AdvancedStatsThread(threading.Thread):
-    """
-    A thread that runs the registered AdvancedStatsFunction objects
-    for statistic and monitoring purpose.
-    """
-    DEFAULT_LOG = logging.getLogger("AdvancedStatsThread")
-
-    def __init__(self, log=DEFAULT_LOG, daemon=False):
-        """
-        Initialize an AdvancedStatsThread object
-        """
-        threading.Thread.__init__(self)
-        self.daemon = daemon
-
-        self._log = log
-        self._stopEvent = threading.Event()
-        self._contEvent = threading.Event()
-
-        self._statsTime = None
-        self._statsFunctions = []
-
-    def addStatsFunction(self, *args):
-        """
-        Register the functions listed as arguments
-        """
-        if self.isAlive():
-            raise RuntimeError("AdvancedStatsThread is started")
-
-        for statsFunction in args:
-            self._statsFunctions.append(statsFunction)
-
-    def start(self):
-        """
-        Start the execution of the thread and exit
-        """
-        self._log.debug("Start statistics collection")
-        threading.Thread.start(self)
-
-    def stop(self):
-        """
-        Stop the execution of the thread and exit
-        """
-        self._log.debug("Stop statistics collection")
-        self._stopEvent.set()
-        self._contEvent.set()
-
-    def pause(self):
-        """
-        Pause the execution of the registered functions
-        """
-        self._log.debug("Pause statistics collection")
-        self._contEvent.clear()
-
-    def cont(self):
-        """
-        Resume the execution of the registered functions
-        """
-        self._log.debug("Resume statistics collection")
-        self._contEvent.set()
-
-    def getLastSampleTime(self):
-        return self._statsTime
-
-    def run(self):
-        self._log.debug("Stats thread started")
-        self._contEvent.set()
-
-        while not self._stopEvent.isSet():
-            try:
-                self.collect()
-            except:
-                self._log.debug("Stats thread failed", exc_info=True)
-
-        self._log.debug("Stats thread finished")
-
-    def handleStatsException(self, ex):
-        """
-        Handle the registered function exceptions and eventually stop the
-        sampling if a fatal error occurred.
-        """
-        return False
-
-    def collect(self):
-        # TODO: improve this with lcm
-        _mInt = map(lambda x: x.interval, self._statsFunctions)
-        maxInterval = reduce(lambda x, y: x * y, set(_mInt), 1)
-
-        intervalAccum = 0
-        while not self._stopEvent.isSet():
-            self._contEvent.wait()
-
-            self._statsTime = time.time()
-            waitInterval = maxInterval
-
-            for statsFunction in self._statsFunctions:
-                thisInterval = statsFunction.interval - (
-                    intervalAccum % statsFunction.interval)
-                waitInterval = min(waitInterval, thisInterval)
-
-                if intervalAccum % statsFunction.interval == 0:
-                    try:
-                        statsFunction()
-                    except Exception as e:
-                        if not self.handleStatsException(e):
-                            self._log.exception("Stats function failed: %s",
-                                                statsFunction)
-
-            self._stopEvent.wait(waitInterval)
-            intervalAccum = (intervalAccum + waitInterval) % maxInterval
-
-
 class HostStatsThread(threading.Thread):
     """
     A thread that periodically samples host statistics.
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index 6354a74..94d85a0 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -71,7 +71,6 @@
 from .vmtune import io_tune_values_to_dom, io_tune_dom_to_values
 from . import vmxml
 
-from .sampling import AdvancedStatsThread
 from .utils import isVdsmImage
 from vmpowerdown import VmShutdown, VmReboot
 
@@ -174,24 +173,6 @@
 
 
 _MBPS_TO_BPS = 10 ** 6 / 8
-
-
-class VmStatsThread(AdvancedStatsThread):
-
-    def __init__(self, vm):
-        AdvancedStatsThread.__init__(self, log=vm.log, daemon=True)
-        self._vm = vm
-
-    def handleStatsException(self, ex):
-        # We currently handle only libvirt exceptions
-        if not hasattr(ex, "get_error_code"):
-            return False
-
-        # We currently handle only the missing domain exception
-        if ex.get_error_code() != libvirt.VIR_ERR_NO_DOMAIN:
-            return False
-
-        return True
 
 
 class TimeoutError(libvirt.libvirtError):
@@ -1249,7 +1230,7 @@
 
         WARNING: this method should only gather statistics by copying data.
         Especially avoid costly and dangerous ditrect calls to the _dom
-        attribute. Use the VmStatsThread instead!
+        attribute. Use the periodic operations instead!
         """
 
         if self.lastStatus == vmstatus.DOWN:
@@ -1558,21 +1539,6 @@
 
         return domxml.toxml()
 
-    def startVmStats(self):
-        self._vmStats = VmStatsThread(self)
-        self._vmStats.start()
-        self._guestEventTime = self._startTime
-
-    def stopVmStats(self):
-        # this is less clean that it could be, but we can get here from
-        # many flows and with various locks held
-        # (_releaseLock, _shutdownLock)
-        # _vmStats may be None already, and we're good with that.
-        try:
-            self._vmStats.stop()
-        except AttributeError:
-            pass
-
     @staticmethod
     def _guestSockCleanup(sock):
         if os.path.islink(sock):
@@ -1678,9 +1644,6 @@
                         supervdsm.getProxy().setPortMirroring(network,
                                                               nic.name)
 
-        # VmStatsThread may use block devices info from libvirt.
-        # So, run it after you have this info
-        self.startVmStats()
         try:
             self.guestAgent.connect()
         except Exception:


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

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