Function Repository Resource:

FlameChart

Source Notebook

Visualize data as a flame chart

Contributed by: Wolfram Staff

ResourceFunction["FlameChart"][d]

generates an interactive flame chart of the nested data d.

Details and Options

Data d for the label l0, with the associated weight w0, must be in the form {l0,w0,{d1,}}, where each di for ancilliaries li must in turn be in the same form {li,wi,{di1,}}.
For profiler data, labels can refer to function tags fi and weights to execution times ti, with wider frames corresponding to functions taking more time.
ResourceFunction["FlameChart"] sorts data at each level and combines multiple occurances of the same label in a single frame.
Frames are arranged along the horizontal axis, while the vertical axis shows the stack depth, starting from the originator at the bottom.
Hovering over a frame displays a tooltip with the percentage of that frame's weight.
ResourceFunction["FlameChart"] accepts the option ColorFunction that generates frame colors. The default is RandomColor[RGBColor[1,_,_]]&.
ResourceFunction["FlameChart"] also takes the options of Graphics.
Clicking the frame restricts the flame chart to the stack originating at the frame.
or resets the flame chart.

Examples

Basic Examples (3) 

Create a flame chart of nested profiler data:

In[1]:=
ResourceFunction[
 "FlameChart"][{fun1, 0.5, {{fun2, 0.1, {}}, {fun3, 0.3, {{fun4, 0.2, {{fun5, 0.05, {}}, {fun6, 0.05, {{fun7, 0.04, {}}}}}}}}}}]
Out[1]=

Click a frame, for instance fun3, to show only its stack:

any frame to reset the chart:

Scope (2) 

Frames are sorted at each level in the canonical order of their labels:

In[2]:=
ResourceFunction[
 "FlameChart"][{fun1, 0.3, {{fun3, 0.1, {{fun32, 0.05, {}}, {fun31, 0.025, {}}}}, {fun2, 0.1, {{fun5b, .04, {}}, {fun5a, .04, {}}}}}}]
Out[2]=

Frames corresponding to the same label are merged:

In[3]:=
ResourceFunction[
 "FlameChart"][{fun1, 0.3, {{fun3, 0.1, {{fun2, 0.025, {}}, {fun1, 0.025, {}}, {fun2, 0.025, {}}}}, {fun2, 0.1, {}}, {fun3, 0.1, {}}}}]
Out[3]=

Options (2) 

ColorFunction (2) 

Apply a different color function to the chart:

In[4]:=
ResourceFunction[
 "FlameChart"][{fun1, 0.3, {{fun3, 0.1, {{fun2, 0.025, {}}, {fun1, 0.025, {}}}}, {fun2, 0.1, {}}}}, ColorFunction -> (Hue[RandomReal[]] &)]
Out[4]=

Use the specified color palette:

In[5]:=
ResourceFunction[
 "FlameChart"][{fun1, 0.3, {{fun3, 0.1, {{fun2, 0.025, {}}, {fun1, 0.025, {}}}}, {fun2, 0.1, {}}}}, ColorFunction -> "BlueGreenYellow"]
Out[5]=

Version History

  • 1.0.0 – 04 May 2020

Author Notes

The function ought to have a ProfileAccumulatingFunction option (or some such) to convert to the canonical nested form other types of profile data, for instance, a flat list {{function1,"enter",time1},{function2,"enter",time2},{function2,"exit",time3}{function3,"enter",time4},{function3,"exit",time5},{function1,"exit",time6}}, event series data, etc.
It also needs a way to truncate displayed labels to fit into corresponding frames or omit labels altogether in shorter frames.

License Information