@@ -332,6 +332,7 @@ def read_mprofile_file(filename):
332332 values = value .split (' ' )
333333 f_name , mem_start , start , mem_end , end = values [:5 ]
334334 ts = func_ts .get (f_name , [])
335+ print (f_name , mem_start , start , mem_end , end )
335336 to_append = [float (start ), float (end ), float (mem_start ), float (mem_end )]
336337 if len (values ) >= 6 :
337338 # There is a stack level field
@@ -526,7 +527,7 @@ def level_to_saturation(level):
526527
527528 pl .gca ().grid (True )
528529 timestamp_ax = pl .twinx ()
529- timestamp_ax .set_ylim ((0 , stack_size ))
530+ timestamp_ax .set_ylim ((0 , stack_size + 1 ))
530531 timestamp_ax .grid (False )
531532
532533 # plot children, if any
@@ -564,15 +565,14 @@ def level_to_saturation(level):
564565 x0 -= global_start
565566 x1 -= global_start
566567 color = next (colors [y0 ])
567- rect = add_timestamp_rectangle (
568+ _rect , text = add_timestamp_rectangle (
568569 timestamp_ax ,
569- x0 , x1 , y0 , y1 ,
570+ x0 , x1 , y0 , y1 , f ,
570571 color = color
571572 )
572- rectangles [(x0 , y0 , x1 , y1 )] = f
573+ rectangles [(x0 , y0 , x1 , y1 )] = ( f , text )
573574 func_num += 1
574575
575- label = pl .text (0 , 0 , "" )
576576 def mouse_motion_handler (event ):
577577 x , y = event .xdata , event .ydata
578578 if x is None or y is None :
@@ -581,14 +581,26 @@ def mouse_motion_handler(event):
581581 for rect , func_name in rectangles .items ():
582582 x0 , y0 , x1 , y1 = rect
583583 if x0 < x < x1 and y0 < y < y1 :
584- print (x , y )
585- label .set_position ((x , y ))
586- label .set_text (func_name )
584+ # pl.draw()
585+ return
586+
587+ def mouse_click_handler (event ):
588+ x , y = event .xdata , event .ydata
589+ if x is None or y is None :
590+ return
591+
592+ for rect , func_name in rectangles .items ():
593+ x0 , y0 , x1 , y1 = rect
594+ if x0 < x < x1 and y0 < y < y1 :
595+ toolbar = pl .gcf ().canvas .toolbar
596+ toolbar .push_current ()
597+ timestamp_ax .set_xlim (x0 , x1 )
598+ toolbar .push_current ()
587599 pl .draw ()
588600 return
589- label .set_text ("" )
590601
591602 pl .gcf ().canvas .mpl_connect ('motion_notify_event' , mouse_motion_handler )
603+ pl .gcf ().canvas .mpl_connect ('button_press_event' , mouse_click_handler )
592604
593605 if timestamps :
594606 pl .hlines (max_mem ,
@@ -599,8 +611,13 @@ def mouse_motion_handler(event):
599611 return mprofile
600612
601613
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 )
614+ def add_timestamp_rectangle (ax , x0 , x1 , y0 , y1 , func_name , color = 'none' ):
615+ rect = ax .fill_betweenx ((y0 , y1 ), x0 , x1 , color = color , alpha = 0.5 , linewidth = 1 )
616+ text = ax .text (x0 , y1 , func_name ,
617+ horizontalalignment = 'left' ,
618+ verticalalignment = 'top' ,
619+ )
620+ return rect , text
604621
605622
606623def function_labels (dotted_function_names ):
0 commit comments