Skip to content

Commit

Permalink
Support saving from graph format (#184)
Browse files Browse the repository at this point in the history
This is useful for the flamegraphs produced by SnoopCompile.

Fixes #173
Closes #183
  • Loading branch information
timholy authored Dec 15, 2021
1 parent fddf0f3 commit 1e91348
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ProfileView"
uuid = "c46f51b8-102a-5cf2-8d2c-8597cb0e0da7"
author = ["Tim Holy <[email protected]>"]
version = "1.0.0"
version = "1.0.1"

[deps]
Cairo = "159f3aea-2a34-519c-b102-8c37f9878175"
Expand All @@ -21,7 +21,7 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
Cairo = "0.6, 0.8, 1"
Colors = "0.9, 0.10, 0.11, 0.12"
FileIO = "1.6"
FlameGraphs = "0.2"
FlameGraphs = "0.2.8"
Graphics = "0.4, 1"
Gtk = "0.18, 1"
GtkObservables = "1"
Expand Down
20 changes: 14 additions & 6 deletions src/ProfileView.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function viewgui(fcolor, g::Node{NodeData}; data=nothing, lidict=nothing, window
push!(tb, tb_save_as)
# FIXME: likely have to do `allkwargs` in the two below (add in C, combine, recur)
signal_connect(open_cb, tb_open, "clicked", Nothing, (), false, (widget(c),gsig,kwargs))
signal_connect(save_as_cb, tb_save_as, "clicked", Nothing, (), false, (widget(c),data,lidict))
signal_connect(save_as_cb, tb_save_as, "clicked", Nothing, (), false, (widget(c),data,lidict,g))
win = Window(windowname, 800, 600)
push!(win, bx)
GtkObservables.gc_preserve(win, c)
Expand Down Expand Up @@ -258,20 +258,28 @@ end
end

function _open(gsig, selection; kwargs...)
data, lidict = load(selection)::Tuple{Vector{UInt64},Profile.LineInfoDict}
push!(gsig, flamegraph(data; lidict=lidict, kwargs...))
ret = load(selection)
if isa(ret, Node{NodeData})
gsig[] = ret
else
data, lidict = ret::Tuple{Vector{UInt64},Profile.LineInfoDict}
gsig[] = flamegraph(data; lidict=lidict, kwargs...)
end
return nothing
end

@guarded function save_as_cb(::Ptr, profdata::Tuple)
c, data, lidict = profdata
c, data, lidict, g = profdata
selection = save_dialog("Save profile data as *.jlprof file", toplevel(c), ("*.jlprof",))
isempty(selection) && return nothing
if data === nothing && lidict === nothing
return _save(selection, g)
end
return _save(selection, data, lidict)
end

function _save(selection, data, lidict)
FileIO.save(File{format"JLPROF"}(selection), data, lidict)
function _save(selection, args...)
FileIO.save(File{format"JLPROF"}(selection), args...)
return nothing
end

Expand Down
9 changes: 7 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,15 @@ end
end
fn = tempname()
try
tmp = Observable{typeof(g)}()
ProfileView._save(fn, backtraces, lidict)
tmp = []
ProfileView._open(tmp, fn)
for (gn, sn) in zip(PreOrderDFS(g), PreOrderDFS(tmp[1]))
for (gn, sn) in zip(PreOrderDFS(g), PreOrderDFS(tmp[]))
@test gn.data == sn.data
end
ProfileView._save(fn, g)
ProfileView._open(tmp, fn)
for (gn, sn) in zip(PreOrderDFS(g), PreOrderDFS(tmp[]))
@test gn.data == sn.data
end
finally
Expand Down

2 comments on commit 1e91348

@timholy
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/50614

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.1 -m "<description of version>" 1e913489ce899810af972e1b6b00fbbeda4b8c1d
git push origin v1.0.1

Please sign in to comment.