Skip to content

Commit 6e45227

Browse files
timholyserenity4jwahlstrand
authored
Support Julia 1.12/Cthulhu 3 (#256)
--------- Co-authored-by: serenity4 <cedric.bel@hotmail.fr> Co-authored-by: Jared Wahlstrand <jwahlstrand@gmail.com>
1 parent 0b4cdba commit 6e45227

6 files changed

Lines changed: 110 additions & 49 deletions

File tree

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ProfileView"
22
uuid = "c46f51b8-102a-5cf2-8d2c-8597cb0e0da7"
33
author = ["Tim Holy <tim.holy@gmail.com>"]
4-
version = "1.10.2"
4+
version = "1.10.3"
55

66
[deps]
77
Cairo = "159f3aea-2a34-519c-b102-8c37f9878175"
@@ -29,12 +29,12 @@ ProfileViewCthulhuExt = "Cthulhu"
2929
[compat]
3030
Cairo = "0.6, 0.8, 1"
3131
Colors = "0.12, 0.13"
32-
Cthulhu = "2"
32+
Cthulhu = "2, 3"
3333
Dates = "1"
3434
FileIO = "1.6"
3535
FlameGraphs = "0.2.10, 1"
3636
Graphics = "0.4, 1"
37-
Gtk4 = "0.7.6"
37+
Gtk4 = "0.7.12"
3838
GtkObservables = "2"
3939
InteractiveUtils = "1"
4040
IntervalSets = "0.2, 0.3, 0.4, 0.5, 0.6, 0.7"

ext/ProfileViewCthulhuExt.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module ProfileViewCthulhuExt
22

33
using ProfileView
4+
using ProfileView: getmi
45
using Cthulhu: Cthulhu
56

67
function ProfileView.descend_clicked(; optimize=false, iswarn=true, hide_type_stable=true, kwargs...)
@@ -9,7 +10,7 @@ function ProfileView.descend_clicked(; optimize=false, iswarn=true, hide_type_st
910
@warn "the bar you clicked on might have been inlined and unavailable for inspection. Click on a non-inlined bar to `descend`."
1011
return nothing
1112
end
12-
return Cthulhu.descend(st.linfo; optimize, iswarn, hide_type_stable, kwargs...)
13+
return Cthulhu.descend(getmi(st.linfo); optimize, iswarn, hide_type_stable, kwargs...)
1314
end
1415
function ProfileView.ascend_clicked(; hide_type_stable=true, terminal=Cthulhu.default_terminal(), kwargs...)
1516
st = ProfileView.clicked[]
@@ -20,7 +21,7 @@ function ProfileView.ascend_clicked(; hide_type_stable=true, terminal=Cthulhu.de
2021
if hasmethod(Cthulhu.buildframes, Tuple{Vector{StackTraces.StackFrame}})
2122
return Cthulhu.ascend(terminal, ProfileView.clicked_trace[]; hide_type_stable, kwargs...)
2223
else
23-
return Cthulhu.ascend(terminal, st.linfo; hide_type_stable, kwargs...)
24+
return Cthulhu.ascend(terminal, getmi(st.linfo); hide_type_stable, kwargs...)
2425
end
2526
end
2627

src/ProfileView.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ function warntype_clicked(io::IO=stdout; kwargs...)
7373
@warn "click on a non-inlined bar to see `code_warntype` info"
7474
return nothing
7575
end
76-
return code_warntype(io, call_type(st.linfo.specTypes)...; kwargs...)
76+
return code_warntype(io, call_type(getmi(st.linfo).specTypes)...; kwargs...)
7777
end
78+
getmi(mi) = mi
79+
getmi(ci::Core.CodeInstance) = ci.def
7880

7981
"""
8082
descend_clicked(; optimize=false, iswarn=true, hide_type_stable=true, kwargs...)
@@ -526,12 +528,13 @@ function viewprof_func(fcolor, c, g, fontsize, tb_items, graphtype)
526528
end
527529

528530
function long_info_str(sf)
531+
linfo = getmi(sf.linfo)
529532
if sf.file == :none && sf.line == 0
530533
# some flamegraph producers don't provide file/line info as they are not applicable
531534
# The above values together are identifiers for such cases
532535
string(sf.func) # might not actually be a func, just a name
533-
elseif sf.linfo isa Core.MethodInstance
534-
string(sf.file, ':', sf.line, ", ", sf.linfo)
536+
elseif linfo isa Core.MethodInstance
537+
string(sf.file, ':', sf.line, ", ", linfo)
535538
else
536539
string(sf.file, ':', sf.line, ", ", sf.func, " [inlined]")
537540
end

test/extensions.jl

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,44 @@
11
using ProfileView
22
using Cthulhu
3-
if !isdefined(@__MODULE__, :fake_terminal)
4-
@eval (@__MODULE__) begin
5-
include(joinpath(pkgdir(Cthulhu), "test", "FakeTerminals.jl"))
6-
using .FakeTerminals
7-
macro with_try_stderr(out, expr)
8-
quote
9-
try
10-
$(esc(expr))
11-
catch err
12-
bt = catch_backtrace()
13-
Base.display_error(stderr, err, bt)
14-
#close($(esc(out)))
15-
end
16-
end
17-
end
18-
end
19-
end
3+
using Cthulhu.Testing
4+
# if !isdefined(@__MODULE__, Symbol("@with_try_stderr"))
5+
# macro with_try_stderr(out, expr)
6+
# quote
7+
# try
8+
# $(esc(expr))
9+
# catch err
10+
# bt = catch_backtrace()
11+
# Base.display_error(stderr, err, bt)
12+
# end
13+
# end
14+
# end
15+
# end
16+
# end
2017
using Test
2118

2219
@testset "Extensions" begin
2320
@testset "Cthulhu" begin
24-
cread1(io) = readuntil(io, ''; keep=true)
25-
cread(io) = cread1(io) * cread1(io)
26-
21+
println("starting Cthulhu extension tests")
2722
# profile_test(1) # defined in test/runtests.jl
2823
# @profile profile_test(10)
2924
_, bt = add2(Any[1,2])
3025
st = stacktrace(bt)
3126
ProfileView.clicked[] = st[1]
32-
fake_terminal() do term, in, out, _
33-
t = @async begin
34-
@with_try_stderr out descend_clicked(; interruptexc=false, terminal=term)
35-
end
36-
lines = cread(out)
37-
@test occursin("Select a call to descend into", lines)
38-
write(in, 'q')
39-
wait(t)
40-
end
27+
terminal = VirtualTerminal()
28+
harness = Testing.@run terminal descend_clicked(; terminal)
29+
displayed, text = Testing.read_next(harness)
30+
@test occursin("Select a call to descend into", text)
31+
@test Testing.end_terminal_session(harness)
32+
println("finished 1")
33+
terminal = VirtualTerminal()
4134
ProfileView.clicked_trace[] = st
42-
fake_terminal() do term, in, out, _
43-
t = @async begin
44-
@with_try_stderr out ascend_clicked(; interruptexc=false, terminal=term)
45-
end
46-
lines = readuntil(out, 'q'; keep=true) # up to the "q to quit" prompt
47-
@test occursin("Choose a call for analysis", lines)
48-
write(in, 'q')
49-
write(in, 'q')
50-
wait(t)
51-
end
35+
harness = Testing.@run terminal ascend_clicked(; terminal)
36+
# descend into something to generate a next "section" to read,
37+
# as VirtualTerminal is designed to read `descend` output
38+
write(terminal, :enter)
39+
displayed, text = Testing.read_next(harness)
40+
@test occursin("Choose a call for analysis", text)
41+
@test Testing.end_terminal_session(harness)
42+
println("finished 2")
5243
end
5344
end

test/extensions_Cthulhu2.jl

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using Cthulhu
2+
using REPL
3+
using ProfileView
4+
if !isdefined(@__MODULE__, :fake_terminal)
5+
@eval (@__MODULE__) begin
6+
include(joinpath(pkgdir(Cthulhu), "test", "FakeTerminals.jl"))
7+
using .FakeTerminals
8+
macro with_try_stderr(out, expr)
9+
quote
10+
try
11+
$(esc(expr))
12+
catch err
13+
bt = catch_backtrace()
14+
Base.display_error(stderr, err, bt)
15+
#close($(esc(out)))
16+
end
17+
end
18+
end
19+
end
20+
end
21+
using Test
22+
23+
@testset "Extensions" begin
24+
@testset "Cthulhu" begin
25+
cread1(io) = readuntil(io, ''; keep=true)
26+
cread(io) = cread1(io) * cread1(io)
27+
28+
# profile_test(1) # defined in test/runtests.jl
29+
# @profile profile_test(10)
30+
_, bt = add2(Any[1,2])
31+
st = stacktrace(bt)
32+
ProfileView.clicked[] = st[1]
33+
fake_terminal() do term, in, out, _
34+
t = @async begin
35+
@with_try_stderr out descend_clicked(; interruptexc=false, terminal=term)
36+
end
37+
lines = cread(out)
38+
@test occursin("Select a call to descend into", lines)
39+
write(in, 'q')
40+
wait(t)
41+
end
42+
ProfileView.clicked_trace[] = st
43+
fake_terminal() do term, in, out, _
44+
t = @async begin
45+
@with_try_stderr out ascend_clicked(; interruptexc=false, terminal=term)
46+
end
47+
lines = readuntil(out, 'q'; keep=true) # up to the "q to quit" prompt
48+
@test occursin("Choose a call for analysis", lines)
49+
write(in, 'q')
50+
write(in, 'q')
51+
wait(t)
52+
end
53+
end
54+
end

test/runtests.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
using Profile
2-
using ProfileView
32
using GtkObservables
43
using Gtk4
54
using AbstractTrees
5+
# Loading these before ProfileView ensures valid cache versions
6+
using REPL
7+
using Cthulhu
8+
using ProfileView
69
using Test
710

811
function profile_test(n)
@@ -37,11 +40,16 @@ function add2(x)
3740
end
3841

3942
@testset "ProfileView" begin
43+
println("starting ProfileView tests")
4044
Gtk4.GLib.start_main_loop(true) # the loop only starts automatically if isinteractive() == true
45+
println("main loop started")
4146
@testset "windows" begin
4247
profile_test(1)
48+
println("profiling done 1")
4349
@test isa(@profview(profile_test(10)), ProfileView.GtkWindow)
50+
println("profiling done 2")
4451
data, lidict = Profile.retrieve()
52+
println("retrieved profile data")
4553

4654
Profile.clear()
4755
@profile profile_test(10)
@@ -193,4 +201,8 @@ end
193201
end
194202
end
195203

196-
include("extensions.jl")
204+
if Base.pkgversion(Cthulhu) < v"3.0.0-"
205+
include("extensions_Cthulhu2.jl")
206+
else
207+
include("extensions.jl")
208+
end

0 commit comments

Comments
 (0)