using EventTracker
function fib(n)
n <= 1 && return n
@recordinterval :fib1 a = fib(n - 1)
@recordinterval :fib2 b = fib(n - 2)
return a + b
end
EventTracker.clear()
fib(10)
df = EventTracker.summary_dataframe()
| ncalls | time | tag | line | file | _module | firstcall | eventkind | locationid |
---|
| Int64 | Float64 | Union…? | Int64? | Union…? | Module? | UInt64 | EventKi… | UInt64 |
---|
2 rows × 9 columns
1 | 88 | 5.65909e-7 | fib1 | 4 | none | Main.ex-fibonacci-serial | 226476430345 | EVENT_INTERVAL | 139935178511776 |
---|
2 | 88 | 3.11364e-7 | fib2 | 5 | none | Main.ex-fibonacci-serial | 226476431145 | EVENT_INTERVAL | 139935178511824 |
---|
using Plots
stks = EventTracker.stacks()
plot(stks)

using EventTracker
function fib(n)
n <= 1 && return n
t = @async begin
rand(Bool) && yield() # introduce more task jugglings
@recordinterval :fib1 fib(n - 1)
end
@recordinterval :fib2 b = fib(n - 2)
return (fetch(t)::Int) + b
end
function withspin(f)
done = Threads.Atomic{Bool}(false)
@sync begin
Threads.@spawn begin
while !done[]
@recordpoint :spin
yield()
end
end
try
f()
finally
done[] = true
end
end
end
function run_fibs_with_spin(nums)
withspin() do
for n in nums
fib(n)
end
end
end
run_fibs_with_spin([5, 6, 7]) # invoke compilation
EventTracker.clear()
run_fibs_with_spin([5, 6, 7])
df = EventTracker.summary_dataframe()
| ncalls | time | tag | line | file | _module | firstcall | eventkind | locationid |
---|
| Int64 | Float64? | Union…? | Int64? | Union…? | Module? | UInt64 | EventKi… | UInt64 |
---|
3 rows × 9 columns
1 | 39 | 1.19899e-5 | fib2 | 8 | none | Main.ex-fibonacci-spin | 263198325977 | EVENT_INTERVAL | 139935166336832 |
---|
2 | 36 | missing | spin | 6 | none | Main.ex-fibonacci-spin | 263198331477 | EVENT_POINT | 139935178695600 |
---|
3 | 39 | 2.06489e-5 | fib1 | 6 | none | Main.ex-fibonacci-spin | 263198335877 | EVENT_INTERVAL | 139935166336784 |
---|
using Plots
stks = EventTracker.stacks()
plot(stks)

Ref: Tak (function) - Wikipedia
using EventTracker
function tarai(x, y, z)
@recordinterval if y < x
tarai(
tarai(x - 1, y, z),
tarai(y - 1, z, x),
tarai(z - 1, x, y),
)
else
@recordpoint
y
end
end
EventTracker.clear()
tarai(3, 1, 7)
df = EventTracker.summary_dataframe()
| ncalls | time | tag | line | file | _module | firstcall | eventkind | locationid |
---|
| Int64 | Float64? | Union…? | Int64? | Union…? | Module? | UInt64 | EventKi… | UInt64 |
---|
2 rows × 9 columns
1 | 461 | 1.17226e-6 | | 3 | none | Main.ex-tarai-serial | 266508886047 | EVENT_INTERVAL | 139934636379824 |
---|
2 | 346 | missing | | 10 | none | Main.ex-tarai-serial | 266508886447 | EVENT_POINT | 139934636380544 |
---|
using Plots
stks = EventTracker.stacks()
plot(stks)
