Reference
TrackingTimers.TrackingTimerTrackingTimers.TrackingTimerTrackingTimers.synchronize!TrackingTimers.@timeit
TrackingTimers.TrackingTimer — TypeTrackingTimerStores the results of @timed calls in a RemoteChannel to provide a distributed and thread-friendly way to collect timing results. Construct a TrackingTimer by t = TrackingTimer(). Populate it by TrackingTimers.@timeit or call t on a function (optionally providing a name) to obtain an InstrumentedFunction, which automatically populates t with timing results whenever it is called.
TrackingTimer's support the Tables.jl row table interface. Call Tables.rows(t) to obtain a Vector{NamedTuple{(:name, :time, :gctime, :n_allocs, :bytes, :thread_id, :pid), Tuple{String, Float64, Float64, Int64, Int64, Int64, Int64}}} of the timing results obtained so far. Note that this uses a lock (via synchronize!) so it should be thread-safe albeit may cause contention if called from multiple threads simultaneously.
Example
julia> using Distributed
julia> addprocs(2);
julia> @everywhere using TrackingTimers
julia> t = TrackingTimer()
TrackingTimer: 1.09 s since creation (0% measured).
No entries.
julia> @everywhere function f(i)
v = 1:(1000*myid())
return sum( v .^ (1/π))
end
julia> f_inst = t(f) # instrument `f` with TrackingTimer `t`
(::TrackingTimers.InstrumentedFunction{typeof(f)}) (generic function with 1 method)
julia> pmap(f_inst, 1:10)
10-element Vector{Float64}:
17056.850202253918
29106.968991882364
29106.968991882364
17056.850202253918
17056.850202253918
29106.968991882364
17056.850202253918
29106.968991882364
17056.850202253918
29106.968991882364
julia> t
TrackingTimer: 2.54 s since creation (0% measured).
name time gcfraction n_allocs allocs thread ID proc ID
────────────────────────────────────────────────────────────────
f 0.00 s 0% 2 23.516 KiB 1 3
f 0.00 s 0% 1 15.750 KiB 1 2
f 0.00 s 0% 2 23.516 KiB 1 3
f 0.00 s 0% 2 23.516 KiB 1 3
f 0.00 s 0% 2 23.516 KiB 1 3
f 0.00 s 0% 2 23.516 KiB 1 3
f 0.00 s 0% 1 15.750 KiB 1 2
f 0.00 s 0% 1 15.750 KiB 1 2
f 0.00 s 0% 1 15.750 KiB 1 2
f 0.00 s 0% 1 15.750 KiB 1 2TrackingTimers.TrackingTimer — Type(t::TrackingTimer)(f, name=string(repr(f))) -> InstrumentedFunctionInstruments f by the TrackingTimer t returning an InstrumentedFunction. This function can be used just like f, but whenever it is called it stores timing results in t.
TrackingTimers.synchronize! — Methodsynchronize!(t::TrackingTimer)Populates t.results with any timing results collected so far. This uses a lock so it is safe to call from multiple threads, but may cause contention. Called automatically by Tables.rows(::TrackingTimer).
TrackingTimers.@timeit — Macro@timeit(t::TrackingTimer, name, expr)Evaluates expr under @timed, storing the results in the TrackingTimer t.