Skip to content

Commit

Permalink
Update source locations with Revise (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy authored Jan 5, 2020
1 parent 05ac9ed commit e2d13d5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion 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 = "0.5.2"
version = "0.5.3"

[deps]
Cairo = "159f3aea-2a34-519c-b102-8c37f9878175"
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ Here is the meaning of the different arguments:

- `pruned` is a list of functions (see example) whose call tree will not be displayed. This is useful to control the output of very deep (or recursive) functions. Example: `pruned = [("sort!", "sort.jl"), ("some_function_name", "some_filename.jl")]`

## Source locations & Revise (new in ProfileView 0.5.3)

Profiling and [Revise](https://github.com/timholy/Revise.jl) are natural partners,
as together they allow you to iteratively improve the performance of your code.
If you use Revise and are tracking the source files (either as a package or with `includet`),
the source locations (file and line number) reported by ProfileView
will match the current code at the time the window is created.

### Saving profile data manually

If you're using the Gtk backend, the easiest approach is to click on
Expand Down
25 changes: 23 additions & 2 deletions src/ProfileView.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@ using Colors

import Base: isequal, show

# This allows Revise to correct the location information in profiles
if VERSION >= v"1.5.0-DEV.9"
using Profile: getdict # ref https://github.com/JuliaLang/julia/pull/34235
else
# Use the definition of getdict from Julia 1.5.0-DEV.9+
function getdict(data::Vector{UInt})
# Lookup is expensive, so do it only once per ip.
udata = unique(data)
dict = Profile.LineInfoDict()
for ip in udata
st = Profile.lookup(convert(Ptr{Cvoid}, ip))
# To correct line numbers for moving code, put it in the form expected by
# Base.update_stackframes_callback[]
stn = map(x->(x, 1), st)
try Base.invokelatest(Base.update_stackframes_callback[], stn) catch end
dict[UInt64(ip)] = map(first, stn)
end
return dict
end
end

export @profview

"""
Expand Down Expand Up @@ -113,8 +134,8 @@ function prepare_data(data, lidict)
# Do code address lookups on all unique instruction pointers
uip = unique(vcat(bt...))
if lidict == nothing
lkup = Vector{StackTraces.StackFrame}[Profile.lookup(ip) for ip in uip]
lidict = Dict(zip(uip, lkup))
lidict = getdict(uip)
lkup = map(ip->lidict[ip], uip)
else
lkup = [lidict[ip] for ip in uip]
end
Expand Down

2 comments on commit e2d13d5

@timholy
Copy link
Owner Author

@timholy timholy commented on e2d13d5 Jan 5, 2020

Choose a reason for hiding this comment

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

@JuliaRegistrator register()

@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/7539

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 Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.3 -m "<description of version>" e2d13d5701a095329449c14796c90a35e87a4568
git push origin v0.5.3

Please sign in to comment.