Skip to content

Commit

Permalink
Unrolled build for rust-lang#131476
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#131476 - Zalathar:highest-counter, r=jieyouxu

coverage: Include the highest counter ID seen in `.cov-map` dumps

When making changes that have a large impact on coverage counter creation, this makes it easier to see whether the number of physical counters has changed.

(The highest counter ID seen in coverage maps is not necessarily the same as the number of physical counters actually used by the instrumented code, but it's the best approximation we can get from looking only at the coverage maps, and it should be reasonably accurate in most cases.)

Extracted from rust-lang#131398, since I'm still considering whether to make those changes as-is, whereas this PR is useful and good on its own.
  • Loading branch information
rust-timer authored Oct 11, 2024
2 parents ce697f9 + 599f95e commit a3ee590
Show file tree
Hide file tree
Showing 88 changed files with 338 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/tools/coverage-dump/src/covfun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,19 @@ pub(crate) fn dump_covfun_mappings(
expression_resolver.push_operands(lhs, rhs);
}

let mut max_counter = None;
for i in 0..num_files {
let num_mappings = parser.read_uleb128_u32()?;
println!("Number of file {i} mappings: {num_mappings}");

for _ in 0..num_mappings {
let (kind, region) = parser.read_mapping_kind_and_region()?;
println!("- {kind:?} at {region:?}");
kind.for_each_term(|term| {
if let CovTerm::Counter(n) = term {
max_counter = max_counter.max(Some(n));
}
});

match kind {
// Also print expression mappings in resolved form.
Expand All @@ -83,6 +89,16 @@ pub(crate) fn dump_covfun_mappings(
}

parser.ensure_empty()?;

// Printing the highest counter ID seen in the functions mappings makes
// it easier to determine whether a change to coverage instrumentation
// has increased or decreased the number of physical counters needed.
// (It's possible for the generated code to have more counters that
// aren't used by any mappings, but that should hopefully be rare.)
println!("Highest counter ID seen: {}", match max_counter {
Some(id) => format!("c{id}"),
None => "(none)".to_owned(),
});
println!();
}
Ok(())
Expand Down Expand Up @@ -271,6 +287,32 @@ enum MappingKind {
},
}

impl MappingKind {
fn for_each_term(&self, mut callback: impl FnMut(CovTerm)) {
match *self {
Self::Code(term) => callback(term),
Self::Gap(term) => callback(term),
Self::Expansion(_id) => {}
Self::Skip => {}
Self::Branch { r#true, r#false } => {
callback(r#true);
callback(r#false);
}
Self::MCDCBranch {
r#true,
r#false,
condition_id: _,
true_next_id: _,
false_next_id: _,
} => {
callback(r#true);
callback(r#false);
}
Self::MCDCDecision { bitmap_idx: _, conditions_num: _ } => {}
}
}
}

struct MappingRegion {
/// Offset of this region's start line, relative to the *start line* of
/// the *previous mapping* (or 0). Line numbers are 1-based.
Expand Down
2 changes: 2 additions & 0 deletions tests/coverage/abort.cov-map
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Number of file 0 mappings: 13
- Code(Expression(9, Add)) at (prev + 1, 9) to (start + 0, 23)
= (c1 + c2)
- Code(Counter(3)) at (prev + 2, 5) to (start + 1, 2)
Highest counter ID seen: c5

Function name: abort::might_abort
Raw bytes (21): 0x[01, 01, 01, 01, 05, 03, 01, 03, 01, 01, 14, 05, 02, 09, 01, 24, 02, 02, 0c, 03, 02]
Expand All @@ -46,4 +47,5 @@ Number of file 0 mappings: 3
- Code(Counter(1)) at (prev + 2, 9) to (start + 1, 36)
- Code(Expression(0, Sub)) at (prev + 2, 12) to (start + 3, 2)
= (c0 - c1)
Highest counter ID seen: c1

1 change: 1 addition & 0 deletions tests/coverage/assert-ne.cov-map
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ Number of file 0 mappings: 4
- Code(Expression(0, Sub)) at (prev + 2, 13) to (start + 0, 19)
= (c0 - c1)
- Code(Counter(2)) at (prev + 3, 5) to (start + 1, 2)
Highest counter ID seen: c2

2 changes: 2 additions & 0 deletions tests/coverage/assert.cov-map
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Number of file 0 mappings: 9
- Code(Expression(6, Add)) at (prev + 1, 9) to (start + 0, 23)
= (c1 + (c2 + c3))
- Code(Counter(4)) at (prev + 2, 5) to (start + 1, 2)
Highest counter ID seen: c4

Function name: assert::might_fail_assert
Raw bytes (21): 0x[01, 01, 01, 01, 05, 03, 01, 04, 01, 02, 0f, 02, 02, 25, 00, 3d, 05, 01, 01, 00, 02]
Expand All @@ -37,4 +38,5 @@ Number of file 0 mappings: 3
- Code(Expression(0, Sub)) at (prev + 2, 37) to (start + 0, 61)
= (c0 - c1)
- Code(Counter(1)) at (prev + 1, 1) to (start + 0, 2)
Highest counter ID seen: c1

1 change: 1 addition & 0 deletions tests/coverage/assert_not.cov-map
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ Number of file 0 mappings: 5
- Code(Counter(3)) at (prev + 1, 5) to (start + 0, 22)
- Code(Expression(1, Sub)) at (prev + 1, 1) to (start + 0, 2)
= (c3 - Zero)
Highest counter ID seen: c3

25 changes: 25 additions & 0 deletions tests/coverage/async.cov-map
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Number of files: 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 12, 1) to (start + 0, 25)
Highest counter ID seen: c0

Function name: async::c::{closure#0}
Raw bytes (26): 0x[01, 01, 01, 01, 05, 04, 01, 0c, 19, 01, 0e, 05, 02, 09, 00, 0a, 02, 02, 09, 00, 0a, 01, 02, 01, 00, 02]
Expand All @@ -18,6 +19,7 @@ Number of file 0 mappings: 4
- Code(Expression(0, Sub)) at (prev + 2, 9) to (start + 0, 10)
= (c0 - c1)
- Code(Counter(0)) at (prev + 2, 1) to (start + 0, 2)
Highest counter ID seen: c1

Function name: async::d
Raw bytes (9): 0x[01, 01, 00, 01, 01, 14, 01, 00, 14]
Expand All @@ -26,6 +28,7 @@ Number of files: 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 20, 1) to (start + 0, 20)
Highest counter ID seen: c0

Function name: async::d::{closure#0}
Raw bytes (9): 0x[01, 01, 00, 01, 01, 14, 14, 00, 19]
Expand All @@ -34,6 +37,7 @@ Number of files: 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 20, 20) to (start + 0, 25)
Highest counter ID seen: c0

Function name: async::e (unused)
Raw bytes (9): 0x[01, 01, 00, 01, 00, 16, 01, 00, 14]
Expand All @@ -42,6 +46,7 @@ Number of files: 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Zero) at (prev + 22, 1) to (start + 0, 20)
Highest counter ID seen: (none)

Function name: async::e::{closure#0} (unused)
Raw bytes (9): 0x[01, 01, 00, 01, 00, 16, 14, 00, 19]
Expand All @@ -50,6 +55,7 @@ Number of files: 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Zero) at (prev + 22, 20) to (start + 0, 25)
Highest counter ID seen: (none)

Function name: async::f
Raw bytes (9): 0x[01, 01, 00, 01, 01, 18, 01, 00, 14]
Expand All @@ -58,6 +64,7 @@ Number of files: 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 24, 1) to (start + 0, 20)
Highest counter ID seen: c0

Function name: async::f::{closure#0}
Raw bytes (9): 0x[01, 01, 00, 01, 01, 18, 14, 00, 19]
Expand All @@ -66,6 +73,7 @@ Number of files: 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 24, 20) to (start + 0, 25)
Highest counter ID seen: c0

Function name: async::foo (unused)
Raw bytes (9): 0x[01, 01, 00, 01, 00, 1a, 01, 00, 1e]
Expand All @@ -74,6 +82,7 @@ Number of files: 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Zero) at (prev + 26, 1) to (start + 0, 30)
Highest counter ID seen: (none)

Function name: async::foo::{closure#0} (unused)
Raw bytes (9): 0x[01, 01, 00, 01, 00, 1a, 1e, 00, 2d]
Expand All @@ -82,6 +91,7 @@ Number of files: 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Zero) at (prev + 26, 30) to (start + 0, 45)
Highest counter ID seen: (none)

Function name: async::g
Raw bytes (9): 0x[01, 01, 00, 01, 01, 1c, 01, 00, 17]
Expand All @@ -90,6 +100,7 @@ Number of files: 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 28, 1) to (start + 0, 23)
Highest counter ID seen: c0

Function name: async::g::{closure#0} (unused)
Raw bytes (59): 0x[01, 01, 00, 0b, 00, 1c, 17, 01, 0c, 00, 02, 09, 00, 0a, 00, 00, 0e, 00, 17, 00, 00, 1b, 00, 1c, 00, 00, 20, 00, 22, 00, 01, 09, 00, 0a, 00, 00, 0e, 00, 17, 00, 00, 1b, 00, 1c, 00, 00, 20, 00, 22, 00, 01, 0e, 00, 10, 00, 02, 01, 00, 02]
Expand All @@ -108,6 +119,7 @@ Number of file 0 mappings: 11
- Code(Zero) at (prev + 0, 32) to (start + 0, 34)
- Code(Zero) at (prev + 1, 14) to (start + 0, 16)
- Code(Zero) at (prev + 2, 1) to (start + 0, 2)
Highest counter ID seen: (none)

Function name: async::h
Raw bytes (9): 0x[01, 01, 00, 01, 01, 24, 01, 00, 16]
Expand All @@ -116,6 +128,7 @@ Number of files: 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 36, 1) to (start + 0, 22)
Highest counter ID seen: c0

Function name: async::h::{closure#0} (unused)
Raw bytes (39): 0x[01, 01, 00, 07, 00, 24, 16, 03, 0c, 00, 04, 09, 00, 0a, 00, 00, 0e, 00, 19, 00, 00, 1a, 00, 1b, 00, 00, 20, 00, 22, 00, 01, 0e, 00, 10, 00, 02, 01, 00, 02]
Expand All @@ -130,6 +143,7 @@ Number of file 0 mappings: 7
- Code(Zero) at (prev + 0, 32) to (start + 0, 34)
- Code(Zero) at (prev + 1, 14) to (start + 0, 16)
- Code(Zero) at (prev + 2, 1) to (start + 0, 2)
Highest counter ID seen: (none)

Function name: async::i
Raw bytes (9): 0x[01, 01, 00, 01, 01, 2d, 01, 00, 13]
Expand All @@ -138,6 +152,7 @@ Number of files: 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 45, 1) to (start + 0, 19)
Highest counter ID seen: c0

Function name: async::i::{closure#0}
Raw bytes (63): 0x[01, 01, 02, 07, 19, 11, 15, 0b, 01, 2d, 13, 04, 0c, 09, 05, 09, 00, 0a, 01, 00, 0e, 00, 18, 05, 00, 1c, 00, 21, 09, 00, 27, 00, 30, 15, 01, 09, 00, 0a, 0d, 00, 0e, 00, 17, 1d, 00, 1b, 00, 20, 15, 00, 24, 00, 26, 19, 01, 0e, 00, 10, 03, 02, 01, 00, 02]
Expand All @@ -159,6 +174,7 @@ Number of file 0 mappings: 11
- Code(Counter(6)) at (prev + 1, 14) to (start + 0, 16)
- Code(Expression(0, Add)) at (prev + 2, 1) to (start + 0, 2)
= ((c4 + c5) + c6)
Highest counter ID seen: c7

Function name: async::j
Raw bytes (58): 0x[01, 01, 02, 07, 0d, 05, 09, 0a, 01, 38, 01, 00, 0d, 01, 0b, 0b, 00, 0c, 05, 01, 09, 00, 0a, 01, 00, 0e, 00, 1b, 05, 00, 1f, 00, 27, 09, 01, 09, 00, 0a, 11, 00, 0e, 00, 1a, 09, 00, 1e, 00, 20, 0d, 01, 0e, 00, 10, 03, 02, 01, 00, 02]
Expand All @@ -179,6 +195,7 @@ Number of file 0 mappings: 10
- Code(Counter(3)) at (prev + 1, 14) to (start + 0, 16)
- Code(Expression(0, Add)) at (prev + 2, 1) to (start + 0, 2)
= ((c1 + c2) + c3)
Highest counter ID seen: c4

Function name: async::j::c
Raw bytes (26): 0x[01, 01, 01, 01, 05, 04, 01, 3a, 05, 01, 12, 05, 02, 0d, 00, 0e, 02, 02, 0d, 00, 0e, 01, 02, 05, 00, 06]
Expand All @@ -192,6 +209,7 @@ Number of file 0 mappings: 4
- Code(Expression(0, Sub)) at (prev + 2, 13) to (start + 0, 14)
= (c0 - c1)
- Code(Counter(0)) at (prev + 2, 5) to (start + 0, 6)
Highest counter ID seen: c1

Function name: async::j::d
Raw bytes (9): 0x[01, 01, 00, 01, 01, 41, 05, 00, 17]
Expand All @@ -200,6 +218,7 @@ Number of files: 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 65, 5) to (start + 0, 23)
Highest counter ID seen: c0

Function name: async::j::f
Raw bytes (9): 0x[01, 01, 00, 01, 01, 42, 05, 00, 17]
Expand All @@ -208,6 +227,7 @@ Number of files: 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 66, 5) to (start + 0, 23)
Highest counter ID seen: c0

Function name: async::k (unused)
Raw bytes (29): 0x[01, 01, 00, 05, 00, 4a, 01, 01, 0c, 00, 02, 0e, 00, 10, 00, 01, 0e, 00, 10, 00, 01, 0e, 00, 10, 00, 02, 01, 00, 02]
Expand All @@ -220,6 +240,7 @@ Number of file 0 mappings: 5
- Code(Zero) at (prev + 1, 14) to (start + 0, 16)
- Code(Zero) at (prev + 1, 14) to (start + 0, 16)
- Code(Zero) at (prev + 2, 1) to (start + 0, 2)
Highest counter ID seen: (none)

Function name: async::l
Raw bytes (37): 0x[01, 01, 04, 01, 07, 05, 09, 0f, 02, 09, 05, 05, 01, 52, 01, 01, 0c, 02, 02, 0e, 00, 10, 05, 01, 0e, 00, 10, 09, 01, 0e, 00, 10, 0b, 02, 01, 00, 02]
Expand All @@ -238,6 +259,7 @@ Number of file 0 mappings: 5
- Code(Counter(2)) at (prev + 1, 14) to (start + 0, 16)
- Code(Expression(2, Add)) at (prev + 2, 1) to (start + 0, 2)
= ((c2 + c1) + (c0 - (c1 + c2)))
Highest counter ID seen: c2

Function name: async::m
Raw bytes (9): 0x[01, 01, 00, 01, 01, 5a, 01, 00, 19]
Expand All @@ -246,6 +268,7 @@ Number of files: 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 90, 1) to (start + 0, 25)
Highest counter ID seen: c0

Function name: async::m::{closure#0} (unused)
Raw bytes (9): 0x[01, 01, 00, 01, 00, 5a, 19, 00, 22]
Expand All @@ -254,6 +277,7 @@ Number of files: 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Zero) at (prev + 90, 25) to (start + 0, 34)
Highest counter ID seen: (none)

Function name: async::main
Raw bytes (9): 0x[01, 01, 00, 01, 01, 5c, 01, 08, 02]
Expand All @@ -262,4 +286,5 @@ Number of files: 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 92, 1) to (start + 8, 2)
Highest counter ID seen: c0

6 changes: 6 additions & 0 deletions tests/coverage/async2.cov-map
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Number of files: 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 16, 1) to (start + 0, 23)
Highest counter ID seen: c0

Function name: async2::async_func::{closure#0}
Raw bytes (24): 0x[01, 01, 00, 04, 01, 10, 17, 03, 09, 05, 03, 0a, 02, 06, 00, 02, 06, 00, 07, 01, 01, 01, 00, 02]
Expand All @@ -16,6 +17,7 @@ Number of file 0 mappings: 4
- Code(Counter(1)) at (prev + 3, 10) to (start + 2, 6)
- Code(Zero) at (prev + 2, 6) to (start + 0, 7)
- Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2)
Highest counter ID seen: c1

Function name: async2::async_func_just_println
Raw bytes (9): 0x[01, 01, 00, 01, 01, 18, 01, 00, 24]
Expand All @@ -24,6 +26,7 @@ Number of files: 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 24, 1) to (start + 0, 36)
Highest counter ID seen: c0

Function name: async2::async_func_just_println::{closure#0}
Raw bytes (9): 0x[01, 01, 00, 01, 01, 18, 24, 02, 02]
Expand All @@ -32,6 +35,7 @@ Number of files: 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 24, 36) to (start + 2, 2)
Highest counter ID seen: c0

Function name: async2::main
Raw bytes (9): 0x[01, 01, 00, 01, 01, 1c, 01, 07, 02]
Expand All @@ -40,6 +44,7 @@ Number of files: 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 28, 1) to (start + 7, 2)
Highest counter ID seen: c0

Function name: async2::non_async_func
Raw bytes (24): 0x[01, 01, 00, 04, 01, 08, 01, 03, 09, 05, 03, 0a, 02, 06, 00, 02, 06, 00, 07, 01, 01, 01, 00, 02]
Expand All @@ -51,4 +56,5 @@ Number of file 0 mappings: 4
- Code(Counter(1)) at (prev + 3, 10) to (start + 2, 6)
- Code(Zero) at (prev + 2, 6) to (start + 0, 7)
- Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2)
Highest counter ID seen: c1

2 changes: 2 additions & 0 deletions tests/coverage/async_block.cov-map
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Number of file 0 mappings: 6
- Code(Counter(1)) at (prev + 0, 20) to (start + 1, 22)
- Code(Counter(1)) at (prev + 7, 10) to (start + 2, 6)
- Code(Counter(0)) at (prev + 3, 1) to (start + 0, 2)
Highest counter ID seen: c1

Function name: async_block::main::{closure#0}
Raw bytes (26): 0x[01, 01, 01, 01, 05, 04, 01, 0a, 1c, 01, 17, 05, 01, 18, 02, 0e, 02, 02, 14, 02, 0e, 01, 03, 09, 00, 0a]
Expand All @@ -25,4 +26,5 @@ Number of file 0 mappings: 4
- Code(Expression(0, Sub)) at (prev + 2, 20) to (start + 2, 14)
= (c0 - c1)
- Code(Counter(0)) at (prev + 3, 9) to (start + 0, 10)
Highest counter ID seen: c1

3 changes: 3 additions & 0 deletions tests/coverage/attr/impl.cov-map
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Number of files: 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Zero) at (prev + 14, 5) to (start + 0, 19)
Highest counter ID seen: (none)

Function name: <impl::MyStruct>::on_inherit (unused)
Raw bytes (9): 0x[01, 01, 00, 01, 00, 16, 05, 00, 17]
Expand All @@ -13,6 +14,7 @@ Number of files: 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Zero) at (prev + 22, 5) to (start + 0, 23)
Highest counter ID seen: (none)

Function name: <impl::MyStruct>::on_on (unused)
Raw bytes (9): 0x[01, 01, 00, 01, 00, 19, 05, 00, 12]
Expand All @@ -21,4 +23,5 @@ Number of files: 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Zero) at (prev + 25, 5) to (start + 0, 18)
Highest counter ID seen: (none)

Loading

0 comments on commit a3ee590

Please sign in to comment.