Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-rename out= files with the .pb.gz extension if not provided. #15

Merged
merged 2 commits into from
Dec 13, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/PProf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ function pprof(data::Union{Nothing, Vector{UInt}} = nothing,
if period === nothing
period = ccall(:jl_profile_delay_nsec, UInt64, ())
end
@assert !isempty(basename(out)) "`out=` must specify a file path to write to. Got unexpected: '$out'"
if !endswith(out, ".pb.gz")
out = "$out.pb.gz"
@info "Writing output to $out"
end

string_table = OrderedDict{AbstractString, Int64}()
enter!(string) = _enter!(string_table, string)
Expand Down
14 changes: 11 additions & 3 deletions test/PProf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using Test
using Profile
using ProtoBuf

const out = tempname()
const out = tempname() * ".pb.gz"

function foo(n, a, out=[])
# make this expensive to ensure it's sampled
Expand All @@ -33,10 +33,10 @@ end
_prior_profile_output = Profile.retrieve()

# Write the profile
pprof(out=out, web=false)
outf = pprof(out=out, web=false)

# Read the exported profile
prof = open(io->readproto(io, PProf.perftools.profiles.Profile()), out, "r")
prof = open(io->readproto(io, PProf.perftools.profiles.Profile()), outf, "r")

# Verify that we exported stack trace samples:
@test length(prof.sample) > 0
Expand Down Expand Up @@ -123,4 +123,12 @@ end
rm("profile.pb.gz")
end

@testset "enforce correct output file extension (.pb.gz)" begin
dir = mktempdir()
@test basename(pprof(out="$dir/test")) == "test.pb.gz"
@test basename(pprof(out="$dir/test.pb.gz")) == "test.pb.gz"

@test_throws AssertionError pprof(out="$dir/") # directory path with no file throws err
end

end # module