Skip to content

Commit 530eb13

Browse files
author
Armand Foucault
committed
First implementation of label
1 parent 075de73 commit 530eb13

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

mprof.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,20 +555,41 @@ def level_to_saturation(level):
555555
if len(ts) > 0 and timestamps:
556556
func_num = 0
557557
f_labels = function_labels(ts.keys())
558+
rectangles = {}
558559
for f, exec_ts in ts.items():
559560
for execution in exec_ts:
560561
x0, x1 = execution[:2]
561562
y0 = execution[4]
562563
y1 = y0 + 1
564+
x0 -= global_start
565+
x1 -= global_start
563566
color = next(colors[y0])
564-
add_timestamp_rectangle(
567+
rect = add_timestamp_rectangle(
565568
timestamp_ax,
566569
x0, x1, y0, y1,
567-
xshift=global_start,
568570
color=color
569571
)
572+
rectangles[(x0, y0, x1, y1)] = f
570573
func_num += 1
571574

575+
label = pl.text(0, 0, "")
576+
def mouse_motion_handler(event):
577+
x, y = event.xdata, event.ydata
578+
if x is None or y is None:
579+
return
580+
581+
for rect, func_name in rectangles.items():
582+
x0, y0, x1, y1 = rect
583+
if x0 < x < x1 and y0 < y < y1:
584+
print(x, y)
585+
label.set_position((x, y))
586+
label.set_text(func_name)
587+
pl.draw()
588+
return
589+
label.set_text("")
590+
591+
pl.gcf().canvas.mpl_connect('motion_notify_event', mouse_motion_handler)
592+
572593
if timestamps:
573594
pl.hlines(max_mem,
574595
pl.xlim()[0] + 0.001, pl.xlim()[1] - 0.001,
@@ -578,10 +599,8 @@ def level_to_saturation(level):
578599
return mprofile
579600

580601

581-
def add_timestamp_rectangle(ax, x0, x1, y0, y1, *, xshift=0, color='none'):
582-
x0 -= xshift
583-
x1 -= xshift
584-
ax.fill_betweenx((y0, y1), x0, x1, color=color, alpha=0.5, linewidth=1)
602+
def add_timestamp_rectangle(ax, x0, x1, y0, y1, *, color='none'):
603+
return ax.fill_betweenx((y0, y1), x0, x1, color=color, alpha=0.5, linewidth=1)
585604

586605

587606
def function_labels(dotted_function_names):

0 commit comments

Comments
 (0)