@@ -118,22 +118,19 @@ def get_deterministic_priv_key(self):
118
118
def get_mem_rss (self ):
119
119
"""Get the memory usage (RSS) per `ps`.
120
120
121
- If process is stopped or `ps` is unavailable, return None .
121
+ Returns None if `ps` is unavailable.
122
122
"""
123
- if not (self .running and self .process ):
124
- self .log .warning ("Couldn't get memory usage; process isn't running." )
125
- return None
123
+ assert self .running
126
124
127
125
try :
128
126
return int (subprocess .check_output (
129
- "ps h -o rss {}" .format (self .process .pid ),
130
- shell = True , stderr = subprocess .DEVNULL ).strip () )
127
+ [ "ps" , "h" , "-o" , " rss" , " {}" .format (self .process .pid )] ,
128
+ stderr = subprocess .DEVNULL ).split ()[ - 1 ] )
131
129
132
- # Catching `Exception` broadly to avoid failing on platforms where ps
133
- # isn't installed or doesn't work as expected, e.g. OpenBSD.
130
+ # Avoid failing on platforms where ps isn't installed.
134
131
#
135
132
# We could later use something like `psutils` to work across platforms.
136
- except Exception :
133
+ except ( FileNotFoundError , subprocess . SubprocessError ) :
137
134
self .log .exception ("Unable to get memory usage" )
138
135
return None
139
136
@@ -308,7 +305,7 @@ def assert_memory_usage_stable(self, perc_increase_allowed=0.03):
308
305
self .log .warning ("Unable to detect memory usage (RSS) - skipping memory check." )
309
306
return
310
307
311
- perc_increase_memory_usage = 1 - ( float ( before_memory_usage ) / after_memory_usage )
308
+ perc_increase_memory_usage = ( after_memory_usage / before_memory_usage ) - 1
312
309
313
310
if perc_increase_memory_usage > perc_increase_allowed :
314
311
self ._raise_assertion_error (
0 commit comments