From 0b30e046bcd73c4a28fe6c3a80d724cc6d3703d8 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Wed, 19 Mar 2025 15:53:30 -0500 Subject: [PATCH 1/5] Add back `methods_with_generators` (fix #407) (#408) Fix #407 --- src/utils.jl | 16 ++++++++++++++++ test/snoop_inference.jl | 11 +++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/utils.jl b/src/utils.jl index e2335474..77b19a07 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -223,3 +223,19 @@ function split2(str, on) return (SubString(str, firstindex(str), prevind(str, first(i))), SubString(str, nextind(str, last(i)))) end + +function methods_with_generators(m::Module) + meths = Method[] + for name in names(m; all=true) + isdefined(m, name) || continue + f = getfield(m, name) + if isa(f, Function) + for method in methods(f) + if isdefined(method, :generator) + push!(meths, method) + end + end + end + end + return meths +end diff --git a/test/snoop_inference.jl b/test/snoop_inference.jl index 356534f8..6df6a001 100644 --- a/test/snoop_inference.jl +++ b/test/snoop_inference.jl @@ -705,6 +705,10 @@ end @test SnoopCompile.itrigs_higherorder_demo() isa SnoopCompile.InferenceTimingNode end +# must be outside @testset +@generated gen407(x) = x <: Integer ? :(x^2) : :(-x) +callgen407(x) = gen407(x) + include("testmodules/SnoopBench.jl") @testset "parcel" begin a = SnoopBench.A() @@ -784,6 +788,13 @@ include("testmodules/SnoopBench.jl") g197(@nospecialize(x::Vector{<:Number})) = f197(x) g197([1,2,3]) @test SnoopCompile.get_reprs([(rand(), mi) for mi in methodinstances(f197)])[1] isa AbstractSet + + # issue #407 + tinf = @snoop_inference callgen407(3) + tinft = flatten(tinf; tmin=0) + tmi = [(inclusive(inft), Core.MethodInstance(inft)) for inft in tinft] + strs, twritten = SnoopCompile.get_reprs(tmi; tmin=0) + @test any(str -> occursin("which(gen407,(Any,)).generator", str), strs) end @testset "Specialization" begin From 8052ebb85df2d252a090c51d5915fe82d7b0e8d6 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Wed, 19 Mar 2025 16:03:56 -0500 Subject: [PATCH 2/5] [deps]: rm Pkg (fix #371) (#409) --- Project.toml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index b70b9916..e3687233 100644 --- a/Project.toml +++ b/Project.toml @@ -8,7 +8,6 @@ AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" FlameGraphs = "08572546-2f56-4bcf-ba4e-bab62c3a3f89" InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" -Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" Profile = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79" Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b" @@ -40,10 +39,10 @@ PrettyTables = "2" Printf = "1" Profile = "1" PyPlot = "2" +REPL = "1" Random = "1" Serialization = "1" SnoopCompileCore = "3" -REPL = "1" Test = "1" YAML = "0.4" julia = "1.10" @@ -55,8 +54,8 @@ JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" MethodAnalysis = "85b6ec6f-f7df-4429-9514-a64bcd9ee824" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d" -Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] From 519299d81cafff5be354787300e50e617a1d0e00 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Wed, 19 Mar 2025 16:04:21 -0500 Subject: [PATCH 3/5] Use Float16 for % (#410) Fixes #406 --- ext/SCPrettyTablesExt.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ext/SCPrettyTablesExt.jl b/ext/SCPrettyTablesExt.jl index f50b74d9..37f2426a 100644 --- a/ext/SCPrettyTablesExt.jl +++ b/ext/SCPrettyTablesExt.jl @@ -29,8 +29,7 @@ function SnoopCompile.report_invalidations(io::IO = stdout; trunc_msg = truncated_invs ? " (showing $nr functions) " : "" @info "$n_total_invalidations methods invalidated for $n_invs_total functions$trunc_msg" n_invalidations_percent = map(invs_per_method) do inv - inv_perc = inv / sum_invs - Int(round(inv_perc*100, digits = 0)) + Float16(100 * inv / sum_invs) end meth_name = map(trees) do inv "$(inv.method.name)" From 9a864afd08a0099742be63e7e4727a0883741ffd Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Fri, 21 Mar 2025 02:58:40 -0500 Subject: [PATCH 4/5] llvm parsing: filter out `nothing` (#414) Some of the `Dicts` in `llvm_yaml` had entries `"before" => nothing`, and that was breaking parsing. Fixes #405 --- docs/src/tutorials/snoop_llvm.md | 2 +- src/parcel_snoop_llvm.jl | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/src/tutorials/snoop_llvm.md b/docs/src/tutorials/snoop_llvm.md index a1b2eacb..0c8c99ff 100644 --- a/docs/src/tutorials/snoop_llvm.md +++ b/docs/src/tutorials/snoop_llvm.md @@ -25,7 +25,7 @@ using SnoopCompileCore end using SnoopCompile -times, info = SnoopCompile.read_snoop_llvm("func_names.csv", "llvm_timings.yaml", tmin_secs = 0.025); +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: diff --git a/src/parcel_snoop_llvm.jl b/src/parcel_snoop_llvm.jl index 675ea99c..06b10ee9 100644 --- a/src/parcel_snoop_llvm.jl +++ b/src/parcel_snoop_llvm.jl @@ -38,11 +38,15 @@ Dict{String, NamedTuple{(:before, :after), Tuple{NamedTuple{(:instructions, :bas function read_snoop_llvm(func_csv_file, llvm_yaml_file; tmin_secs=0.0) func_csv = _read_snoop_llvm_csv(func_csv_file) llvm_yaml = YAML.load_file(llvm_yaml_file) + filter!(llvm_yaml) do llvm_module + llvm_module["before"] !== nothing + end jl_names = Dict(r[1]::String => r[2]::String for r in func_csv) + # `get`, but with a warning try_get_jl_name(name) = if name in keys(jl_names) - jl_names[name] + jl_names[name] else @warn "Couldn't find $name" name From 98d42a8b1b2fe096231a8afa97b95bbf1e669fd6 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Fri, 21 Mar 2025 06:50:45 -0500 Subject: [PATCH 5/5] Version 3.0.3 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index e3687233..8ff3802e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "SnoopCompile" uuid = "aa65fe97-06da-5843-b5b1-d5d13cad87d2" author = ["Tim Holy ", "Shuhei Kadowaki "] -version = "3.0.2" +version = "3.0.3" [deps] AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"