@@ -118,22 +118,19 @@ def get_deterministic_priv_key(self):
118118 def get_mem_rss (self ):
119119 """Get the memory usage (RSS) per `ps`.
120120
121- If process is stopped or `ps` is unavailable, return None .
121+ Returns None if `ps` is unavailable.
122122 """
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
126124
127125 try :
128126 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 ] )
131129
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.
134131 #
135132 # We could later use something like `psutils` to work across platforms.
136- except Exception :
133+ except ( FileNotFoundError , subprocess . SubprocessError ) :
137134 self .log .exception ("Unable to get memory usage" )
138135 return None
139136
@@ -308,7 +305,7 @@ def assert_memory_usage_stable(self, perc_increase_allowed=0.03):
308305 self .log .warning ("Unable to detect memory usage (RSS) - skipping memory check." )
309306 return
310307
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
312309
313310 if perc_increase_memory_usage > perc_increase_allowed :
314311 self ._raise_assertion_error (
0 commit comments