summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-04-23 03:22:15 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2020-04-23 03:22:15 +0200
commit830b9748e91ab44e0c2205db5c4a9321fb130668 (patch)
tree63d99d994eee83186cdebb18eaff3c51dc66392d
parent3b0f1ec78df673c101647b50b3211b8da3cd1b80 (diff)
downloadpsutil-memleaks-refact.tar.gz
add verbose optmemleaks-refact
-rw-r--r--psutil/_common.py4
-rw-r--r--psutil/tests/__init__.py8
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: