Skip to content

Commit

Permalink
feat: gzip check first
Browse files Browse the repository at this point in the history
  • Loading branch information
Cluas committed Jul 17, 2024
1 parent 8d2cb11 commit bd831a3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
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

0 comments on commit bd831a3

Please sign in to comment.