timholy / SnoopCompile.jl

Provide insights about latency (TTFX) for Julia packages
https://timholy.github.io/SnoopCompile.jl/dev/
Other
309 stars 48 forks source link

Skip nothing results in visualization to avoid log(::Nothing) #269

Closed charleskawczynski closed 2 years ago

charleskawczynski commented 2 years ago

I've been visualizing invalidations for a package, the plots and docs are fantastic. I have been running into an error when plotting, however:

RuntimeError: <PyCall.jlwrap (in a Julia function called from Python)
JULIA: MethodError: no method matching log(::Nothing)
Closest candidates are:
  log(!Matched::StridedMatrix{T} where T) at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/LinearAlgebra/src/dense.jl:757
  log(!Matched::SymbolicUtils.Add) at ~/.julia/packages/SymbolicUtils/fgHzN/src/methods.jl:68
  log(!Matched::SymbolicUtils.Sym) at ~/.julia/packages/SymbolicUtils/fgHzN/src/methods.jl:68
  ...
Stacktrace:
  [1] (::SnoopCompile.var"#onclick#171"{Float64, Base.RefValue{Union{Method, SnoopCompile.MethodLoc}}})(event::PyCall.PyObject)
    @ SnoopCompile ~/.julia/packages/SnoopCompile/NF9Dd/src/visualizations.jl:32
  [2] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Base ./essentials.jl:716
  [3] invokelatest(::Any, ::Any, ::Vararg{Any})
    @ Base ./essentials.jl:714
  [4] _pyjlwrap_call(f::Function, args_::Ptr{PyCall.PyObject_struct}, kw_::Ptr{PyCall.PyObject_struct})
    @ PyCall ~/.julia/packages/PyCall/3fwVL/src/callback.jl:32
  [5] pyjlwrap_call(self_::Ptr{PyCall.PyObject_struct}, args_::Ptr{PyCall.PyObject_struct}, kw_::Ptr{PyCall.PyObject_struct})
    @ PyCall ~/.julia/packages/PyCall/3fwVL/src/callback.jl:44
  [6] macro expansion
    @ ~/.julia/packages/PyCall/3fwVL/src/exception.jl:95 [inlined]
  [7] #107
    @ ~/.julia/packages/PyCall/3fwVL/src/pyfncall.jl:43 [inlined]
  [8] disable_sigint
    @ ./c.jl:458 [inlined]
  [9] __pycall!
    @ ~/.julia/packages/PyCall/3fwVL/src/pyfncall.jl:42 [inlined]
 [10] _pycall!(ret::PyCall.PyObject, o::PyCall.PyObject, args::Tuple{PyCall.PyObject, PyCall.PyObject}, nargs::Int64, kw::Ptr{Nothing})
    @ PyCall ~/.julia/packages/PyCall/3fwVL/src/pyfncall.jl:29
 [11] _pycall!
    @ ~/.julia/packages/PyCall/3fwVL/src/pyfncall.jl:11 [inlined]
 [12] #pycall#112
    @ ~/.julia/packages/PyCall/3fwVL/src/pyfncall.jl:80 [inlined]
 [13] pycall
    @ ~/.julia/packages/PyCall/3fwVL/src/pyfncall.jl:80 [inlined]
 [14] (::PyCall.var"#3#4"{PyCall.PyObject, PyCall.PyObject, PyCall.PyObject, PyCall.PyObject})(async::Timer)
    @ PyCall ~/.julia/packages/PyCall/3fwVL/src/gui.jl:151
 [15] macro expansion
    @ ./asyncevent.jl:260 [inlined]
 [16] (::Base.var"#632#633"{PyCall.var"#3#4"{PyCall.PyObject, PyCall.PyObject, PyCall.PyObject, PyCall.PyObject}, Timer})()
    @ Base ./task.jl:123>

It seems that some of the pushed elements are nothing, which results in an error when calling log(::Nothing). I'm not super familiar with the package, so I'm not sure if this is the best solution.

timholy commented 2 years ago

I'd really love a reproducer of this one, as it seems possible this reflects a deeper problem.

charleskawczynski commented 2 years ago

I can try, but I imagine this may be a bit difficult for me to boil down.

timholy commented 2 years ago

Having looked at this a little more, there seems to be no way these could be Nothing. Check the type on ridata to that function and then the definition of PGDSData: those fields are Float64. There's no way they should ever be nothing.

However, check the stacktrace: the error is thrown on line 32, not line 40. This error must have happened when you clicked, not during basic plotting. I think if you change this to check whether xc or yc is nothing in onclick, we can merge this.

charleskawczynski commented 2 years ago

Ahhh, I think you're right. I am seeing this error when I click outside the scatter plot window (to bring the window into view).