Skip to content

Commit b38d277

Browse files
Decode snappy-compressed files
1 parent 8128d6d commit b38d277

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

Cargo.lock

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

site/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jemallocator = "0.3"
2929
jemalloc-ctl = "0.3"
3030
rust_team_data = { git = "https://github.com/rust-lang/team" }
3131
parking_lot = "0.9"
32+
snap = "0.2.5"
3233

3334
[dependencies.collector]
3435
path = "../collector"

site/src/load.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl InputData {
193193
let repo_loc = PathBuf::from(repo_loc);
194194
let mut skipped = 0;
195195
let mut artifact_data = BTreeMap::new();
196-
let mut data = BTreeMap::new();
196+
let mut data = HashMap::new();
197197

198198
if !repo_loc.exists() {
199199
// If the repository doesn't yet exist, simplify clone it to the given location.
@@ -214,19 +214,36 @@ impl InputData {
214214
trace!("loading files from directory");
215215

216216
// Read all files from repo_loc/processed
217-
let mut file_count = 0;
217+
let mut files = Vec::new();
218218
for entry in fs::read_dir(repo_loc.join("times"))? {
219219
let entry = entry?;
220220
if entry.file_type()?.is_dir() {
221221
continue;
222222
}
223-
file_count += 1;
224-
225223
let filename = entry.file_name();
226224
let filename = filename.to_str().unwrap();
227225
let file_contents =
228226
fs::read(entry.path()).with_context(|| format!("Failed to read {}", filename))?;
229227

228+
files.push((filename.to_owned(), file_contents));
229+
}
230+
231+
trace!("read directory");
232+
233+
data.reserve(files.len());
234+
for (filename, file_contents) in &files {
235+
let c;
236+
let file_contents = if filename.ends_with(".sz") {
237+
use std::io::Read;
238+
let mut out = Vec::with_capacity(snap::decompress_len(&file_contents).unwrap_or(0));
239+
let mut szip_reader = snap::Reader::new(&file_contents[..]);
240+
szip_reader.read_to_end(&mut out).unwrap();
241+
c = out;
242+
&c
243+
} else {
244+
&file_contents
245+
};
246+
230247
if filename.starts_with("artifact-") {
231248
let contents: ArtifactData = match serde_json::from_slice(&file_contents) {
232249
Ok(j) => j,
@@ -262,7 +279,7 @@ impl InputData {
262279
}
263280
}
264281

265-
info!("{} total files", file_count);
282+
info!("{} total files", files.len());
266283
info!("{} skipped files", skipped);
267284
info!("{} measured", data.len());
268285

@@ -275,7 +292,7 @@ impl InputData {
275292
}
276293
};
277294

278-
InputData::new(data, artifact_data, config)
295+
InputData::new(data.into_iter().collect(), artifact_data, config)
279296
}
280297

281298
pub fn new(

0 commit comments

Comments
 (0)