Skip to content

Commit 6da24dd

Browse files
author
Armand Foucault
committed
Hiding function names, showing them only on hover
1 parent 7e8efb0 commit 6da24dd

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

mprof.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ def plot_file(filename, index=0, timestamps=True, children=True, options=None):
459459

460460
FLAME_PLOTTER_VARS = {
461461
'hovered_rect': None,
462+
'hovered_text': None,
462463
'alpha': None
463464
}
464465

@@ -498,7 +499,10 @@ def flame_plotter(filename, index=0, timestamps=True, children=True, options=Non
498499
mem = mem[ind]
499500
t = t[ind]
500501

501-
stack_size = 1 + max(ex[4] for executions in ts.values() for ex in executions)
502+
if ts:
503+
stack_size = 1 + max(ex[4] for executions in ts.values() for ex in executions)
504+
else:
505+
stack_size = 0
502506
def level_to_saturation(level):
503507
return 1 - 0.75 * level / stack_size
504508

@@ -588,20 +592,25 @@ def mouse_motion_handler(event):
588592

589593
if FLAME_PLOTTER_VARS['hovered_rect'] is not None:
590594
FLAME_PLOTTER_VARS['hovered_rect'].set_alpha(FLAME_PLOTTER_VARS['alpha'])
595+
FLAME_PLOTTER_VARS['hovered_text'].set_color((0, 0, 0, 0))
591596
FLAME_PLOTTER_VARS['hovered_rect'].set_linewidth(1)
592597

598+
FLAME_PLOTTER_VARS['hovered_text'] = text
593599
FLAME_PLOTTER_VARS['hovered_rect'] = rect
594600
FLAME_PLOTTER_VARS['alpha'] = rect.get_alpha()
595601
FLAME_PLOTTER_VARS['hovered_rect'].set_alpha(0.8)
596602
FLAME_PLOTTER_VARS['hovered_rect'].set_linewidth(3)
603+
FLAME_PLOTTER_VARS['hovered_text'].set_color((0, 0, 0, 1))
597604
pl.draw()
598605
return
599606

600607
if FLAME_PLOTTER_VARS['hovered_rect'] is not None:
608+
FLAME_PLOTTER_VARS['hovered_text'].set_color((0, 0, 0, 0))
601609
FLAME_PLOTTER_VARS['hovered_rect'].set_alpha(FLAME_PLOTTER_VARS['alpha'])
602610
FLAME_PLOTTER_VARS['hovered_rect'].set_linewidth(1)
603611
pl.draw()
604612
FLAME_PLOTTER_VARS['hovered_rect'] = None
613+
FLAME_PLOTTER_VARS['hovered_text'] = None
605614

606615
def mouse_click_handler(event):
607616
x, y = event.xdata, event.ydata
@@ -638,6 +647,7 @@ def add_timestamp_rectangle(ax, x0, x1, y0, y1, func_name, color='none'):
638647
text = ax.text(x0, y1, func_name,
639648
horizontalalignment='left',
640649
verticalalignment='top',
650+
color=(0, 0, 0, 0)
641651
)
642652
return rect, text
643653

0 commit comments

Comments
 (0)