Skip to content

Commit 5eef560

Browse files
committed
ENH: added quiet as well
1 parent e496c5d commit 5eef560

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

memory_profiler.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,9 @@ def memit(self, line='', cell=None):
817817
-c: If present, add the memory usage of any children process to the report.
818818
819819
-o: If present, return a object containing memit run details
820+
821+
-q: If present, be quiet and do not output a result.
822+
820823
Examples
821824
--------
822825
::
@@ -834,7 +837,7 @@ def memit(self, line='', cell=None):
834837
835838
"""
836839
from memory_profiler import memory_usage, _func_exec
837-
opts, stmt = self.parse_options(line, 'r:t:i:co', posix=False, strict=False)
840+
opts, stmt = self.parse_options(line, 'r:t:i:coq', posix=False, strict=False)
838841

839842
if cell is None:
840843
setup = 'pass'
@@ -851,6 +854,7 @@ def memit(self, line='', cell=None):
851854
interval = float(getattr(opts, 'i', 0.1))
852855
include_children = 'c' in opts
853856
return_result = 'o' in opts
857+
quiet = 'q' in opts
854858

855859
# I've noticed we get less noisier measurements if we run
856860
# a garbage collection first
@@ -869,13 +873,14 @@ def memit(self, line='', cell=None):
869873
include_children=include_children)
870874
mem_usage.append(tmp[0])
871875

872-
if mem_usage:
873-
max_mem = max(mem_usage)
874-
print('peak memory: %.02f MiB, increment: %.02f MiB' %
875-
(max_mem, max_mem - baseline))
876-
else:
877-
print('ERROR: could not read memory usage, try with a lower interval '
878-
'or more iterations')
876+
if not quiet:
877+
if mem_usage:
878+
max_mem = max(mem_usage)
879+
print('peak memory: %.02f MiB, increment: %.02f MiB' %
880+
(max_mem, max_mem - baseline))
881+
else:
882+
print('ERROR: could not read memory usage, try with a lower interval '
883+
'or more iterations')
879884

880885
if return_result:
881886
return MemitResult(mem_usage, baseline, repeat, timeout, interval,

0 commit comments

Comments
 (0)