@@ -491,6 +491,7 @@ def flame_plotter(filename, index=0, timestamps=True, children=True, options=Non
491491 ind = t .argsort ()
492492 mem = mem [ind ]
493493 t = t [ind ]
494+ stack_size = 1 + max (ex [4 ] for executions in ts .values () for ex in executions )
494495
495496 # Plot curves
496497 global_start = float (t [0 ])
@@ -499,7 +500,7 @@ def flame_plotter(filename, index=0, timestamps=True, children=True, options=Non
499500 max_mem = mem .max ()
500501 max_mem_ind = mem .argmax ()
501502
502- all_colors = ( "c" , "y" , "g" , "r" , "b" )
503+ cmap = pl . cm . get_cmap ( 'gist_rainbow' )
503504 mem_line_colors = ("k" , "b" , "r" , "g" , "c" , "y" , "m" )
504505 mem_line_label = time .strftime ("%d / %m / %Y - start at %H:%M:%S" ,
505506 time .localtime (global_start )) \
@@ -512,6 +513,9 @@ def flame_plotter(filename, index=0, timestamps=True, children=True, options=Non
512513 bottom += 0.001
513514 top -= 0.001
514515
516+ timestamp_ax = pl .twinx ()
517+ timestamp_ax .set_ylim ((0 , stack_size ))
518+
515519 # plot children, if any
516520 if len (chld ) > 0 and children :
517521 cmpoint = (0 ,0 ) # maximal child memory
@@ -540,10 +544,16 @@ def flame_plotter(filename, index=0, timestamps=True, children=True, options=Non
540544 f_labels = function_labels (ts .keys ())
541545 for f , exec_ts in ts .items ():
542546 for execution in exec_ts :
543- add_brackets (execution [:2 ], execution [2 :], xshift = global_start ,
544- color = all_colors [func_num % len (all_colors )],
545- label = f_labels [f ]
546- + " %.3fs" % (execution [1 ] - execution [0 ]), options = options )
547+ x0 , x1 = execution [:2 ]
548+ y0 = execution [4 ]
549+ y1 = y0 + 1
550+ color = cmap (0.5 )
551+ add_timestamp_rectangle (
552+ timestamp_ax ,
553+ x0 , x1 , y0 , y1 ,
554+ xshift = global_start ,
555+ color = color
556+ )
547557 func_num += 1
548558
549559 if timestamps :
@@ -555,6 +565,14 @@ def flame_plotter(filename, index=0, timestamps=True, children=True, options=Non
555565 return mprofile
556566
557567
568+ def add_timestamp_rectangle (ax , x0 , x1 , y0 , y1 , * , xshift = 0 , color = 'none' ):
569+ x0 -= xshift
570+ x1 -= xshift
571+ print (f"Drawing rectangle ({ x0 } , { y0 } , { x1 } , { y1 } )" )
572+ print (color )
573+ ax .fill_betweenx ((y0 , y1 ), x0 , x1 , color = color , alpha = 0.5 , linewidth = 1 )
574+
575+
558576def function_labels (dotted_function_names ):
559577 state = {}
560578
0 commit comments