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

Fix SCPyPlotExt #398

Merged
merged 3 commits into from
Oct 21, 2024
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 docs/src/tutorials/pgdsgui.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Again, this seems appropriate for a language where specialization typically happ

We'll add these packages to your [default environment](https://pkgdocs.julialang.org/v1/environments/) so you can use them while in the package environment:

```
```julia
using Pkg
Pkg.add(["SnoopCompileCore", "SnoopCompile", "PyPlot"]);
```
Expand Down Expand Up @@ -84,7 +84,7 @@ julia> tinf = @snoop_inference mappushes(spelltype, Ts);

Then, *in the same session*, profile the runtime:

```
```julia
julia> using Profile

julia> @profile mappushes(spelltype, Ts);
Expand Down
12 changes: 7 additions & 5 deletions ext/SCPyPlotExt.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
module SCPyPlotExt

import Profile

using SnoopCompile
using SnoopCompile: MethodLoc, InferenceTimingNode, PGDSData, lookups
using PyPlot: PyPlot, plt, PyCall

get_bystr(@nospecialize(by)) = by === inclusive ? "Inclusive" :
by === exclusive ? "Exclusive" : error("unknown ", by)

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...)
function SnoopCompile.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}}() # returned to the user for inspection of clicked methods
function onclick(event)
xc, yc = event.xdata, event.ydata
Expand Down Expand Up @@ -48,18 +50,18 @@ function pgdsgui(ax::PyCall.PyObject, ridata::AbstractVector{Pair{Union{Method,M
return methodref
end

function pgdsgui(ax::PyCall.PyObject, args...; consts::Bool=true, by=inclusive, kwargs...)
function SnoopCompile.pgdsgui(ax::PyCall.PyObject, args...; consts::Bool=true, by=inclusive, kwargs...)
pgdsgui(ax, prep_ri(args...; consts, by, kwargs...); bystr=get_bystr(by), consts, kwargs...)
end

function pgdsgui(args...; kwargs...)
function SnoopCompile.pgdsgui(args...; kwargs...)
fig, ax = plt.subplots()
pgdsgui(ax, args...; kwargs...), ax
end

function prep_ri(tinf::InferenceTimingNode, pdata=Profile.fetch(); lidict=lookups, consts, by, kwargs...)
lookup_firstip!(lookups, pdata)
return runtime_inferencetime(tinf, pdata; lidict, consts, by)
SnoopCompile.lookup_firstip!(lookups, pdata)
return SnoopCompile.runtime_inferencetime(tinf, pdata; lidict, consts, by)
end

end
2 changes: 1 addition & 1 deletion src/SnoopCompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ that method.
`ax` is the pyplot axis of the scatterplot.

!!! compat
`pgdsgui` depends on PyPlot via the Requires.jl package. You must load both SnoopCompile and PyPlot for this function to be defined.
`pgdsgui` depends on PyPlot via Julia extensions. You must load both SnoopCompile and PyPlot for this function to be defined.
"""
function pgdsgui end
export pgdsgui
Expand Down
Loading