Skip to content

Commit

Permalink
test_node: get_mem_rss fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoFalke committed Nov 8, 2018
1 parent 11e1ac3 commit fa9ed38
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions test/functional/test_framework/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,19 @@ def get_deterministic_priv_key(self):
def get_mem_rss(self):
"""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):
self.log.warning("Couldn't get memory usage; process isn't running.")
return None
assert self.running

try:
return int(subprocess.check_output(
"ps h -o rss {}".format(self.process.pid),
shell=True, stderr=subprocess.DEVNULL).strip())
["ps", "h", "-o", "rss", "{}".format(self.process.pid)],
stderr=subprocess.DEVNULL).split()[-1])

# Catching `Exception` broadly to avoid failing on platforms where ps
# isn't installed or doesn't work as expected, e.g. OpenBSD.
# Avoid failing on platforms where ps isn't installed.
#
# 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")
return None

Expand Down Expand Up @@ -308,7 +305,7 @@ def assert_memory_usage_stable(self, perc_increase_allowed=0.03):
self.log.warning("Unable to detect memory usage (RSS) - skipping memory check.")
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:
self._raise_assertion_error(
Expand Down

0 comments on commit fa9ed38

Please sign in to comment.