diff --git a/Project.toml b/Project.toml index 80ec0a45e..6a23227dd 100644 --- a/Project.toml +++ b/Project.toml @@ -15,15 +15,18 @@ Preferences = "21216c6a-2e73-6563-6e65-726566657250" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [weakdeps] +Cthulhu = "f68482b8-f384-11e8-15f7-abe071a5a75f" Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" [extensions] +JETCthulhuExt = "Cthulhu" ReviseExt = "Revise" [compat] Aqua = "0.8.2" BenchmarkTools = "1.3.2" CodeTracking = "1.3.1" +Cthulhu = "2.12.7" Example = "0.5.3" InteractiveUtils = "1.10" JuliaInterpreter = "0.9" @@ -43,6 +46,7 @@ julia = "1.10" [extras] Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" +Cthulhu = "f68482b8-f384-11e8-15f7-abe071a5a75f" Example = "7876af07-990d-54b4-ab0e-23690620f79a" Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" @@ -52,4 +56,4 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Aqua", "BenchmarkTools", "Example", "Libdl", "Logging", "Random", "Revise", "StaticArrays", "Test"] +test = ["Aqua", "BenchmarkTools", "Cthulhu", "Example", "Libdl", "Logging", "Random", "Revise", "StaticArrays", "Test"] diff --git a/ext/JETCthuhluExt.jl b/ext/JETCthuhluExt.jl new file mode 100644 index 000000000..f13f6fb71 --- /dev/null +++ b/ext/JETCthuhluExt.jl @@ -0,0 +1,25 @@ +module JETCthulhuExt + +using JET: JET, RuntimeDispatchReport, VirtualFrame +using Cthulhu: Cthulhu, Node, Data, callstring +using Core: MethodInstance + +const _emptybackedges = MethodInstance[] + +struct CallFrames + frames::Vector{VirtualFrame} +end + +function Cthulhu.treelist(r::RuntimeDispatchReport) + io = IOBuffer() + cf = CallFrames(r.vst) + frame = r.vst[end] + str = callstring(io, frame.linfo) + Cthulhu.treelist!(Node(Data(str, frame.linfo)), io, cf, "", Base.IdSet{MethodInstance}()) +end + +Cthulhu.instance(cf::CallFrames) = cf.frames[end].linfo +Cthulhu.backedges(cf::CallFrames) = isempty(cf.frames) ? _emptybackedges : [cf.frames[end].linfo] +Cthulhu.nextnode(cf::CallFrames, ::MethodInstance) = CallFrames(cf.frames[1:end-1]) + +end