Skip to content

Commit

Permalink
use gzip to compress self profile json
Browse files Browse the repository at this point in the history
  • Loading branch information
s7tya committed Aug 22, 2024
1 parent 191132b commit e8b072d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
17 changes: 9 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions site/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ rust-embed = { version = "6.6.0", features = ["include-exclude", "interpolate-fo
humansize = "2"
lru = "0.12.0"
ruzstd = "0.7.0"
flate2 = "1.0.32"

[target.'cfg(unix)'.dependencies]
jemallocator = "0.5"
Expand Down
2 changes: 2 additions & 0 deletions site/src/request_handlers/self_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ pub async fn handle_self_profile_processed_download(
ContentType::from("image/svg+xml".parse::<mime::Mime>().unwrap())
} else if output.filename.ends_with("html") {
ContentType::html()
} else if output.filename.ends_with("gz") {
headers::ContentType::from("application/gzip".parse::<mime::Mime>().unwrap())
} else {
unreachable!()
})
Expand Down
13 changes: 11 additions & 2 deletions site/src/self_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use analyzeme::ProfilingData;
use anyhow::Context;
use bytes::Buf;
use database::ArtifactId;
use flate2::write::GzEncoder;
use flate2::Compression;
use lru::LruCache;
use std::io::Write;
use std::num::NonZeroUsize;
use std::time::Duration;
use std::{collections::HashMap, io::Read, time::Instant};
Expand Down Expand Up @@ -37,9 +40,15 @@ pub fn generate(
ProcessorType::Crox => {
let opt = serde_json::from_str(&serde_json::to_string(&params).unwrap())
.context("crox opts")?;
let data = crox::generate(self_profile_data, opt).context("crox")?;

let mut encoder = GzEncoder::new(Vec::new(), Compression::default());
encoder.write_all(&data)?;
let gzip_compressed_data = encoder.finish()?;

Ok(Output {
filename: "chrome_profiler.json",
data: crox::generate(self_profile_data, opt).context("crox")?,
filename: "chrome_profiler.json.gz",
data: gzip_compressed_data,
is_download: true,
})
}
Expand Down

0 comments on commit e8b072d

Please sign in to comment.