@@ -280,10 +280,10 @@ def memory_usage(proc=-1, interval=.1, timeout=None, timestamps=False,
280280 to this file instead of stored in memory and returned at the end of
281281 the subprocess. Useful for long-running processes.
282282 Implies timestamps=True.
283-
283+
284284 max_iterations : int
285285 Limits the number of iterations (calls to the process being monitored). Relevent
286- when the process is a python function.
286+ when the process is a python function.
287287
288288 Returns
289289 -------
@@ -357,7 +357,7 @@ def memory_usage(proc=-1, interval=.1, timeout=None, timestamps=False,
357357 raise
358358
359359 p .join (5 * interval )
360-
360+
361361 if (n_measurements > 4 ) or (current_iter == max_iter ) or (interval < 1e-6 ):
362362 break
363363 interval /= 10.
@@ -643,7 +643,12 @@ def trace(self, code, lineno, prev_lineno):
643643
644644 prev_line_value = self [code ].get (prev_lineno , None ) if prev_lineno else None
645645 prev_line_memory = prev_line_value [1 ] if prev_line_value else 0
646- self [code ][lineno ] = (max (previous_inc , memory - prev_line_memory ), max (memory , previous_memory ))
646+ occ_count = self [code ][lineno ][2 ] + 1 if lineno in self [code ] else 1
647+ self [code ][lineno ] = (
648+ previous_inc + (memory - prev_line_memory ),
649+ max (memory , previous_memory ),
650+ occ_count ,
651+ )
647652
648653 def items (self ):
649654 """Iterate on the toplevel code blocks."""
@@ -800,10 +805,10 @@ def disable(self):
800805def show_results (prof , stream = None , precision = 1 ):
801806 if stream is None :
802807 stream = sys .stdout
803- template = '{0:>6} {1:>12} {2:>12} {3 :<}'
808+ template = '{0:>6} {1:>12} {2:>12} {3:>10} {4 :<}'
804809
805810 for (filename , lines ) in prof .code_map .items ():
806- header = template .format ('Line #' , 'Mem usage' , 'Increment' ,
811+ header = template .format ('Line #' , 'Mem usage' , 'Increment' , 'Occurences' ,
807812 'Line Contents' )
808813
809814 stream .write (u'Filename: ' + filename + '\n \n ' )
@@ -817,13 +822,15 @@ def show_results(prof, stream=None, precision=1):
817822 for (lineno , mem ) in lines :
818823 if mem :
819824 inc = mem [0 ]
820- mem = mem [1 ]
821- mem = template_mem .format (mem )
825+ total_mem = mem [1 ]
826+ total_mem = template_mem .format (total_mem )
827+ occurences = mem [2 ]
822828 inc = template_mem .format (inc )
823829 else :
824- mem = u''
830+ total_mem = u''
825831 inc = u''
826- tmp = template .format (lineno , mem , inc , all_lines [lineno - 1 ])
832+ occurences = u''
833+ tmp = template .format (lineno , total_mem , inc , occurences , all_lines [lineno - 1 ])
827834 stream .write (to_str (tmp ))
828835 stream .write (u'\n \n ' )
829836
0 commit comments