MCPcopy Index your code
hub / github.com/pythonprofilers/memory_profiler / flame_plotter

Function flame_plotter

mprof.py:534–715  ·  view source on GitHub ↗
(filename, index=0, timestamps=True, children=True, options=None)

Source from the content-addressed store, hash-verified

532}
533
534def flame_plotter(filename, index=0, timestamps=True, children=True, options=None):
535 try:
536 import pylab as pl
537 except ImportError as e:
538 print("matplotlib is needed for plotting.")
539 print(e)
540 sys.exit(1)
541 import numpy as np # pylab requires numpy anyway
542 mprofile = read_mprofile_file(filename)
543
544 if len(mprofile['timestamp']) == 0:
545 print('** No memory usage values have been found in the profile '
546 'file.**\nFile path: {0}\n'
547 'File may be empty or invalid.\n'
548 'It can be deleted with "mprof rm {0}"'.format(
549 mprofile['filename']))
550 sys.exit(0)
551
552 # Merge function timestamps and memory usage together
553 ts = mprofile['func_timestamp']
554 t = mprofile['timestamp']
555 mem = mprofile['mem_usage']
556 chld = mprofile['children']
557
558 if len(ts) > 0:
559 for values in ts.values():
560 for v in values:
561 t.extend(v[:2])
562 mem.extend(v[2:4])
563
564 mem = np.asarray(mem)
565 t = np.asarray(t)
566 ind = t.argsort()
567 mem = mem[ind]
568 t = t[ind]
569
570 if ts:
571 stack_size = 1 + max(ex[4] for executions in ts.values() for ex in executions)
572 else:
573 stack_size = 0
574 def level_to_saturation(level):
575 return 1 - 0.75 * level / stack_size
576
577 colors = [
578 itertools.cycle([
579 pl.matplotlib.colors.hsv_to_rgb((0, level_to_saturation(level), 1)),
580 pl.matplotlib.colors.hsv_to_rgb((0.1, level_to_saturation(level), 1)),
581 ]) for level in range(stack_size)
582 ]
583
584 # Plot curves
585 global_start = float(t[0])
586 t = t - global_start
587
588 max_mem = mem.max()
589 max_mem_ind = mem.argmax()
590
591 # cmap = pl.cm.get_cmap('gist_rainbow')

Callers

nothing calls this directly

Calls 5

read_mprofile_fileFunction · 0.85
level_to_saturationFunction · 0.85
function_labelsFunction · 0.85
add_timestamp_rectangleFunction · 0.85
itemsMethod · 0.80

Tested by

no test coverage detected