Reference

SnoopCompile.@snoopiMacro
inf_timing = @snoopi commands
inf_timing = @snoopi tmin=0.0 commands

Execute commands while snooping on inference. Returns an array of (t, linfo) tuples, where t is the amount of time spent infering linfo (a MethodInstance).

Methods that take less time than tmin will not be reported.

source
SnoopCompile.@snoopcMacro
@snoopc "compiledata.csv" begin
    # Commands to execute, in a new process
end

causes the julia compiler to log all functions compiled in the course of executing the commands to the file "compiledata.csv". This file can be used for the input to SnoopCompile.read.

source
SnoopCompile.parcelFunction

pc = parcel(calls; subst=[], blacklist=[]) assigns each compile statement to the module that owns the function. Perform string substitution via subst=["Module1"=>"Module2"], and omit functions in particular modules with blacklist=["Module3"]. On output, pc[:Module2] contains all the precompiles assigned to Module2.

Use SnoopCompile.write(prefix, pc) to generate a series of files in directory prefix, one file per module.

source
SnoopCompile.writeFunction
write(prefix::AbstractString, pc::Dict; always::Bool = false)

Write each modules' precompiles to a separate file. If always is true, the generated function will always run the precompile statements when called, otherwise the statements will only be called during package precompilation.

source
SnoopCompile.readFunction

SnoopCompile.read("compiledata.csv") reads the log file produced by the compiler and returns the functions as a pair of arrays. The first array is the amount of time required to compile each function, the second is the corresponding function + types. The functions are sorted in order of increasing compilation time. (The time does not include the cost of nested compiles.)

source
SnoopCompile.format_userimgFunction

pc = format_userimg(calls; subst=[], blacklist=[]) generates precompile directives intended for your base/userimg.jl script. Use SnoopCompile.write(filename, pc) to create a file that you can include into userimg.jl.

source
SnoopCompile.timesumFunction
timesum(snoop)

Calculates and prints the total time measured by a snoop macro.

It is used inside @snoopibench. Julia can cache inference results so to measure the effect of adding _precompile() sentences generated by snoopi to your package, use the @snoopi_bench. This benchmark measures inference time taken during loading and running of a package.

Examples

using SnoopCompile
data = @snoopi begin
    include(joinpath(dirname(dirname(pathof(MatLang))),"test","runtests.jl"))
end;
println(timesum(data));

Manual Benchmark (withtout using @snoopi_bench)

  • dev your package

  • comment the precompile part of your package (include() and _precompile_())

  • run the following benchmark

  • restart Julia

  • uncomment the precompile part of your package (include() and _precompile_())

  • run the following benchmark

  • restart Julia

Benchmark

using SnoopCompile

println("Package load time:")
loadSnoop = @snoopi using MatLang

timesum(loadSnoop)

println("Running Examples/Tests:")
runSnoop = @snoopi begin
    using MatLang
    include(joinpath(dirname(dirname(pathof(MatLang))),"test","runtests.jl"))
end

timesum(runSnoop)
source