Francesco Romani has uploaded a new change for review.

Change subject: WIP: restore cpu tuning samples
......................................................................

WIP: restore cpu tuning samples

DONT MERGE WORK IN PROGRESS

Previous (hackish) patch disabled cpu tune sampling.
This patch builds an hack over an hack and restores
the cpu tune sampling, in order to assess the increased
libvirt load.

Change-Id: Ic3d05bb388d76e26b5fb983a9af2e998ff289054
Signed-off-by: Francesco Romani <[email protected]>
---
M vdsm/virt/sampling.py
M vdsm/virt/vm.py
M vdsm/virt/vmstats.py
3 files changed, 46 insertions(+), 41 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/27/37327/1

diff --git a/vdsm/virt/sampling.py b/vdsm/virt/sampling.py
index f103f96..3aef267 100644
--- a/vdsm/virt/sampling.py
+++ b/vdsm/virt/sampling.py
@@ -30,6 +30,7 @@
 import re
 import threading
 import time
+import xml.etree.cElementTree as ET
 
 import libvirt
 
@@ -107,11 +108,11 @@
             return ({}, {}, 1.0)
         self._log.debug('vm %s is responsive', vm_id)
         first_sample, last_sample, interval = self._bulk.stats()
-        res = (first_sample.get(vm_id, {}),
-               last_sample.get(vm_id, {}),
-               interval)
-        self._log.debug('getting stats for %s:\n%s', vm_id, res)
-        return res
+        first_sample = {} if first_sample is None else first_sample
+        last_sample = {} if last_sample is None else last_sample
+        return (first_sample.get(vm_id, {}),
+                last_sample.get(vm_id, {}),
+                interval)
 
     # Task interface
 
@@ -201,10 +202,45 @@
         except KeyError:
             pass  # nevermind about errors
 
+        stats.update(_sample_cpu_tune(dom))
         snapshot[vmId] = stats
     return snapshot
 
 
+METADATA_VM_TUNE_URI = 'http://ovirt.org/vm/tune/1.0'
+
+
+_libvirt_metadata_supported = True
+
+
+def _sample_cpu_tune(dom):
+    global _libvirt_metadata_supported
+
+    infos = dom.schedulerParameters()
+
+    metadataCpuLimit = None
+
+    try:
+        if _libvirt_metadata_supported:
+            metadataCpuLimit = dom.metadata(
+                libvirt.VIR_DOMAIN_METADATA_ELEMENT,
+                METADATA_VM_TUNE_URI, 0)
+    except libvirt.libvirtError as e:
+        if e.get_error_code() == libvirt.VIR_ERR_ARGUMENT_UNSUPPORTED:
+            _libvirt_metadata_supported = False
+        else:
+            pass
+
+    if metadataCpuLimit:
+        metadataCpuLimitXML = ET.fromstring(metadataCpuLimit)
+#        nodeList = \
+#            metadataCpuLimitXML.getElementsByTagName('vcpulimit')
+#        infos['vcpuLimit'] = nodeList[0].childNodes[0].data
+        infos['vcpuLimit'] = len(metadataCpuLimitXML)  # FIXME
+
+    return infos
+
+
 def use_bulk():
     return (
         hasattr(libvirt, 'VIR_DOMAIN_STATS_STATE') and not
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index 13659b8..70075cd 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -503,47 +503,12 @@
         self._bulkStats = None
 
         self._sampleVmJobs = sampling.SampleWindow(self.SAMPLE_NUM)
-        self._sampleCpuTune = sampling.SampleWindow(self.SAMPLE_NUM)
 
     def sampleVmJobs(self):
         # compatibility with VmStatsThread
         jobs = self._vm.queryBlockJobs()
         self._sampleVmJobs.append(jobs)
         return jobs
-
-    def sampleCpuTune(self):
-        infos = self._vm._dom.schedulerParameters()
-        infos['vcpuCount'] = self._vm._dom.vcpusFlags(
-            libvirt.VIR_DOMAIN_VCPU_CURRENT)
-
-        metadataCpuLimit = None
-
-        try:
-            if VmStats._libvirt_metadata_supported:
-                metadataCpuLimit = self._vm._dom.metadata(
-                    libvirt.VIR_DOMAIN_METADATA_ELEMENT,
-                    METADATA_VM_TUNE_URI, 0)
-        except libvirt.libvirtError as e:
-            if e.get_error_code() == libvirt.VIR_ERR_ARGUMENT_UNSUPPORTED:
-                VmStats._libvirt_metadata_supported = False
-                self._log.error("libvirt does not support metadata")
-
-            elif (e.get_error_code()
-                  not in (libvirt.VIR_ERR_NO_DOMAIN,
-                          libvirt.VIR_ERR_NO_DOMAIN_METADATA)):
-                # Non-existing VM and no metadata block are expected
-                # conditions and no reasons for concern here.
-                # All other errors should be reported.
-                self._log.warn("Failed to retrieve QoS metadata because of %s",
-                               e)
-
-        if metadataCpuLimit:
-            metadataCpuLimitXML = _domParseStr(metadataCpuLimit)
-            nodeList = \
-                metadataCpuLimitXML.getElementsByTagName('vcpulimit')
-            infos['vcpuLimit'] = nodeList[0].childNodes[0].data
-
-        self._sampleCpuTune.append(infos)
 
     # vmstats.Collector interface
     def refresh(self, now):
@@ -574,7 +539,8 @@
         return first_sample or last_sample
 
     def getSampleCpuTune(self):
-        return self._sampleCpuTune.last()
+        first_sample, last_sample, interval = self._bulkStats
+        return first_sample or last_sample
 
     # compatibility with VmStatsThread
 
diff --git a/vdsm/virt/vmstats.py b/vdsm/virt/vmstats.py
index 86025c7..302e4ff 100644
--- a/vdsm/virt/vmstats.py
+++ b/vdsm/virt/vmstats.py
@@ -176,6 +176,9 @@
                 stats['vcpuCount'] = vcpuCount
             else:
                 self._log.error('Failed to get VM cpu count')
+        elif 'vcpu.current' in sample:
+            value = sample['vcpu.current']
+            stats['vcpuCount'] = value
 
     def _getUserCpuTuneInfo(self, stats, sample):
         # Handling the case when not enough samples exist


-- 
To view, visit http://gerrit.ovirt.org/37327
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic3d05bb388d76e26b5fb983a9af2e998ff289054
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to