Skip to content

Commit

Permalink
Add v9 format test
Browse files Browse the repository at this point in the history
  • Loading branch information
smklein committed Dec 15, 2023
1 parent 95da6df commit cdd29c6
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions analyzeme/src/profiling_data.rs
Expand Up @@ -649,6 +649,86 @@ mod tests {
);
}

// To generate this revision, a v9 revision of the rust toolchain was
// created, and "rustup toolchain link" was used to name it "bespoke".
// Then, the following commands were executed:
//
// # Make a small test binary and profile it.
// cargo new --bin testbinary
// cargo +bespoke rustc --bin testbinary -- -Zself-profile
//
// # Gzip the output profdata.
// gzip testbinary-...mm_profdata
// mv testbinary-...mm_profdata.gz v9.mm_profdata.gz
#[test]
fn can_read_v9_profdata_files() {
let (data, file_format_version) =
read_data_and_version("tests/profdata/v9.mm_profdata.gz");
assert_eq!(file_format_version, file_formats::v9::FILE_FORMAT);
let profiling_data = ProfilingData::from_paged_buffer(data, None)
.expect("Creating the profiling data failed");
let grouped_events = group_events(&profiling_data);
let event_kinds = grouped_events
.keys()
.map(|k| k.as_str())
.collect::<HashSet<_>>();
let expect_event_kinds = vec![
"GenericActivity",
"IncrementalResultHashing",
"Query",
"ArtifactSize",

This comment has been minimized.

Copy link
@smklein

smklein Dec 15, 2023

Author Contributor

Most of this test was just copied from the v8 version, but ArtifactSize seems new?

]
.into_iter()
.collect::<HashSet<_>>();
assert_eq!(event_kinds, expect_event_kinds);

let generic_activity_len = 5125;
let incremental_hashing_len = 1844;
let query_len = 1877;
let artifact_size_len = 24;
assert_eq!(
grouped_events["GenericActivity"].len(),
generic_activity_len
);
assert_eq!(
grouped_events["IncrementalResultHashing"].len(),
incremental_hashing_len
);
assert_eq!(grouped_events["Query"].len(), query_len);
assert_eq!(grouped_events["ArtifactSize"].len(), artifact_size_len);

assert_eq!(
grouped_events["GenericActivity"][generic_activity_len / 2].label,
"metadata_decode_entry_item_attrs"
);
assert_eq!(
grouped_events["GenericActivity"][generic_activity_len / 2].duration(),
Some(Duration::from_nanos(376))
);

assert_eq!(
grouped_events["IncrementalResultHashing"][incremental_hashing_len - 1].label,
"crate_hash"
);
assert_eq!(
grouped_events["IncrementalResultHashing"][incremental_hashing_len - 1].duration(),
Some(Duration::from_nanos(461))
);

assert_eq!(grouped_events["Query"][0].label, "registered_tools");
assert_eq!(
grouped_events["Query"][0].duration(),
Some(Duration::from_nanos(45077))
);

assert_eq!(

This comment has been minimized.

Copy link
@smklein

smklein Dec 15, 2023

Author Contributor

These assertions about ArtifactSize are new, since I didn't see them in the v8 version, but they're in this version.

This comment has been minimized.

Copy link
@michaelwoerister

michaelwoerister Dec 15, 2023

Member

Yeah, that got added to the compiler semi-recently. No harm in checking it.

grouped_events["ArtifactSize"][0].label,
"codegen_unit_size_estimate"
);
assert_eq!(grouped_events["ArtifactSize"][0].duration(), None);
assert_eq!(grouped_events["ArtifactSize"][0].integer(), Some(3));
}

fn read_data_and_version(file_path: &str) -> (Vec<u8>, u32) {
let data = std::fs::read(file_path).expect("Test data not found");
let mut gz = flate2::read::GzDecoder::new(&data[..]);
Expand Down
Binary file added analyzeme/tests/profdata/v9.mm_profdata.gz
Binary file not shown.

0 comments on commit cdd29c6

Please sign in to comment.