Skip to content

Commit cdac877

Browse files
Single-file upload of a tarball
1 parent 6943021 commit cdac877

File tree

1 file changed

+39
-21
lines changed

1 file changed

+39
-21
lines changed

collector/src/execute.rs

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use std::env;
1212
use std::fmt;
1313
use std::fs::{self, File};
1414
use std::hash;
15-
use std::io::Write as _;
1615
use std::path::{Path, PathBuf};
1716
use std::process::{self, Command, Stdio};
1817
use std::str;
@@ -21,34 +20,25 @@ use tempfile::TempDir;
2120
use tokio::runtime::Runtime;
2221

2322
fn to_s3(local: &Path, remote: &Path) -> anyhow::Result<()> {
24-
let data = fs::read(local).with_context(|| format!("reading {:?}", local))?;
25-
let mut compressor = snap::read::FrameEncoder::new(&data[..]);
26-
let mut compressed_file = tempfile::NamedTempFile::new().context("create temporary file")?;
27-
{
28-
let mut buffered = std::io::BufWriter::new(&mut compressed_file);
29-
std::io::copy(&mut compressor, &mut buffered).context("compressed and written")?;
30-
buffered.flush()?;
31-
}
32-
3323
let start = std::time::Instant::now();
3424
let status = Command::new("aws")
3525
.arg("s3")
3626
.arg("cp")
3727
.arg("--only-show-errors")
38-
.arg(compressed_file.path())
39-
.arg(&format!("s3://rustc-perf/{}.sz", remote.to_str().unwrap()))
28+
.arg(local)
29+
.arg(&format!("s3://rustc-perf/{}", remote.to_str().unwrap()))
4030
.status()
4131
.with_context(|| {
4232
format!(
4333
"upload {:?} to s3://rustc-perf/{}",
44-
compressed_file.path(),
34+
local,
4535
remote.to_str().unwrap()
4636
)
4737
})?;
4838
if !status.success() {
4939
anyhow::bail!(
5040
"upload {:?} to s3://rustc-perf/{}: {:?}",
51-
compressed_file.path(),
41+
local,
5242
remote.to_str().unwrap(),
5343
status
5444
);
@@ -637,13 +627,41 @@ impl<'a> MeasureProcessor<'a> {
637627
.join(self.krate.0.as_str())
638628
.join(profile.to_string())
639629
.join(cache.to_id());
640-
let filename = |ext| format!("self-profile-{}.{}", collection, ext);
641-
to_s3(&files.string_index, &prefix.join(filename("string_index")))
642-
.expect("s3 upload succeeded");
643-
to_s3(&files.string_data, &prefix.join(filename("string_data")))
644-
.expect("s3 upload succeeded");
645-
to_s3(&files.events, &prefix.join(filename("events")))
646-
.expect("s3 upload succeeded");
630+
let tarball = snap::write::FrameEncoder::new(Vec::new());
631+
let mut builder = tar::Builder::new(tarball);
632+
builder.mode(tar::HeaderMode::Deterministic);
633+
634+
let append_file = |builder: &mut tar::Builder<_>,
635+
file: &Path,
636+
name: &str|
637+
-> anyhow::Result<()> {
638+
builder.append_path_with_name(file, name)?;
639+
Ok(())
640+
};
641+
append_file(&mut builder, &files.string_index, "string_index")
642+
.expect("append string index");
643+
append_file(&mut builder, &files.string_data, "string_data")
644+
.expect("append string data");
645+
append_file(&mut builder, &files.events, "events").expect("append events");
646+
647+
let upload = tempfile::NamedTempFile::new()
648+
.context("create temporary file")
649+
.unwrap();
650+
builder.finish().expect("complete tarball");
651+
std::fs::write(
652+
upload.path(),
653+
builder
654+
.into_inner()
655+
.expect("get")
656+
.into_inner()
657+
.expect("snap success"),
658+
)
659+
.expect("wrote tarball");
660+
to_s3(
661+
upload.path(),
662+
&prefix.join(format!("self-profile-{}.tar.sz", collection)),
663+
)
664+
.expect("s3 upload succeeded");
647665

648666
self.rt.block_on(self.conn.record_raw_self_profile(
649667
collection,

0 commit comments

Comments
 (0)