From 830b9748e91ab44e0c2205db5c4a9321fb130668 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Thu, 23 Apr 2020 03:22:15 +0200 Subject: add verbose opt --- psutil/_common.py | 4 ++-- psutil/tests/__init__.py | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/psutil/_common.py b/psutil/_common.py index 2c327051..ac0f5537 100644 --- a/psutil/_common.py +++ b/psutil/_common.py @@ -785,7 +785,7 @@ def hilite(s, color="green", bold=False): if not term_supports_colors(): return s attr = [] - colors = dict(green='32', red='91', brown='33') + colors = dict(green='32', red='91', brown='33', yellow='93') colors[None] = '29' try: color = colors[color] @@ -812,7 +812,7 @@ def print_color(s, color="green", bold=False, file=sys.stdout, end='\n'): SetConsoleTextAttribute = \ ctypes.windll.Kernel32.SetConsoleTextAttribute - colors = dict(green=2, red=4, brown=6) + colors = dict(green=2, red=4, brown=6, yellow=6) colors[None] = DEFAULT_COLOR try: color = colors[color] diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index 6f4f0343..1d832cd7 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -835,9 +835,11 @@ class TestMemoryLeak(unittest.TestCase): warmup_times = 10 tolerance = 4096 # memory retry_for = 3.0 # seconds + verbose = True def setUp(self): self._thisproc = psutil.Process() + gc.collect() def _get_mem(self): # USS is the closest thing we have to "real" memory usage and it @@ -877,7 +879,8 @@ class TestMemoryLeak(unittest.TestCase): return self._itercall(fun, iterator(secs)) def _log(self, msg): - print_color(msg, color="brown", file=sys.stderr) + if self.verbose: + print_color(msg, color="yellow", file=sys.stderr) def execute(self, fun, times=times, warmup_times=warmup_times, tolerance=tolerance, retry_for=retry_for): @@ -894,13 +897,14 @@ class TestMemoryLeak(unittest.TestCase): # warm up self._call_ntimes(fun, warmup_times) mem1 = self._call_ntimes(fun, times) + if mem1 > tolerance: # This doesn't necessarily mean we have a leak yet. # At this point we assume that after having called the # function so many times the memory usage is stabilized # and if there are no leaks it should not increase # anymore. Let's keep calling fun for N more seconds and - # fail if we notice any difference. + # fail if we notice any difference (ignore tolerance). msg = "+%s after %s calls; try calling fun for another %s secs" % ( bytes2human(mem1), times, retry_for) if not retry_for: -- cgit v1.2.1