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);
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
1-element Vector{Pair{Float64, Vector{String}}}: 0.227199902 => ["Tuple{typeof(LinearAlgebra._generic_matmatmul!), Array{Float64, 2}, Char, Char, Array{Float64, 2}, Array{Float64, 2}, LinearAlgebra.MulAddMul{true, true, Bool, Bool}}"]
julia> info
Dict{String, @NamedTuple{before::@NamedTuple{instructions::Int64, basicblocks::Int64}, after::@NamedTuple{instructions::Int64, basicblocks::Int64}}} with 1 entry: "Tuple{typeof(LinearAlge… => (before = (instructions = 5735, basicblocks = 13…