Skip to content

Commit 2640098

Browse files
Prepare collector for measureme 0.8
1 parent 0c4b315 commit 2640098

File tree

2 files changed

+100
-58
lines changed

2 files changed

+100
-58
lines changed

collector/src/execute.rs

Lines changed: 78 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::env;
1212
use std::fmt;
1313
use std::fs::{self, File};
1414
use std::hash;
15+
use std::io::Read;
1516
use std::path::{Path, PathBuf};
1617
use std::process::{self, Command, Stdio};
1718
use std::str;
@@ -642,42 +643,58 @@ impl Upload {
642643
// Files are placed at
643644
// * self-profile/<artifact id>/<krate>/<profile>/<cache>
644645
// /self-profile-<collection-id>.{extension}
645-
let tarball = snap::write::FrameEncoder::new(Vec::new());
646-
let mut builder = tar::Builder::new(tarball);
647-
builder.mode(tar::HeaderMode::Deterministic);
648-
649-
let append_file =
650-
|builder: &mut tar::Builder<_>, file: &Path, name: &str| -> anyhow::Result<()> {
651-
if file.exists() {
652-
// Silently ignore missing files, the new self-profile
653-
// experiment with one file has a different structure.
654-
builder.append_path_with_name(file, name)?;
655-
}
656-
Ok(())
657-
};
658-
append_file(
659-
&mut builder,
660-
&files.string_index,
661-
"self-profile.string_index",
662-
)
663-
.expect("append string index");
664-
append_file(&mut builder, &files.string_data, "self-profile.string_data")
665-
.expect("append string data");
666-
append_file(&mut builder, &files.events, "self-profile.events").expect("append events");
667-
668646
let upload = tempfile::NamedTempFile::new()
669647
.context("create temporary file")
670648
.unwrap();
671-
builder.finish().expect("complete tarball");
672-
std::fs::write(
673-
upload.path(),
674-
builder
675-
.into_inner()
676-
.expect("get")
677-
.into_inner()
678-
.expect("snap success"),
679-
)
680-
.expect("wrote tarball");
649+
let filename = match files {
650+
SelfProfileFiles::Seven {
651+
string_index,
652+
string_data,
653+
events,
654+
} => {
655+
let tarball = snap::write::FrameEncoder::new(Vec::new());
656+
let mut builder = tar::Builder::new(tarball);
657+
builder.mode(tar::HeaderMode::Deterministic);
658+
659+
let append_file = |builder: &mut tar::Builder<_>,
660+
file: &Path,
661+
name: &str|
662+
-> anyhow::Result<()> {
663+
if file.exists() {
664+
// Silently ignore missing files, the new self-profile
665+
// experiment with one file has a different structure.
666+
builder.append_path_with_name(file, name)?;
667+
}
668+
Ok(())
669+
};
670+
671+
append_file(&mut builder, &string_index, "self-profile.string_index")
672+
.expect("append string index");
673+
append_file(&mut builder, &string_data, "self-profile.string_data")
674+
.expect("append string data");
675+
append_file(&mut builder, &events, "self-profile.events").expect("append events");
676+
builder.finish().expect("complete tarball");
677+
std::fs::write(
678+
upload.path(),
679+
builder
680+
.into_inner()
681+
.expect("get")
682+
.into_inner()
683+
.expect("snap success"),
684+
)
685+
.expect("wrote tarball");
686+
format!("self-profile-{}.tar.sz", collection)
687+
}
688+
SelfProfileFiles::Eight { file } => {
689+
let data = std::fs::read(&file).expect("read profile data");
690+
let mut data = snap::read::FrameEncoder::new(&data[..]);
691+
let mut compressed = Vec::new();
692+
data.read_to_end(&mut compressed).expect("compressed");
693+
std::fs::write(upload.path(), &compressed).expect("write compressed profile data");
694+
695+
format!("self-profile-{}.mm_profdata.sz", collection)
696+
}
697+
};
681698

682699
let child = Command::new("aws")
683700
.arg("s3")
@@ -686,10 +703,7 @@ impl Upload {
686703
.arg(upload.path())
687704
.arg(&format!(
688705
"s3://rustc-perf/{}",
689-
&prefix
690-
.join(format!("self-profile-{}.tar.sz", collection))
691-
.to_str()
692-
.unwrap()
706+
&prefix.join(&filename).to_str().unwrap()
693707
))
694708
.spawn()
695709
.expect("spawn aws");
@@ -1283,10 +1297,15 @@ enum DeserializeStatError {
12831297
ParseError(String, #[source] ::std::num::ParseFloatError),
12841298
}
12851299

1286-
struct SelfProfileFiles {
1287-
string_data: PathBuf,
1288-
string_index: PathBuf,
1289-
events: PathBuf,
1300+
enum SelfProfileFiles {
1301+
Seven {
1302+
string_data: PathBuf,
1303+
string_index: PathBuf,
1304+
events: PathBuf,
1305+
},
1306+
Eight {
1307+
file: PathBuf,
1308+
},
12901309
}
12911310

12921311
fn process_perf_stat_output(
@@ -1298,6 +1317,7 @@ fn process_perf_stat_output(
12981317
let mut profile: Option<SelfProfile> = None;
12991318
let mut dir: Option<PathBuf> = None;
13001319
let mut prefix: Option<String> = None;
1320+
let mut file: Option<PathBuf> = None;
13011321
for line in stdout.lines() {
13021322
if line.starts_with("!self-profile-output:") {
13031323
profile = Some(serde_json::from_str(&line["!self-profile-output:".len()..]).unwrap());
@@ -1311,6 +1331,10 @@ fn process_perf_stat_output(
13111331
prefix = Some(String::from(&line["!self-profile-prefix:".len()..]));
13121332
continue;
13131333
}
1334+
if line.starts_with("!self-profile-file:") {
1335+
file = Some(PathBuf::from(&line["!self-profile-file:".len()..]));
1336+
continue;
1337+
}
13141338

13151339
// github.com/torvalds/linux/blob/bc78d646e708/tools/perf/Documentation/perf-stat.txt#L281
13161340
macro_rules! get {
@@ -1347,29 +1371,32 @@ fn process_perf_stat_output(
13471371
}
13481372

13491373
let files = if let (Some(prefix), Some(dir)) = (prefix, dir) {
1350-
let mut files = SelfProfileFiles {
1351-
string_index: PathBuf::new(),
1352-
string_data: PathBuf::new(),
1353-
events: PathBuf::new(),
1354-
};
1355-
// Rename the data files. There should be exactly three.
1374+
let mut string_index = PathBuf::new();
1375+
let mut string_data = PathBuf::new();
1376+
let mut events = PathBuf::new();
13561377
for entry in fs::read_dir(&dir).unwrap() {
13571378
let filename = entry.unwrap().file_name();
13581379
let filename_str = filename.to_str().unwrap();
13591380
let path = dir.join(filename_str);
13601381
if filename_str.ends_with(".events") {
13611382
assert!(filename_str.contains(&prefix), "{:?}", path);
1362-
files.events = path;
1383+
events = path;
13631384
} else if filename_str.ends_with(".string_data") {
13641385
assert!(filename_str.contains(&prefix), "{:?}", path);
1365-
files.string_data = path;
1386+
string_data = path;
13661387
} else if filename_str.ends_with(".string_index") {
13671388
assert!(filename_str.contains(&prefix), "{:?}", path);
1368-
files.string_index = path;
1389+
string_index = path;
13691390
}
13701391
}
13711392

1372-
Some(files)
1393+
Some(SelfProfileFiles::Seven {
1394+
string_index,
1395+
string_data,
1396+
events,
1397+
})
1398+
} else if let Some(file) = file {
1399+
Some(SelfProfileFiles::Eight { file })
13731400
} else {
13741401
None
13751402
};

collector/src/rustc-fake.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ fn main() {
8282
.and_then(|args| args[1].to_str())
8383
.expect("rustc to be invoked with crate name");
8484
let mut prefix = None;
85+
let mut full_path = None;
8586
// We don't know the pid of rustc, and can't easily get it -- we only know the
8687
// `perf` pid. So just blindly look in the directory to hopefully find it.
8788
for entry in fs::read_dir(&prof_out_dir).unwrap() {
@@ -91,6 +92,10 @@ fn main() {
9192
.to_str()
9293
.map_or(false, |s| s.starts_with(crate_name))
9394
{
95+
if entry.file_name().to_str().unwrap().ends_with("mm_profdata") {
96+
full_path = Some(entry.path());
97+
break;
98+
}
9499
let file = entry.file_name().to_str().unwrap().to_owned();
95100
let new_prefix = Some(file[..file.find('.').unwrap()].to_owned());
96101
assert!(
@@ -102,13 +107,23 @@ fn main() {
102107
prefix = new_prefix;
103108
}
104109
}
105-
let prefix = prefix.expect(&format!("found prefix {:?}", prof_out_dir));
106-
let json = run_summarize("summarize", &prof_out_dir, &prefix)
107-
.or_else(|_| run_summarize("summarize-0.7", &prof_out_dir, &prefix))
108-
.expect("able to run summarize or summarize-0.7");
109-
println!("!self-profile-dir:{}", prof_out_dir.to_str().unwrap());
110-
println!("!self-profile-prefix:{}", prefix);
111-
println!("!self-profile-output:{}", json);
110+
if let Some(profile_data) = full_path {
111+
// measureme 0.8 has a single file
112+
println!("!self-profile-file:{}", profile_data.to_str().unwrap());
113+
let filename = profile_data.file_name().unwrap().to_str().unwrap();
114+
let json = run_summarize("summarize", &prof_out_dir, filename)
115+
.or_else(|_| run_summarize("summarize-0.8", &prof_out_dir, filename))
116+
.expect("able to run summarize or summarize-0.7");
117+
println!("!self-profile-output:{}", json);
118+
} else {
119+
let prefix = prefix.expect(&format!("found prefix {:?}", prof_out_dir));
120+
let json = run_summarize("summarize", &prof_out_dir, &prefix)
121+
.or_else(|_| run_summarize("summarize-0.7", &prof_out_dir, &prefix))
122+
.expect("able to run summarize or summarize-0.7");
123+
println!("!self-profile-dir:{}", prof_out_dir.to_str().unwrap());
124+
println!("!self-profile-prefix:{}", prefix);
125+
println!("!self-profile-output:{}", json);
126+
}
112127
}
113128
}
114129

0 commit comments

Comments
 (0)