From 5fe38da926738a7715c860053a498859e2db0c87 Mon Sep 17 00:00:00 2001 From: Fabian Pedregosa Date: Thu, 28 Jun 2018 15:57:01 +0200 Subject: [PATCH] Fixes #195 "large negative increment values" This should fix #195. Increment should reflect the largest increment with respect to the previous line, which is not what the previous code was doing. If run in a for loop, for some reason it was accumulating the increments. I also disabled a test that was assuming that the increment of a function that deletes its temporaries need to be zero, which given the above should not be its behaviour. --- memory_profiler.py | 4 +--- test/test_tracemalloc.py | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/memory_profiler.py b/memory_profiler.py index 9de2ccd..6573e58 100644 --- a/memory_profiler.py +++ b/memory_profiler.py @@ -597,9 +597,7 @@ def trace(self, code, lineno, prev_lineno): prev_line_value = self[code].get(prev_lineno, None) if prev_lineno else None prev_line_memory = prev_line_value[1] if prev_line_value else 0 - #inc = (memory-prev_line_memory) - #print('trace lineno=%(lineno)s prev_lineno=%(prev_lineno)s mem=%(memory)s prev_inc=%(previous_inc)s inc=%(inc)s' % locals()) - self[code][lineno] = (previous_inc + (memory-prev_line_memory), max(memory, previous_memory)) + self[code][lineno] = (max(previous_inc, memory-prev_line_memory), max(memory, previous_memory)) def items(self): """Iterate on the toplevel code blocks.""" diff --git a/test/test_tracemalloc.py b/test/test_tracemalloc.py index 5bedc50..4e8006c 100644 --- a/test/test_tracemalloc.py +++ b/test/test_tracemalloc.py @@ -18,8 +18,6 @@ def test_memory_profiler(test_input, expected): mem_prof(test_input) inc, dec = parse_mem_prof() - assert abs(inc - dec) <= EPSILON, \ - 'inc = {}, dec = {}, err = {}'.format(inc, dec, abs(inc - dec)) assert abs(inc - expected) <= EPSILON, \ 'inc = {}, size = {}, err = {}'.format( inc, expected, abs(inc - expected)