Library

Documentation for TerminalScope.jl.

TerminalScope.@scopeMacro
@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. delay is the time between two samples and n the sample buffer size, forwarded to Profile.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 the u key re-ranking by allocation counts. expr runs once as a warm-up so compiler allocations stay out of the profile — pass warmup = false when its side effects must happen only once, and consider a lower sample_rate if the profiled run may still compile fresh code.
  • @scope inference expr: Type-inference profile via SnoopCompileCore.@snoop_inference. Run it on code that has not been compiled yet (typically in a fresh session).
  • @scope invalidations expr: Method invalidations caused by expr, typically @scope invalidations using SomePackage.
  • @scope descend f(x, y): Type-instability inspector on the call, like Cthulhu.@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.

source
TerminalScope.scope_profileFunction
scope_profile(g; kwargs...) -> Nothing

Open 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 :dark or :light. See also theme!. (Default: DEFAULT_THEME[])
source
scope_profile(; kwargs...) -> Nothing

Build 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 :dark or :light. See also theme!. (Default: DEFAULT_THEME[])
source
TerminalScope.scope_inferenceFunction
scope_inference(tinf; theme::Symbol = DEFAULT_THEME[]) -> Nothing

Open 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!.

source
TerminalScope.scope_allocsFunction
scope_allocs(results = Profile.Allocs.fetch(); theme::Symbol = DEFAULT_THEME[]) -> Nothing

Open 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.

source
TerminalScope.scope_invalidationsFunction
scope_invalidations(invs) -> Nothing

Open 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.

source
TerminalScope.scope_descendFunction
scope_descend(f, types::Type{<:Tuple} = Tuple{}; theme::Symbol = DEFAULT_THEME[]) -> Nothing

Open 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.

source