Skip to content

Commit dfed0cb

Browse files
Fix SCPyPlotExt (#398)
The `SCPyPlotExt` had two problems: - the default argument to `pdata` is `Profile.fetch()`, but `Profile` was not imported - the extension was not adding methods to `SnoopCompile.pgdsgui` As a result, the tutorial on `pgdsgui` was broken. This commit fixes both of these issues. It also fixes syntax highlighting in pgdsgui tutorial --------- Co-authored-by: Charles Kawczynski <[email protected]>
1 parent 2ecfc9a commit dfed0cb

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

docs/src/tutorials/pgdsgui.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Again, this seems appropriate for a language where specialization typically happ
2626

2727
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:
2828

29-
```
29+
```julia
3030
using Pkg
3131
Pkg.add(["SnoopCompileCore", "SnoopCompile", "PyPlot"]);
3232
```
@@ -84,7 +84,7 @@ julia> tinf = @snoop_inference mappushes(spelltype, Ts);
8484

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

87-
```
87+
```julia
8888
julia> using Profile
8989

9090
julia> @profile mappushes(spelltype, Ts);

ext/SCPyPlotExt.jl

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
module SCPyPlotExt
22

3+
import Profile
4+
35
using SnoopCompile
46
using SnoopCompile: MethodLoc, InferenceTimingNode, PGDSData, lookups
57
using PyPlot: PyPlot, plt, PyCall
68

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

10-
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...)
12+
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...)
1113
methodref = Ref{Union{Method,MethodLoc}}() # returned to the user for inspection of clicked methods
1214
function onclick(event)
1315
xc, yc = event.xdata, event.ydata
@@ -48,18 +50,18 @@ function pgdsgui(ax::PyCall.PyObject, ridata::AbstractVector{Pair{Union{Method,M
4850
return methodref
4951
end
5052

51-
function pgdsgui(ax::PyCall.PyObject, args...; consts::Bool=true, by=inclusive, kwargs...)
53+
function SnoopCompile.pgdsgui(ax::PyCall.PyObject, args...; consts::Bool=true, by=inclusive, kwargs...)
5254
pgdsgui(ax, prep_ri(args...; consts, by, kwargs...); bystr=get_bystr(by), consts, kwargs...)
5355
end
5456

55-
function pgdsgui(args...; kwargs...)
57+
function SnoopCompile.pgdsgui(args...; kwargs...)
5658
fig, ax = plt.subplots()
5759
pgdsgui(ax, args...; kwargs...), ax
5860
end
5961

6062
function prep_ri(tinf::InferenceTimingNode, pdata=Profile.fetch(); lidict=lookups, consts, by, kwargs...)
61-
lookup_firstip!(lookups, pdata)
62-
return runtime_inferencetime(tinf, pdata; lidict, consts, by)
63+
SnoopCompile.lookup_firstip!(lookups, pdata)
64+
return SnoopCompile.runtime_inferencetime(tinf, pdata; lidict, consts, by)
6365
end
6466

6567
end

src/SnoopCompile.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ that method.
105105
`ax` is the pyplot axis of the scatterplot.
106106
107107
!!! compat
108-
`pgdsgui` depends on PyPlot via the Requires.jl package. You must load both SnoopCompile and PyPlot for this function to be defined.
108+
`pgdsgui` depends on PyPlot via Julia extensions. You must load both SnoopCompile and PyPlot for this function to be defined.
109109
"""
110110
function pgdsgui end
111111
export pgdsgui

0 commit comments

Comments
 (0)