Function Repository Resource:

StackTicker

Source Notebook

Display information from the evaluation stack during long-running evaluations

Contributed by: Lou D'Andria

ResourceFunction["StackTicker"][expr]

displays a stack ticker while the given expression is evaluating.

ResourceFunction["StackTicker"]["On"]

displays a stack ticker for every input in the kernel session.

Details and Options

StackTicker requires a notebook front end.
ResourceFunction["StackTicker"][expr] prints a temporary stack ticker cell which shows the heads of the expressions on the evaluation stack during the evaluation of expr, updating every few seconds.
ResourceFunction["StackTicker"][expr] returns the result of evaluating expr.
StackTicker["On"] displays the stack ticker for every input in that kernel session, by setting the values of $Pre and $Post appropriately.
StackTicker["Off"] turns off the session stack ticker, unsetting the values of $Pre and $Post.
StackTicker supports the following options:
BaseStyle{ }base style specifications for the stack ticker
"CommonHeads"Automaticcommon heads to be excluded from the stack ticker
"InitialDelay"3how long to delay before the stack ticker is shown
"RemoveCommonHeads"Truewhether to remove common heads from the stack ticker
"ShowWarning"Falsewhether to show a warning before showing the stack ticker
UpdateInterval3time interval at which to do updates
The Automatic setting for "CommonHeads" is equivalent to {Association,Block,CompoundExpression,List,Module,Quiet,Rule,Set,With}.
If expr evaluates more quickly than the value of "InitialDelay", the stack ticker will not appear.
StackTicker uses PrintTemporary to create its display, which is deleted when the evaluation completes.
StackTicker uses preemptive calls to Stack[ ] to retrieve the information it displays.
ResourceFunction["StackTicker"] uses ScheduledTask and Dynamic to manage the delay and updates.
StackTicker has the attribute HoldFirst.

Examples

Basic Examples (2) 

Show the heads of the expressions on the evaluation stack every few seconds during a long running evaluation:

In[1]:=
Do[f[i][Pause[1]], {i, 10}] // ResourceFunction["StackTicker"]

Use a stack ticker to watch how functions written in Wolfram Language evaluate:

In[2]:=
TimeConstrained[Integrate[1/Sqrt[x^3 + 3 a x + b], {x, a1, a2}], 20] // ResourceFunction["StackTicker"]
Out[2]=

Scope (3) 

Show a stack ticker automatically for every long evaluation for the remainder of this kernel session:

In[3]:=
ResourceFunction["StackTicker"]["On"]

Run an evaluation that takes a while:

In[4]:=
RecurrenceTable[{a[n + 1] == (a[n] + b[n])/2, b[n + 1] == (2/(1/a[n] + 1/b[n])), a[0] == 4, b[0] == 3}, {a, b}, {n, 0, 25}] // Dimensions
Out[4]=

Turn off the automatic session stack ticker:

In[5]:=
ResourceFunction["StackTicker"]["Off"]

Options (8) 

BaseStyle (2) 

Change the display of a particular stack ticker:

In[6]:=
ResourceFunction["StackTicker"][Pause[10], BaseStyle -> {Magnification -> 1.25, FontFamily -> "Courier"}]

Change the display of the session stack tickers:

In[7]:=
ResourceFunction["StackTicker"]["On", BaseStyle -> {FontSize -> 14, FontColor -> White, FrameBoxOptions -> {Background -> Darker @ Gray, FrameStyle -> Black}}]
In[8]:=
ResourceFunction["StackTicker"]["Off"]

CommonHeads (2) 

Hide certain heads from the stack ticker:

In[9]:=
ResourceFunction["StackTicker"][Do[Pause[1], 10], "CommonHeads" -> {Do, Block}]

Hide all heads from the stack ticker:

In[10]:=
ResourceFunction["StackTicker"][Do[Pause[1], 10], "CommonHeads" -> {_}]

InitialDelay (1) 

Display the stack ticker after one second:

In[11]:=
ResourceFunction["StackTicker"][Do[f[i][Pause[1]], {i, 10}], "InitialDelay" -> 1]

RemoveCommonHeads (1) 

Turn off removal of heads specified by the option "CommonHeads":

In[12]:=
ResourceFunction["StackTicker"][Do[f[i][Pause[1]], {i, 10}], "RemoveCommonHeads" -> False]

ShowWarning (1) 

Show a warning instead of immediately showing the stack ticker when an evaluation takes longer than "InitialDelay":

In[13]:=
ResourceFunction["StackTicker"][Do[f[i][Pause[1]], {i, 10}], "ShowWarning" -> True]

UpdateInterval (1) 

Update the stack ticker contents every second:

In[14]:=
ResourceFunction["StackTicker"][Do[f[i][Pause[1]], {i, 10}], UpdateInterval -> 1]

Properties and Relations (1) 

Use StackInhibit to hide stack information from Stack and StackTicker:

In[15]:=
ResourceFunction["StackTicker"][f[Pause[5]]; StackInhibit[g[Pause[5]]]; h[Pause[5]]; "done"]
Out[15]=

Possible Issues (1) 

StackTicker cannot update while an evaluation is within the scope of a PreemptProtect:

In[16]:=
PreemptProtect[Table[Pause[1]; i + 1, {i, 10}]] // ResourceFunction[
 "StackTicker"]
Out[16]=

Publisher

Lou D'Andria

Version History

  • 1.0.0 – 09 December 2022

Related Resources

License Information