Skip to content

Commit 199367f

Browse files
Compress output files with snappy
This compresses the files such that we have much smaller files in the output, but still preserves ability to read non-compressed data.
1 parent b38d277 commit 199367f

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

collector/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ xz2 = "0.1.3"
2323
tar = "0.4"
2424
crossbeam-channel = "0.3.8"
2525
bincode = "1"
26+
snap = "0.2.5"
2627

2728
[dependencies.rustup]
2829
git = "https://github.com/rust-lang-nursery/rustup.rs.git"

collector/src/bin/rustc-perf-collector/outrepo.rs

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ impl Repo {
123123
trace!("loading file {}", filepath.display());
124124
let contents =
125125
fs::read(&filepath).with_context(|| format!("failed to read {:?}", filepath))?;
126+
let c;
127+
let contents = if filepath.to_str().map_or(false, |s| s.ends_with(".sz")) {
128+
use std::io::Read;
129+
let mut out = Vec::with_capacity(snap::decompress_len(&contents).unwrap_or(0));
130+
let mut szip_reader = snap::Reader::new(&contents[..]);
131+
szip_reader.read_to_end(&mut out).unwrap();
132+
c = out;
133+
&c
134+
} else {
135+
&contents
136+
};
126137
let data = serde_json::from_slice(&contents)
127138
.with_context(|| format!("failed to read JSON from {:?}", filepath))?;
128139
Ok(data)
@@ -135,24 +146,30 @@ impl Repo {
135146
commit.sha,
136147
triple
137148
));
138-
match self.load_commit_data_file(&filepath) {
139-
Ok(v) => return Ok(v),
140-
Err(_) => self.load_commit_data_file(
141-
&self
142-
.times()
143-
.join(format!("commit-{}-{}.json", commit.sha, triple)),
144-
),
149+
if let Ok(v) = self.load_commit_data_file(&filepath) {
150+
return Ok(v);
151+
}
152+
let filepath = self
153+
.times()
154+
.join(format!("commit-{}-{}.json", commit.sha, triple));
155+
if let Ok(v) = self.load_commit_data_file(&filepath) {
156+
return Ok(v);
145157
}
158+
let filepath = self
159+
.times()
160+
.join(format!("commit-{}-{}.json.sz", commit.sha, triple));
161+
Ok(self.load_commit_data_file(&filepath)?)
146162
}
147163

148164
pub fn add_commit_data(&self, data: &CommitData) -> anyhow::Result<()> {
149165
let commit = &data.commit;
150166
let filepath = self
151167
.times()
152-
.join(format!("commit-{}-{}.json", commit.sha, data.triple));
168+
.join(format!("commit-{}-{}.json.sz", commit.sha, data.triple));
153169
info!("creating file {}", filepath.display());
154-
let serialized = serde_json::to_string(&data)?;
155-
fs::write(&filepath, &serialized)?;
170+
let mut v = snap::Writer::new(Vec::new());
171+
serde_json::to_writer(&mut v, &data)?;
172+
fs::write(&filepath, v.into_inner()?)?;
156173
Ok(())
157174
}
158175

0 commit comments

Comments
 (0)