Profile on M1 mac fails with Bounds error
Testing latest master on an m1 mac gives an error while using ProfileView, while normal profiling works fine.
Profile:
@profile plot(sin)
Profile.print()
Overhead ╎ [+additional indent] Count File:Line; Function
=========================================================
╎2 @Base/client.jl:518; _start()
╎ 2 @Base/client.jl:318; exec_options(opts::Base.JLOptions)
╎ 2 @Base/client.jl:404; run_main_repl(interactive::Bool,...
╎ 2 @Base/essentials.jl:794; invokelatest
╎ 2 @Base/essentials.jl:796; #invokelatest#2
╎ 2 @Base/client.jl:419; (::Base.var"#961#963"{Bool, Bo...
╎ ╎ 2 @REPL/src/REPL.jl:355; run_repl(repl::REPL.AbstractRE...
╎ ╎ 2 @REPL/src/REPL.jl:368; run_repl(repl::REPL.AbstractR...
╎ ╎ 2 @REPL/src/REPL.jl:231; start_repl_backend(backend::...
╎ ╎ 2 @REPL/src/REPL.jl:246; repl_backend_loop(backend::R...
╎ ╎ 2 @REPL/src/REPL.jl:151; eval_user_input(ast::Any, b...
╎ ╎ ╎ 2 @Base/boot.jl:370; eval
╎ ╎ ╎ 2 @Plots/src/plot.jl:85; plot(args::Any)
╎ ╎ ╎ 2 @Plots/src/plot.jl:91; plot(args::Any; kw::Base.P...
╎ ╎ ╎ 2 @Plots/src/plot.jl:208; _plot!(plt::Plots.Plot, p...
╎ ╎ ╎ 2 ...ipesPipeline.jl:70; recipe_pipeline!(plt::Any...
╎ ╎ ╎ ╎ 2 .../user_recipe.jl:36; _process_userrecipes!(pl...
╎ ╎ ╎ ╎ 2 ...RecipesBase.jl:289; apply_recipe(plotattrib...
╎ ╎ ╎ ╎ 1 ...user_recipe.jl:253; macro expansion
╎ ╎ ╎ ╎ 1 .../broadcast.jl:860; materialize
╎ ╎ ╎ ╎ 1 .../broadcast.jl:882; copy
1╎ ╎ ╎ ╎ ╎ 1 .../broadcast.jl:717; combine_eltypes(f::Fu...
╎ ╎ ╎ ╎ 1 ...user_recipe.jl:293; macro expansion
╎ ╎ ╎ ╎ 1 ...ser_recipe.jl:353; _scaled_adapted_grid(f...
╎ ╎ ╎ ╎ 1 ...apted_grid.jl:21; adapted_grid(f::Any, m...
1╎ ╎ ╎ ╎ ╎ 1 ...apted_grid.jl:75; adapted_grid(f::Any, ...
Total snapshots: 20. Utilization: 25% across all threads and tasks. Use the `groupby` kwarg to break down by thread and/or task
ProfileView:
@profview plot(sin)
Gtk.GtkWindowLeaf(name="", parent, width-request=-1, height-request=-1, visible=TRUE, sensitive=TRUE, app-paintable=FALSE, can-focus=FALSE, has-focus=FALSE, is-focus=FALSE, focus-on-click=TRUE, can-default=FALSE, has-default=FALSE, receives-default=FALSE, composite-child=FALSE, style, events=0, no-show-all=FALSE, has-tooltip=FALSE, tooltip-markup=NULL, tooltip-text=NULL, window, opacity=1.000000, double-buffered, halign=GTK_ALIGN_FILL, valign=GTK_ALIGN_FILL, margin-left, margin-right, margin-start=0, margin-end=0, margin-top=0, margin-bottom=0, margin=0, hexpand=FALSE, vexpand=FALSE, hexpand-set=FALSE, vexpand-set=FALSE, expand=FALSE, scale-factor=2, border-width=0, resize-mode, child, type=GTK_WINDOW_TOPLEVEL, title="Profile", role=NULL, resizable=TRUE, modal=FALSE, window-position=GTK_WIN_POS_NONE, default-width=800, default-height=600, destroy-with-parent=FALSE, hide-titlebar-when-maximized=FALSE, icon, icon-name=NULL, screen, type-hint=GDK_WINDOW_TYPE_HINT_NORMAL, skip-taskbar-hint=FALSE, skip-pager-hint=FALSE, urgency-hint=FALSE, accept-focus=TRUE, focus-on-map=TRUE, decorated=TRUE, deletable=TRUE, gravity=GDK_GRAVITY_NORTH_WEST, transient-for, attached-to, has-resize-grip, resize-grip-visible, application, is-active=FALSE, has-toplevel-focus=FALSE, startup-id, mnemonics-visible=FALSE, focus-visible=FALSE, is-maximized=FALSE)
julia> FATAL ERROR: Gtk state corrupted by error thrown in a callback:
ERROR: BoundsError: attempt to access 12×0 Matrix{Int64} at index [12, 0]
Stacktrace:
[1] throw_boundserror(A::Matrix{Int64}, I::Tuple{Int64, Int64})
@ Base ./abstractarray.jl:703
[2] checkbounds
@ ./abstractarray.jl:668 [inlined]
[3] getindex
@ ~/.julia/packages/IndirectArrays/BUQO3/src/IndirectArrays.jl:69 [inlined]
[4] (::ProfileView.var"#gettag#31")(tagimg::IndirectArrays.IndirectArray{Base.StackTraces.StackFrame, 2, Int64, Matrix{Int64}, Vector{Base.StackTraces.StackFrame}}, xu::GtkObservables.UserUnit, yu::GtkObservables.UserUnit)
@ ProfileView ~/.julia/packages/ProfileView/6ayqy/src/ProfileView.jl:319
[5] (::ProfileView.var"#29#34"{FlameGraphs.FlameColors, GtkObservables.Canvas{GtkObservables.UserUnit}, Int64, Cairo.CairoSurfaceImage{RGB24}, Observables.Observable{GtkObservables.ZoomRegion{Float64}}, ProfileView.var"#device_bb#32"{Symbol}, ProfileView.var"#gettag#31", Gtk.GtkEntryLeaf, Base.RefValue{Graphics.BoundingBox}, IndirectArrays.IndirectArray{Base.StackTraces.StackFrame, 2, Int64, Matrix{Int64}, Vector{Base.StackTraces.StackFrame}}})(btn::GtkObservables.MouseButton{GtkObservables.UserUnit})
@ ProfileView ~/.julia/packages/ProfileView/6ayqy/src/ProfileView.jl:373
[6] #invokelatest#2
@ ./essentials.jl:796 [inlined]
[7] invokelatest
@ ./essentials.jl:794 [inlined]
[8] notify
@ ~/.julia/packages/Observables/OFj0u/src/Observables.jl:88 [inlined]
[9] setindex!
@ ~/.julia/packages/Observables/OFj0u/src/Observables.jl:248 [inlined]
[10] mousemove_cb(ptr::Ptr{Gtk.GLib.GObject}, eventp::Ptr{Gtk.GdkEventMotion}, handler::GtkObservables.MouseHandler{GtkObservables.UserUnit})
@ GtkObservables ~/.julia/packages/GtkObservables/oJrqY/src/graphics_interaction.jl:665
[11] notify_motion(p::Ptr{Gtk.GLib.GObject}, eventp::Ptr{Gtk.GdkEventMotion}, closure::Gtk.Gtk_signal_motion{GtkObservables.MouseHandler{GtkObservables.UserUnit}})
@ Gtk ~/.julia/packages/Gtk/B6LVT/src/events.jl:46
[12] (::Gtk.var"#253#254")()
@ Gtk ~/.julia/packages/Gtk/B6LVT/src/events.jl:2
[13] g_sigatom(f::Any)
@ Gtk.GLib ~/.julia/packages/Gtk/B6LVT/src/GLib/signals.jl:176
[14] gtk_main()
@ Gtk ~/.julia/packages/Gtk/B6LVT/src/events.jl:1
ProfileView version: 1.5.0
versioninfo()
Julia Version 1.9.0-DEV.406
Commit 6f8662b2c2 (2022-04-18 15:08 UTC)
Platform Info:
OS: macOS (arm64-apple-darwin21.4.0)
CPU: 8 × Apple M1
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-13.0.1 (ORCJIT, apple-m1)
Threads: 4 on 4 virtual cores
Environment:
JULIA_NUM_PRECOMPILE_TASKS = 4
JULIA_NUM_THREADS = 4
I'm experiencing this same issue on an M1 Mac on Julia 1.7.1 and 1.8.0 (just released as of this comment), for a completely unrelated code.
I can't replicate this even though I can obtain what looks like a very similar 2-sample profile. This happens when there is no data to show. (2 snapshots it basically useless, so you wouldn't gain any insight from this even if it worked.)
However, we should fix the error. The stacktrace makes it clear that the image that ProfileView is attempting to show is empty, despite your two snapshots. The stacktrace is filtered in the FlameGraphs.jl package, so here's a step in the right direction:
data, lidict = Profile.retrieve();
using ProfileView.FlameGraphs
julia> g = flamegraph(data; lidict)
Node(FlameGraphs.NodeData(ip:0x0, 0x01, 1:2))
julia> g.child
Node(FlameGraphs.NodeData(eval at boot.jl:368 [inlined], 0x01, 1:2))
What do you see? I want to point out one likely culprit: https://github.com/timholy/FlameGraphs.jl/blob/b1c547a67ce3e3e2fd143da1c2bd3f47a867759d/src/graph.jl#L161
This is what's responsible for identifying the beginning of the "interesting" part of the stacktrace (all the stuff in client.jl is basically from starting Julia), and my guess is this is where something goes wrong.
Same error here too with Julia 1.9.1 on M1 Max.
Your code gives:
julia> data, lidict = Profile.retrieve();
julia> using ProfileView.FlameGraphs
julia> g = flamegraph(data; lidict)
Node(FlameGraphs.NodeData(ip:0x0, 0x00, 1:1))
julia> g.child
Node(FlameGraphs.NodeData(ip:0x0, 0x00, 1:1))