Skip to content

Commit

Permalink
Profile: add helper method for printing profile report to file (Julia…
Browse files Browse the repository at this point in the history
…Lang#56505)

The IOContext part is isn't obvious, because otherwise the IO is assumed
to be 80 chars wide, which makes for bad reports.
  • Loading branch information
IanButterworth authored Nov 10, 2024
1 parent b6a2cc1 commit afdba95
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions stdlib/Profile/src/Profile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ const META_OFFSET_THREADID = 5

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

function print(path::String, cols::Int = 1000, args...; kwargs...)
open(path, "w") do io
ioc = IOContext(io, :displaysize=>(1000,cols))
print(ioc, args...; kwargs...)
end
end

"""
print([io::IO = stdout,] data::Vector, lidict::LineInfoDict; kwargs...)
Expand Down
3 changes: 3 additions & 0 deletions stdlib/Profile/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ for options in ((format=:tree, C=true),
Profile.print(iobuf; options...)
str = String(take!(iobuf))
@test !isempty(str)
file, _ = mktemp()
Profile.print(file; options...)
@test filesize(file) > 0
end

@testset "Profile.print() groupby options" begin
Expand Down

0 comments on commit afdba95

Please sign in to comment.