Hello Piotr Kliczewski, Nir Soffer, I'd like you to do a code review. Please visit
https://gerrit.ovirt.org/52626 to review the following change. Change subject: health: Report resource usage ...................................................................... health: Report resource usage Report cpu usage in the last interval, memory size, memory delta, and number of threads: user=7.67%, sys=3.07%, rss=68716 kB (+2188), threads=60 Change-Id: I512a57ebf54113aa442d9862a24164455d4de042 Signed-off-by: Nir Soffer <nsof...@redhat.com> Reviewed-on: https://gerrit.ovirt.org/51916 Reviewed-by: Francesco Romani <from...@redhat.com> Reviewed-by: Michal Skrivanek <michal.skriva...@redhat.com> Reviewed-by: Piotr Kliczewski <piotr.kliczew...@gmail.com> Continuous-Integration: Jenkins CI --- M lib/vdsm/health.py 1 file changed, 36 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/26/52626/1 diff --git a/lib/vdsm/health.py b/lib/vdsm/health.py index c1bade6..1b414a5 100644 --- a/lib/vdsm/health.py +++ b/lib/vdsm/health.py @@ -21,6 +21,7 @@ from __future__ import absolute_import import gc import logging +import os import threading from . config import config @@ -53,6 +54,7 @@ self._interval = interval self._thread = concurrent.thread(self._run) self._done = threading.Event() + self._last = ProcStat() def start(self): self.log.info("Starting health monitor (interval=%d)", self._interval) @@ -82,6 +84,10 @@ def _check(self): self.log.debug("Checking health") + self._check_garbage() + self._check_resources() + + def _check_garbage(self): collected = gc.collect() self.log.debug("Collected %d objects", collected) # Copy garbage so it is not modified while iterate over it. @@ -91,6 +97,36 @@ self.log.warning("Found %d uncollectable objects: %s", len(uncollectable), uncollectable) + def _check_resources(self): + current = ProcStat() + utime_pct = (current.utime - self._last.utime) / self._interval * 100 + stime_pct = (current.stime - self._last.stime) / self._interval * 100 + delta_rss = current.rss - self._last.rss + self._last = current + self.log.debug("user=%.2f%%, sys=%.2f%%, rss=%d kB (%s%d), threads=%d", + utime_pct, + stime_pct, + current.rss, + "+" if delta_rss >= 0 else "-", + abs(delta_rss), + current.threads) + + +class ProcStat(object): + + _PAGE_SIZE = os.sysconf("SC_PAGESIZE") + _TICKS_PER_SEC = os.sysconf("SC_CLK_TCK") + _PATH = "/proc/self/stat" + + def __init__(self): + with open(self._PATH, "rb") as f: + fields = f.readline().split() + # See proc(5) for available fields and their semantics. + self.utime = int(fields[13], 10) / float(self._TICKS_PER_SEC) + self.stime = int(fields[14], 10) / float(self._TICKS_PER_SEC) + self.threads = int(fields[19], 10) + self.rss = int(fields[23], 10) * self._PAGE_SIZE / 1024 + def saferepr(obj): """ -- To view, visit https://gerrit.ovirt.org/52626 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I512a57ebf54113aa442d9862a24164455d4de042 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: ovirt-3.6 Gerrit-Owner: Francesco Romani <from...@redhat.com> Gerrit-Reviewer: Nir Soffer <nsof...@redhat.com> Gerrit-Reviewer: Piotr Kliczewski <piotr.kliczew...@gmail.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches