Skip to content

Commit

Permalink
Merge pull request #15 from vchuravy/enforce-.pb.gz
Browse files Browse the repository at this point in the history
Auto-rename `out=` files with the `.pb.gz` extension if not provided.
  • Loading branch information
NHDaly authored Dec 13, 2019
2 parents 6112f40 + 4be9197 commit d6f9855
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PProf"
uuid = "e4faabce-9ead-11e9-39d9-4379958e3056"
authors = ["Valentin Churavy <v.churavy@gmail.com>", "Nathan Daly <nhdaly@gmail.com>"]
version = "0.3.1"
version = "0.3.2"

[deps]
BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
Expand Down
5 changes: 5 additions & 0 deletions src/PProf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,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

0 comments on commit d6f9855

Please sign in to comment.