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

feat: check gzip and decompress #538

Merged
merged 1 commit into from
Jul 17, 2024
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
1 change: 1 addition & 0 deletions pyroscope/pprof-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ prost = "0.12.3"
json = "0.12.4"
lazy_static = "1.4.0"
bytemuck = "1.16.1"
flate2 = "1.0"

# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
Expand Down
Binary file modified pyroscope/pprof-bin/pkg/pprof_bin_bg.wasm
Binary file not shown.
14 changes: 12 additions & 2 deletions pyroscope/pprof-bin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use pprof_pb::querier::v1::Level;
use pprof_pb::querier::v1::SelectMergeStacktracesResponse;
use prost::Message;
use std::collections::{HashMap, HashSet};
use std::io::Read;
use std::panic;
use std::sync::Mutex;
use std::vec::Vec;
Expand Down Expand Up @@ -615,8 +616,17 @@ pub fn export_trees_pprof(payload: &[u8]) -> Vec<u8> {
let bin_profs = reader.read_blob_vec();
let mut merger = merge::ProfileMerge::new();
for bin_prof in bin_profs {
let mut prof = Profile::decode(bin_prof).unwrap();
merger.merge(&mut prof);
if bin_prof.len() >= 2 && bin_prof[0] == 0x1f && bin_prof[1] == 0x8b {
let mut decompressed = Vec::new();
let mut decoder = flate2::read::GzDecoder::new(&bin_prof[..]);
decoder.read_to_end(&mut decompressed).unwrap();
let mut prof = Profile::decode(std::io::Cursor::new(decompressed)).unwrap();
merger.merge(&mut prof);
}else {
let mut prof = Profile::decode(bin_prof).unwrap();
merger.merge(&mut prof);
}

}
let res = merger.profile();
res.encode_to_vec()
Expand Down
Loading