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

Compress on the fly #82

Merged
merged 9 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name = "PProf"
uuid = "e4faabce-9ead-11e9-39d9-4379958e3056"
authors = ["Valentin Churavy <[email protected]>", "Nathan Daly <[email protected]>"]
version = "2.2.2"
version = "3.0.0"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
EnumX = "4e289a0a-7415-4d19-859d-a7e5c4648b56"
FlameGraphs = "08572546-2f56-4bcf-ba4e-bab62c3a3f89"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Expand All @@ -23,6 +24,7 @@ ProgressMeter = "1.7"
ProtoBuf = "1"
julia = "1.6"
pprof_jll = "0.1, 1"
CodecZlib = "0.7"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
6 changes: 5 additions & 1 deletion src/Allocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ using Base.StackTraces: StackFrame

using PProf.ProtoBuf
using PProf.OrderedCollections
using CodecZlib

using ProgressMeter

Expand Down Expand Up @@ -201,8 +202,11 @@ function pprof(alloc_profile::Profile.Allocs.AllocResults = Profile.Allocs.fetch
)

# Write to disk
open(out, "w") do io
io = GzipCompressorStream(open(out, "w"))
try
ProtoBuf.encode(ProtoBuf.ProtoEncoder(io), prof)
finally
close(io)
end

if web
Expand Down
6 changes: 5 additions & 1 deletion src/PProf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export pprof, @pprof
using Profile
using ProtoBuf
using OrderedCollections
using CodecZlib
import pprof_jll

using Profile: clear
Expand Down Expand Up @@ -266,8 +267,11 @@ function pprof(data::Union{Nothing, Vector{UInt}} = nothing,
)

# Write to disk
open(out, "w") do io
io = GzipCompressorStream(open(out, "w"))
try
ProtoBuf.encode(ProtoBuf.ProtoEncoder(io), prof)
finally
close(io)
end

if web
Expand Down
8 changes: 7 additions & 1 deletion test/Allocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module PProfAllocsTest
import PProf
import Profile
using ProtoBuf
using CodecZlib

using Test

Expand All @@ -20,7 +21,12 @@ const out = tempname()
outf = PProf.Allocs.pprof(out=out, web=false)

# Read the exported profile
prof = open(io->decode(ProtoDecoder(io), PProf.perftools.profiles.Profile), outf, "r")
io = GzipDecompressorStream(open(outf, "r"))
prof = try
decode(ProtoDecoder(io), PProf.perftools.profiles.Profile)
finally
close(io)
end

# Verify that we exported stack trace samples:
@test length(prof.sample) > 0
Expand Down
8 changes: 7 additions & 1 deletion test/PProf.jl
NHDaly marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ using PProf
using Test
using Profile
using ProtoBuf
using CodecZlib

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

Expand Down Expand Up @@ -39,7 +40,12 @@ end
outf = pprof(out=out, web=false)

# Read the exported profile
prof = open(io->decode(ProtoDecoder(io), PProf.perftools.profiles.Profile), outf, "r")
io = GzipDecompressorStream(open(outf, "r"))
prof = try
decode(ProtoDecoder(io), PProf.perftools.profiles.Profile)
finally
close(io)
end

# Verify that we exported stack trace samples:
@test length(prof.sample) > 0
Expand Down
17 changes: 14 additions & 3 deletions test/flamegraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ using PProf
using Test
using Profile
using ProtoBuf
using CodecZlib

# Test interactions with FlameGraphs package
using FlameGraphs
Expand Down Expand Up @@ -42,7 +43,12 @@ end
outf = pprof(fg, out=out, web=false)

# Read the exported profile
fg_prof = open(io->decode(ProtoDecoder(io), PProf.perftools.profiles.Profile), outf, "r")
io = GzipDecompressorStream(open(outf, "r"))
fg_prof = try
decode(ProtoDecoder(io), PProf.perftools.profiles.Profile)
finally
close(io)
end

# Verify that we exported stack trace samples:
@test length(fg_prof.sample) > 0
Expand All @@ -54,7 +60,12 @@ end

function load_prof_proto(file)
@show file
open(io->decode(ProtoDecoder(io), PProf.perftools.profiles.Profile), file, "r")
io = GzipDecompressorStream(open(file, "r"))
fg_prof = try
decode(ProtoDecoder(io), PProf.perftools.profiles.Profile)
finally
close(io)
end
end

@testset "with_c" begin
Expand Down Expand Up @@ -85,4 +96,4 @@ end
@test load_prof_proto(pprof(fg, out=tempname(), web=false, keep_frames = "foo")).keep_frames != 0
end

end # module
end # module
Loading