Skip to content

Commit afdba95

Browse files
Profile: add helper method for printing profile report to file (JuliaLang#56505)
The IOContext part is isn't obvious, because otherwise the IO is assumed to be 80 chars wide, which makes for bad reports.
1 parent b6a2cc1 commit afdba95

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

stdlib/Profile/src/Profile.jl

+8
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ const META_OFFSET_THREADID = 5
217217

218218
"""
219219
print([io::IO = stdout,] [data::Vector = fetch()], [lidict::Union{LineInfoDict, LineInfoFlatDict} = getdict(data)]; kwargs...)
220+
print(path::String, [cols::Int = 1000], [data::Vector = fetch()], [lidict::Union{LineInfoDict, LineInfoFlatDict} = getdict(data)]; kwargs...)
220221
221222
Prints profiling results to `io` (by default, `stdout`). If you do not
222223
supply a `data` vector, the internal buffer of accumulated backtraces
@@ -357,6 +358,13 @@ function print(io::IO,
357358
return
358359
end
359360

361+
function print(path::String, cols::Int = 1000, args...; kwargs...)
362+
open(path, "w") do io
363+
ioc = IOContext(io, :displaysize=>(1000,cols))
364+
print(ioc, args...; kwargs...)
365+
end
366+
end
367+
360368
"""
361369
print([io::IO = stdout,] data::Vector, lidict::LineInfoDict; kwargs...)
362370

stdlib/Profile/test/runtests.jl

+3
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ for options in ((format=:tree, C=true),
9595
Profile.print(iobuf; options...)
9696
str = String(take!(iobuf))
9797
@test !isempty(str)
98+
file, _ = mktemp()
99+
Profile.print(file; options...)
100+
@test filesize(file) > 0
98101
end
99102

100103
@testset "Profile.print() groupby options" begin

0 commit comments

Comments
 (0)