Skip to content

Commit 0c5f6f7

Browse files
committed
Addressing @superbobry's comments
1 parent 5eef560 commit 0c5f6f7

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

memory_profiler.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,13 @@ def __init__(self, mem_usage, baseline, repeat, timeout, interval,
6363
self.interval = interval
6464
self.include_children = include_children
6565

66-
def _repr_pretty_(self, p , cycle):
66+
def __str__(self):
6767
max_mem = max(self.mem_usage)
6868
inc = max_mem - self.baseline
69-
msg = 'peak memory: %.02f MiB, increment: %.02f MiB' % (max_mem, inc)
69+
return 'peak memory: %.02f MiB, increment: %.02f MiB' % (max_mem, inc)
7070

71+
def _repr_pretty_(self, p , cycle):
72+
msg = str(self)
7173
p.text(u'<MemitResult : '+msg+u'>')
7274

7375

@@ -873,18 +875,18 @@ def memit(self, line='', cell=None):
873875
include_children=include_children)
874876
mem_usage.append(tmp[0])
875877

878+
result = MemitResult(mem_usage, baseline, repeat, timeout, interval,
879+
include_children)
880+
876881
if not quiet:
877882
if mem_usage:
878-
max_mem = max(mem_usage)
879-
print('peak memory: %.02f MiB, increment: %.02f MiB' %
880-
(max_mem, max_mem - baseline))
883+
print(result)
881884
else:
882885
print('ERROR: could not read memory usage, try with a lower interval '
883886
'or more iterations')
884887

885888
if return_result:
886-
return MemitResult(mem_usage, baseline, repeat, timeout, interval,
887-
include_children)
889+
return result
888890

889891
@classmethod
890892
def register_magics(cls, ip):

0 commit comments

Comments
 (0)