Last active
December 5, 2022 05:45
-
-
Save aviatesk/54ffa6e99d77e7bd8824e3616961de7f to your computer and use it in GitHub Desktop.
Core.Compiler performance tracking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const CC = Core.Compiler | |
import .CC: MethodInstance, CodeInstance, InferenceResult, WorldRange, WorldView | |
struct CCProfilerCache | |
dict::IdDict{MethodInstance,CodeInstance} | |
end | |
struct CCProfiler <: CC.AbstractInterpreter | |
world::UInt | |
inf_cache::Vector{InferenceResult} | |
code_cache::CCProfilerCache | |
CCProfiler(world = Base.get_world_counter(); | |
inf_cache = InferenceResult[], | |
code_cache = CCProfilerCache(IdDict{MethodInstance,CodeInstance}()) | |
) = new(world, inf_cache, code_cache) | |
end | |
CC.InferenceParams(profiler::CCProfiler) = CC.InferenceParams() | |
CC.OptimizationParams(profiler::CCProfiler) = CC.OptimizationParams() | |
CC.get_world_counter(profiler::CCProfiler) = profiler.world | |
CC.get_inference_cache(profiler::CCProfiler) = profiler.inf_cache | |
CC.code_cache(profiler::CCProfiler) = WorldView(profiler.code_cache, WorldRange(CC.get_world_counter(profiler))) | |
CC.get(wvc::WorldView{<:CCProfilerCache}, mi::MethodInstance, default) = get(wvc.cache.dict, mi, default) | |
CC.getindex(wvc::WorldView{<:CCProfilerCache}, mi::MethodInstance) = getindex(wvc.cache.dict, mi) | |
CC.haskey(wvc::WorldView{<:CCProfilerCache}, mi::MethodInstance) = haskey(wvc.cache.dict, mi) | |
CC.setindex!(wvc::WorldView{<:CCProfilerCache}, ci::CodeInstance, mi::MethodInstance) = setindex!(wvc.cache.dict, ci, mi) | |
# boot up | |
Base.return_types(sin, (Int,); interp=CCProfiler()); | |
# profile | |
using Profile | |
@profile Base.return_types(println, (QuoteNode,); interp=CCProfiler()); | |
Profile.print(; format=:flat, sortedby=:count) | |
Profile.print(; recur=:flat, mincount=10) | |
Profile.Allocs.@profile Base.return_types(println, (QuoteNode,); interp=CCProfiler()); | |
Profile.print(; format=:flat, sortedby=:count) | |
Profile.print(; recur=:flat, mincount=10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment