ThreadLocalCounters.jl

ThreadLocalCountersModule

ThreadLocalCounters

Dev CI

ThreadLocalCounters.jl provides a macro @tlc to associate a counter to a code location.

julia> using ThreadLocalCounters

julia> hello_world() = @tlc hello_world;

The installed counters can be enumerated using ThreadLocalCounters.list:

julia> ThreadLocalCounters.list(; all = true)
1-element Vector{ThreadLocalCounters.Internal.ThreadLocalCounter}:
 [0] hello_world @Main #= REPL[2]:2 =#

The thread-local counter is incremented each time the program hits the associated code location:

julia> hello_world();

julia> ThreadLocalCounters.list()
1-element Vector{ThreadLocalCounters.Internal.ThreadLocalCounter}:
 [1] hello_world @Main #= REPL[2]:2 =#

julia> hello_world();

julia> ThreadLocalCounters.list()
1-element Vector{ThreadLocalCounters.Internal.ThreadLocalCounter}:
 [2] hello_world @Main #= REPL[2]:2 =#
source
ThreadLocalCounters.@tlcMacro
@tlc [name]

Count the time this expression is evaluated using thread-local counters.

Examples

julia> using ThreadLocalCounters

julia> hello_world() = @tlc hello_world;
source
ThreadLocalCounters.listFunction
ThreadLocalCounters.list(; all = false)

Get a list of all thread-local counters. The caller must ensure that no thread is accessing the counters.

Pass all = true to include counters with zero counts.

source
ThreadLocalCounters.clearFunction
ThreadLocalCounters.clear()

Reset all counters. The caller must ensure that no thread is accessing the counters.

source