Skip to content

Commit e8b072d

Browse files
committed
use gzip to compress self profile json
1 parent 191132b commit e8b072d

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

Cargo.lock

+9-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ rust-embed = { version = "6.6.0", features = ["include-exclude", "interpolate-fo
4646
humansize = "2"
4747
lru = "0.12.0"
4848
ruzstd = "0.7.0"
49+
flate2 = "1.0.32"
4950

5051
[target.'cfg(unix)'.dependencies]
5152
jemallocator = "0.5"

site/src/request_handlers/self_profile.rs

+2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ pub async fn handle_self_profile_processed_download(
127127
ContentType::from("image/svg+xml".parse::<mime::Mime>().unwrap())
128128
} else if output.filename.ends_with("html") {
129129
ContentType::html()
130+
} else if output.filename.ends_with("gz") {
131+
headers::ContentType::from("application/gzip".parse::<mime::Mime>().unwrap())
130132
} else {
131133
unreachable!()
132134
})

site/src/self_profile.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ use analyzeme::ProfilingData;
99
use anyhow::Context;
1010
use bytes::Buf;
1111
use database::ArtifactId;
12+
use flate2::write::GzEncoder;
13+
use flate2::Compression;
1214
use lru::LruCache;
15+
use std::io::Write;
1316
use std::num::NonZeroUsize;
1417
use std::time::Duration;
1518
use std::{collections::HashMap, io::Read, time::Instant};
@@ -37,9 +40,15 @@ pub fn generate(
3740
ProcessorType::Crox => {
3841
let opt = serde_json::from_str(&serde_json::to_string(&params).unwrap())
3942
.context("crox opts")?;
43+
let data = crox::generate(self_profile_data, opt).context("crox")?;
44+
45+
let mut encoder = GzEncoder::new(Vec::new(), Compression::default());
46+
encoder.write_all(&data)?;
47+
let gzip_compressed_data = encoder.finish()?;
48+
4049
Ok(Output {
41-
filename: "chrome_profiler.json",
42-
data: crox::generate(self_profile_data, opt).context("crox")?,
50+
filename: "chrome_profiler.json.gz",
51+
data: gzip_compressed_data,
4352
is_download: true,
4453
})
4554
}

0 commit comments

Comments
 (0)