Merge #14693: test_node: get_mem_rss fixups
fa9ed38d57
test_node: get_mem_rss fixups (MarcoFalke)
Pull request description:
Follow up to #14522:
* Fix math (Memory usage increase relative to previous memory usage, not final memory usage)
* remove `shell=True`
* assert that the node is running
* Make it work on BSD-like systems
Tree-SHA512: fc1b4f88173914b6cb6373655cffd781044a0c146339e3fa90da03b197faa20954567a77335965b857d29d27f32661698b6a0340f0c616f643b8c4510cd360c2
This commit is contained in:
commit
af3c8a7e9f
1 changed files with 7 additions and 10 deletions
|
@ -118,22 +118,19 @@ class TestNode():
|
||||||
def get_mem_rss(self):
|
def get_mem_rss(self):
|
||||||
"""Get the memory usage (RSS) per `ps`.
|
"""Get the memory usage (RSS) per `ps`.
|
||||||
|
|
||||||
If process is stopped or `ps` is unavailable, return None.
|
Returns None if `ps` is unavailable.
|
||||||
"""
|
"""
|
||||||
if not (self.running and self.process):
|
assert self.running
|
||||||
self.log.warning("Couldn't get memory usage; process isn't running.")
|
|
||||||
return None
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return int(subprocess.check_output(
|
return int(subprocess.check_output(
|
||||||
"ps h -o rss {}".format(self.process.pid),
|
["ps", "h", "-o", "rss", "{}".format(self.process.pid)],
|
||||||
shell=True, stderr=subprocess.DEVNULL).strip())
|
stderr=subprocess.DEVNULL).split()[-1])
|
||||||
|
|
||||||
# Catching `Exception` broadly to avoid failing on platforms where ps
|
# Avoid failing on platforms where ps isn't installed.
|
||||||
# isn't installed or doesn't work as expected, e.g. OpenBSD.
|
|
||||||
#
|
#
|
||||||
# We could later use something like `psutils` to work across platforms.
|
# We could later use something like `psutils` to work across platforms.
|
||||||
except Exception:
|
except (FileNotFoundError, subprocess.SubprocessError):
|
||||||
self.log.exception("Unable to get memory usage")
|
self.log.exception("Unable to get memory usage")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -308,7 +305,7 @@ class TestNode():
|
||||||
self.log.warning("Unable to detect memory usage (RSS) - skipping memory check.")
|
self.log.warning("Unable to detect memory usage (RSS) - skipping memory check.")
|
||||||
return
|
return
|
||||||
|
|
||||||
perc_increase_memory_usage = 1 - (float(before_memory_usage) / after_memory_usage)
|
perc_increase_memory_usage = (after_memory_usage / before_memory_usage) - 1
|
||||||
|
|
||||||
if perc_increase_memory_usage > perc_increase_allowed:
|
if perc_increase_memory_usage > perc_increase_allowed:
|
||||||
self._raise_assertion_error(
|
self._raise_assertion_error(
|
||||||
|
|
Loading…
Reference in a new issue