Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect stray clicks in pgdsgui #273

Merged
merged 1 commit into from
Jan 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SnoopCompile"
uuid = "aa65fe97-06da-5843-b5b1-d5d13cad87d2"
author = ["Tim Holy <[email protected]>"]
version = "2.8.1"
version = "2.8.2"

[deps]
Cthulhu = "f68482b8-f384-11e8-15f7-abe071a5a75f"
Expand All @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion SnoopCompileCore/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SnoopCompileCore"
uuid = "e2b509da-e806-4183-be48-004708413034"
author = ["Tim Holy <[email protected]>"]
version = "2.8.0"
version = "2.8.2"

[deps]
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
Expand Down
8 changes: 6 additions & 2 deletions src/visualizations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down