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 all 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.3.0"
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]
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
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 PProf.ProtoBuf
using PProf.OrderedCollections
using CodecZlib

using ProgressMeter

Expand Down Expand Up @@ -206,8 +207,11 @@
)

# Write to disk
open(out, "w") do io
io = GzipCompressorStream(open(out, "w"))
try

Check warning on line 211 in src/Allocs.jl

View check run for this annotation

Codecov / codecov/patch

src/Allocs.jl#L210-L211

Added lines #L210 - L211 were not covered by tests
ProtoBuf.encode(ProtoBuf.ProtoEncoder(io), prof)
finally
close(io)

Check warning on line 214 in src/Allocs.jl

View check run for this annotation

Codecov / codecov/patch

src/Allocs.jl#L214

Added line #L214 was not covered by tests
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 @@ -260,8 +261,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
5 changes: 4 additions & 1 deletion src/flamegraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,11 @@ function pprof(fg::Node{NodeData},
)

# 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
10 changes: 8 additions & 2 deletions 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 All @@ -43,7 +49,7 @@ end
outf = PProf.Allocs.pprof(out=out, web=false)

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

# Test for both functions:
@test in("foo(::Float64)", prof.string_table)
Expand Down
10 changes: 8 additions & 2 deletions 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 @@ -42,7 +43,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 All @@ -56,7 +62,7 @@ end

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

@testset "with_c" begin
Expand Down
15 changes: 13 additions & 2 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 @@ -43,7 +44,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 @@ -55,7 +61,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