Zhou Zheng Sheng has posted comments on this change.
Change subject: Add qemu's memory usage to VM statistics. ......................................................................
Patch Set 3: I would prefer that you didn't submit this
(1 inline comment)
.................................................... File vdsm/libvirtvm.py Line 173: Line 174: def _sampleMem(self): Line 175: memUsage = {} Line 176: if self.conf['pid'] != '0': Line 177: for line in open('/proc/%d/status' % (self.conf['pid'])): A file is opened here but not gets closed. Every time this stats function is call, we will leak 1 FD. File object returned by open is a Context Manager. So it can be used in a "with" directly. A better way could be:
with open('/proc/%d/status' % (self.conf['pid'])) as f: for line in f: ...
It guarantees that, when the execution flow leaves the "with" block, by whatever means such as "return", exception raised or just finish the block in peace, f will be closed. Line 178: var, value = line.strip().split()[0:2] Line 179: if var in ('VmSize:', 'VmRSS:', 'VmData:'): Line 180: memUsage[var[:-1]] = long(value) Line 181: return memUsage
-- To view, visit http://gerrit.ovirt.org/9006 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: Ibeb35759454c4a9b41e1303956267e93ca3545a0 Gerrit-PatchSet: 3 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Gal Hammer ghammer@redhat.com Gerrit-Reviewer: Gal Hammer ghammer@redhat.com Gerrit-Reviewer: Mark Wu wudxw@linux.vnet.ibm.com Gerrit-Reviewer: Michal Skrivanek michal.skrivanek@redhat.com Gerrit-Reviewer: Royce Lv lvroyce@linux.vnet.ibm.com Gerrit-Reviewer: ShaoHe Feng shaohef@linux.vnet.ibm.com Gerrit-Reviewer: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com