Library
Documentation for TerminalScope.jl.
TerminalScope.@scope — Macro
@scope([mode,] [options...,] expr)Analyze expr and open the interactive terminal viewer with the result. The first argument selects the analysis; without it, expr runs under the sampling profiler.
Modes
@scope [delay = seconds] [n = samples] expr: Runtime profile.delayis the time between two samples andnthe sample buffer size, forwarded toProfile.init(they persist for the session). The compilation time of the run is shown in the header.@scope allocs [sample_rate = 1.0] [warmup = true] expr: Allocation profile, ranked by bytes with theukey re-ranking by allocation counts.exprruns once as a warm-up so compiler allocations stay out of the profile — passwarmup = falsewhen its side effects must happen only once, and consider a lowersample_rateif the profiled run may still compile fresh code.@scope inference expr: Type-inference profile viaSnoopCompileCore.@snoop_inference. Run it on code that has not been compiled yet (typically in a fresh session).@scope invalidations expr: Method invalidations caused byexpr, typically@scope invalidations using SomePackage.@scope descend f(x, y): Type-instability inspector on the call, likeCthulhu.@descend. The call is not executed; only its argument types are used.
The value of expr is discarded (except by descend, which never runs it). The corresponding function forms — scope_profile, scope_allocs, scope_inference, scope_invalidations, and scope_descend — open the viewer on already-collected data.
TerminalScope.scope_profile — Function
scope_profile(g; kwargs...) -> NothingOpen the interactive terminal viewer for the flame graph rooted at g, a node returned by FlameGraphs.flamegraph. The viewer takes over the terminal until the user quits with the q key.
Keywords
compile::Union{CompileStats, Nothing}: Compilation measurements of the profiled expression, shown in the header when available. (Default:nothing)theme::Symbol: Theme variant, either:darkor:light. See alsotheme!. (Default:DEFAULT_THEME[])
scope_profile(; kwargs...) -> NothingBuild the flame graph from the current Profile data and open the interactive terminal viewer. Print a warning and return without opening the viewer when no profile data is available.
Keywords
compile::Union{CompileStats, Nothing}: Compilation measurements of the profiled expression, shown in the header when available. (Default:nothing)theme::Symbol: Theme variant, either:darkor:light. See alsotheme!. (Default:DEFAULT_THEME[])
TerminalScope.scope_inference — Function
scope_inference(tinf; theme::Symbol = DEFAULT_THEME[]) -> NothingOpen the interactive terminal viewer for the inference timing tree tinf returned by SnoopCompileCore.@snoop_inference, with the frame costs shown as inference plus LLVM compilation times. The viewer takes over the terminal until the user quits with the q key. theme selects the :dark or :light variant; see also theme!.
TerminalScope.scope_allocs — Function
scope_allocs(results = Profile.Allocs.fetch(); theme::Symbol = DEFAULT_THEME[]) -> NothingOpen the interactive terminal viewer for the allocation profile results returned by Profile.Allocs.fetch(). The tree shows where memory was allocated, ranked by allocated bytes; the u key re-ranks it by number of allocations. Descending past the deepest frame lists the allocated types. When the profile was collected with a sample rate below 1.0, the shown bytes and counts are the recorded fraction, not the totals. The viewer takes over the terminal until the user quits with the q key. theme selects the :dark or :light variant; see also theme!.
See also @scope.
TerminalScope.scope_invalidations — Function
scope_invalidations(invs) -> NothingOpen the interactive terminal viewer for the method invalidations invs, either the raw data returned by SnoopCompileCore.@snoop_invalidations or the trees returned by SnoopCompile.invalidation_trees. The first level lists the methods whose definition triggered invalidations; descending shows the invalidated specializations and, recursively, the callers invalidated through them. The i key opens the type-instability inspector on the selected instance. The viewer takes over the terminal until the user quits with the q key. theme selects the :dark or :light variant; see also theme!.
Organizing raw invalidation data requires SnoopCompile, which is loaded on the first use (its load-time invalidations do not affect sessions that only use the profilers). When it cannot be loaded, a warning is printed and the raw data is returned so it can be viewed later.
See also @scope.
TerminalScope.scope_descend — Function
scope_descend(f, types::Type{<:Tuple} = Tuple{}; theme::Symbol = DEFAULT_THEME[]) -> NothingOpen the interactive type-instability inspector on the method of f specialized for the argument types types, similar to Cthulhu.descend. The inspector shows the source code annotated with the inferred types, colored by type stability, and the call sites of the method, which can be descended into with the Enter key. The viewer takes over the terminal until the user quits with the q key. theme selects the :dark or :light variant; see also theme!.
The inspector requires Cthulhu, which is loaded on the first use (its load-time invalidations do not affect sessions that only use the profilers).
See also @scope.