From 64a368457e5a8aa6e725bd0b56dd6a0309be5039 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Sat, 22 Jan 2022 06:42:07 -0600 Subject: [PATCH] Detect stray clicks in pgdsgui Fixes #269 --- Project.toml | 4 ++-- SnoopCompileCore/Project.toml | 2 +- src/visualizations.jl | 8 ++++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Project.toml b/Project.toml index 25f2e793..8934faa2 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "SnoopCompile" uuid = "aa65fe97-06da-5843-b5b1-d5d13cad87d2" author = ["Tim Holy "] -version = "2.8.1" +version = "2.8.2" [deps] Cthulhu = "f68482b8-f384-11e8-15f7-abe071a5a75f" @@ -21,7 +21,7 @@ Cthulhu = "1.5, 2" FlameGraphs = "0.2" OrderedCollections = "1" Requires = "1" -SnoopCompileCore = "~2.8.0" +SnoopCompileCore = "~2.8.2" YAML = "0.4" julia = "1" diff --git a/SnoopCompileCore/Project.toml b/SnoopCompileCore/Project.toml index bdfd36bc..8bf386d9 100644 --- a/SnoopCompileCore/Project.toml +++ b/SnoopCompileCore/Project.toml @@ -1,7 +1,7 @@ name = "SnoopCompileCore" uuid = "e2b509da-e806-4183-be48-004708413034" author = ["Tim Holy "] -version = "2.8.0" +version = "2.8.2" [deps] Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b" diff --git a/src/visualizations.jl b/src/visualizations.jl index 38b288d8..b404da70 100644 --- a/src/visualizations.jl +++ b/src/visualizations.jl @@ -26,15 +26,18 @@ that method. `pgdsgui` depends on PyPlot via the Requires.jl package. You must load both SnoopCompile and PyPlot for this function to be defined. """ function pgdsgui(ax::PyCall.PyObject, ridata::AbstractVector{Pair{Union{Method,MethodLoc},PGDSData}}; bystr, consts, markersz=25, linewidth=0.5, t0 = 0.001, interactive::Bool=true, kwargs...) - methodref = Ref{Union{Method,MethodLoc}}() + methodref = Ref{Union{Method,MethodLoc}}() # returned to the user for inspection of clicked methods function onclick(event) xc, yc = event.xdata, event.ydata + (xc === nothing || yc === nothing) && return + # Find dot closest to the click position idx = argmin((log.(rts .+ t0) .- log(xc)).^2 + (log.(its .+ t0) .- log(yc)).^2) m = meths[idx] - methodref[] = m + methodref[] = m # store the clicked method println(m, " ($(nspecs[idx]) specializations)") end + # Unpack the inputs into a form suitable for plotting meths, rts, its, nspecs, ecols = Union{Method,MethodLoc}[], Float64[], Float64[], Int[], Tuple{Float64,Float64,Float64}[] for (m, d) in ridata # (rt, trtd, it, nspec) push!(meths, m) @@ -46,6 +49,7 @@ function pgdsgui(ax::PyCall.PyObject, ridata::AbstractVector{Pair{Union{Method,M sp = sortperm(nspecs) meths, rts, its, nspecs, ecols = meths[sp], rts[sp], its[sp], nspecs[sp], ecols[sp] + # Plot # Add t0 to each entry to handle times of zero in the log-log plot smap = ax.scatter(rts .+ t0, its .+ t0, markersz, nspecs; norm=plt.matplotlib.colors.LogNorm(), edgecolors=ecols, linewidths=linewidth, kwargs...) ax.set_xscale("log")