Tutorial on @snoop_llvm
Julia uses the LLVM compiler to generate machine code. Typically, the two main contributors to the overall compile time are inference and LLVM, and thus together @snoop_inference
and @snoop_llvm
collect fairly comprehensive data on the compiler.
@snoop_llvm
has a somewhat different design than @snoop_inference
: while @snoop_inference
runs in the same session that you'll be using for analysis (and thus requires that you remember to do the data gathering in a fresh session), @snoop_llvm
spawns a fresh process to collect the data. The downside is that you get less interactivity, as the data have to be written out in intermediate forms as a text file.
Add SnoopCompileCore and SnoopCompile to your environment
Here, we'll add these packages to your default environment.
using Pkg
Pkg.add(["SnoopCompileCore", "SnoopCompile"]);
Collecting the data
Here's a simple demonstration of usage:
julia> using SnoopCompileCore
julia> @snoop_llvm "func_names.csv" "llvm_timings.yaml" begin using InteractiveUtils @eval InteractiveUtils.peakflops() end
Launching new julia process to run commands... done.
julia> using SnoopCompile
julia> times, info = SnoopCompile.read_snoop_llvm("func_names.csv", "llvm_timings.yaml", tmin_secs = 0.025);
ERROR: MethodError: no method matching iterate(::Nothing) The function `iterate` exists, but no method is defined for this combination of argument types. Closest candidates are: iterate(::LaTeXStrings.LaTeXString, ::Int64) @ LaTeXStrings ~/.julia/packages/LaTeXStrings/6NrIG/src/LaTeXStrings.jl:108 iterate(::LaTeXStrings.LaTeXString) @ LaTeXStrings ~/.julia/packages/LaTeXStrings/6NrIG/src/LaTeXStrings.jl:109 iterate(::CompositeException, Any...) @ Base task.jl:55 ...
This will write two files, "func_names.csv"
and "llvm_timings.yaml"
, in your current working directory. Let's look at what was read from these files:
julia> times
ERROR: UndefVarError: `times` not defined in `Main.var"Main"` Suggestion: check for spelling errors or missing imports.
julia> info
ERROR: UndefVarError: `info` not defined in `Main.var"Main"` Suggestion: check for spelling errors or missing imports.