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.005);
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
7-element Vector{Pair{Float64, Vector{String}}}: 0.006310317 => ["Tuple{typeof(LinearAlgebra.BLAS.gemm!), Char, Char, Float64, Array{Float64, 2}, Array{Float64, 2}, Float64, Array{Float64, 2}}"] 0.00857271 => ["Tuple{typeof(LinearAlgebra.gemm_wrapper!), Array{Float64, 2}, Char, Char, Array{Float64, 2}, Array{Float64, 2}, LinearAlgebra.MulAddMul{true, true, Bool, Bool}}"] 0.009586046 => ["Tuple{typeof(Base.mapreduce_impl), typeof(Base.identity), typeof(Base.min), Array{Float64, 1}, Int64, Int64}"] 0.009626121 => ["Tuple{LinearAlgebra.var\"##peakflops#349\", DataType, Int64, Bool, typeof(LinearAlgebra.peakflops), Int64}"] 0.011206653 => ["Tuple{typeof(LinearAlgebra.matmul2x2!), Array{Float64, 2}, Char, Char, Array{Float64, 2}, Array{Float64, 2}, LinearAlgebra.MulAddMul{true, true, Bool, Bool}}"] 0.011382037 => ["Tuple{typeof(LinearAlgebra.wrap), Array{Float64, 2}, Char}"] 0.020647398 => ["Tuple{typeof(LinearAlgebra.matmul3x3!), 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 7 entries: "Tuple{LinearAlgebra.var… => (before = (instructions = 830, basicblocks = 100… "Tuple{typeof(LinearAlge… => (before = (instructions = 1069, basicblocks = 14… "Tuple{typeof(LinearAlge… => (before = (instructions = 10425, basicblocks = 1… "Tuple{typeof(Base.mapre… => (before = (instructions = 1043, basicblocks = 12… "Tuple{typeof(LinearAlge… => (before = (instructions = 1109, basicblocks = 14… "Tuple{typeof(LinearAlge… => (before = (instructions = 22969, basicblocks = 2… "Tuple{typeof(LinearAlge… => (before = (instructions = 1322, basicblocks = 99…