Skip to content

Commit a9fe2f7

Browse files
committed
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.)
1 parent eb4e234 commit a9fe2f7

File tree

89 files changed

+339
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+339
-0
lines changed

Diff for: src/tools/coverage-dump/src/covfun.rs

+42
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,19 @@ pub(crate) fn dump_covfun_mappings(
5656
expression_resolver.push_operands(lhs, rhs);
5757
}
5858

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

6364
for _ in 0..num_mappings {
6465
let (kind, region) = parser.read_mapping_kind_and_region()?;
6566
println!("- {kind:?} at {region:?}");
67+
kind.for_each_term(|term| {
68+
if let CovTerm::Counter(n) = term {
69+
max_counter = max_counter.max(Some(n));
70+
}
71+
});
6672

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

8591
parser.ensure_empty()?;
92+
93+
// Printing the highest counter ID seen in the functions mappings makes
94+
// it easier to determine whether a change to coverage instrumentation
95+
// has increased or decreased the number of physical counters needed.
96+
// (It's possible for the generated code to have more counters that
97+
// aren't used by any mappings, but that should hopefully be rare.)
98+
println!("Highest counter ID seen: {}", match max_counter {
99+
Some(id) => format!("c{id}"),
100+
None => "(none)".to_owned(),
101+
});
86102
println!();
87103
}
88104
Ok(())
@@ -271,6 +287,32 @@ enum MappingKind {
271287
},
272288
}
273289

290+
impl MappingKind {
291+
fn for_each_term(&self, mut callback: impl FnMut(CovTerm)) {
292+
match *self {
293+
Self::Code(term) => callback(term),
294+
Self::Gap(term) => callback(term),
295+
Self::Expansion(_id) => {}
296+
Self::Skip => {}
297+
Self::Branch { r#true, r#false } => {
298+
callback(r#true);
299+
callback(r#false);
300+
}
301+
Self::MCDCBranch {
302+
r#true,
303+
r#false,
304+
condition_id: _,
305+
true_next_id: _,
306+
false_next_id: _,
307+
} => {
308+
callback(r#true);
309+
callback(r#false);
310+
}
311+
Self::MCDCDecision { bitmap_idx: _, conditions_num: _ } => {}
312+
}
313+
}
314+
}
315+
274316
struct MappingRegion {
275317
/// Offset of this region's start line, relative to the *start line* of
276318
/// the *previous mapping* (or 0). Line numbers are 1-based.

Diff for: tests/coverage/abort.cov-map

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Number of file 0 mappings: 13
3434
- Code(Expression(9, Add)) at (prev + 1, 9) to (start + 0, 23)
3535
= (c1 + c2)
3636
- Code(Counter(3)) at (prev + 2, 5) to (start + 1, 2)
37+
Highest counter ID seen: c5
3738

3839
Function name: abort::might_abort
3940
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]
@@ -46,4 +47,5 @@ Number of file 0 mappings: 3
4647
- Code(Counter(1)) at (prev + 2, 9) to (start + 1, 36)
4748
- Code(Expression(0, Sub)) at (prev + 2, 12) to (start + 3, 2)
4849
= (c0 - c1)
50+
Highest counter ID seen: c1
4951

Diff for: tests/coverage/assert-ne.cov-map

+1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ Number of file 0 mappings: 4
1010
- Code(Expression(0, Sub)) at (prev + 2, 13) to (start + 0, 19)
1111
= (c0 - c1)
1212
- Code(Counter(2)) at (prev + 3, 5) to (start + 1, 2)
13+
Highest counter ID seen: c2
1314

Diff for: tests/coverage/assert.cov-map

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Number of file 0 mappings: 9
2525
- Code(Expression(6, Add)) at (prev + 1, 9) to (start + 0, 23)
2626
= (c1 + (c2 + c3))
2727
- Code(Counter(4)) at (prev + 2, 5) to (start + 1, 2)
28+
Highest counter ID seen: c4
2829

2930
Function name: assert::might_fail_assert
3031
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]
@@ -37,4 +38,5 @@ Number of file 0 mappings: 3
3738
- Code(Expression(0, Sub)) at (prev + 2, 37) to (start + 0, 61)
3839
= (c0 - c1)
3940
- Code(Counter(1)) at (prev + 1, 1) to (start + 0, 2)
41+
Highest counter ID seen: c1
4042

Diff for: tests/coverage/assert_not.cov-map

+1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ Number of file 0 mappings: 5
1313
- Code(Counter(3)) at (prev + 1, 5) to (start + 0, 22)
1414
- Code(Expression(1, Sub)) at (prev + 1, 1) to (start + 0, 2)
1515
= (c3 - Zero)
16+
Highest counter ID seen: c3
1617

Diff for: tests/coverage/async.cov-map

+25
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Number of files: 1
55
Number of expressions: 0
66
Number of file 0 mappings: 1
77
- Code(Counter(0)) at (prev + 12, 1) to (start + 0, 25)
8+
Highest counter ID seen: c0
89

910
Function name: async::c::{closure#0}
1011
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]
@@ -18,6 +19,7 @@ Number of file 0 mappings: 4
1819
- Code(Expression(0, Sub)) at (prev + 2, 9) to (start + 0, 10)
1920
= (c0 - c1)
2021
- Code(Counter(0)) at (prev + 2, 1) to (start + 0, 2)
22+
Highest counter ID seen: c1
2123

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

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

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

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

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

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

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

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

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

94105
Function name: async::g::{closure#0} (unused)
95106
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]
@@ -108,6 +119,7 @@ Number of file 0 mappings: 11
108119
- Code(Zero) at (prev + 0, 32) to (start + 0, 34)
109120
- Code(Zero) at (prev + 1, 14) to (start + 0, 16)
110121
- Code(Zero) at (prev + 2, 1) to (start + 0, 2)
122+
Highest counter ID seen: (none)
111123

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

120133
Function name: async::h::{closure#0} (unused)
121134
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]
@@ -130,6 +143,7 @@ Number of file 0 mappings: 7
130143
- Code(Zero) at (prev + 0, 32) to (start + 0, 34)
131144
- Code(Zero) at (prev + 1, 14) to (start + 0, 16)
132145
- Code(Zero) at (prev + 2, 1) to (start + 0, 2)
146+
Highest counter ID seen: (none)
133147

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

142157
Function name: async::i::{closure#0}
143158
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]
@@ -159,6 +174,7 @@ Number of file 0 mappings: 11
159174
- Code(Counter(6)) at (prev + 1, 14) to (start + 0, 16)
160175
- Code(Expression(0, Add)) at (prev + 2, 1) to (start + 0, 2)
161176
= ((c4 + c5) + c6)
177+
Highest counter ID seen: c7
162178

163179
Function name: async::j
164180
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]
@@ -179,6 +195,7 @@ Number of file 0 mappings: 10
179195
- Code(Counter(3)) at (prev + 1, 14) to (start + 0, 16)
180196
- Code(Expression(0, Add)) at (prev + 2, 1) to (start + 0, 2)
181197
= ((c1 + c2) + c3)
198+
Highest counter ID seen: c4
182199

183200
Function name: async::j::c
184201
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]
@@ -192,6 +209,7 @@ Number of file 0 mappings: 4
192209
- Code(Expression(0, Sub)) at (prev + 2, 13) to (start + 0, 14)
193210
= (c0 - c1)
194211
- Code(Counter(0)) at (prev + 2, 5) to (start + 0, 6)
212+
Highest counter ID seen: c1
195213

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

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

212232
Function name: async::k (unused)
213233
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]
@@ -220,6 +240,7 @@ Number of file 0 mappings: 5
220240
- Code(Zero) at (prev + 1, 14) to (start + 0, 16)
221241
- Code(Zero) at (prev + 1, 14) to (start + 0, 16)
222242
- Code(Zero) at (prev + 2, 1) to (start + 0, 2)
243+
Highest counter ID seen: (none)
223244

224245
Function name: async::l
225246
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]
@@ -238,6 +259,7 @@ Number of file 0 mappings: 5
238259
- Code(Counter(2)) at (prev + 1, 14) to (start + 0, 16)
239260
- Code(Expression(2, Add)) at (prev + 2, 1) to (start + 0, 2)
240261
= ((c2 + c1) + (c0 - (c1 + c2)))
262+
Highest counter ID seen: c2
241263

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

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

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

Diff for: tests/coverage/async2.cov-map

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Number of files: 1
55
Number of expressions: 0
66
Number of file 0 mappings: 1
77
- Code(Counter(0)) at (prev + 16, 1) to (start + 0, 23)
8+
Highest counter ID seen: c0
89

910
Function name: async2::async_func::{closure#0}
1011
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]
@@ -16,6 +17,7 @@ Number of file 0 mappings: 4
1617
- Code(Counter(1)) at (prev + 3, 10) to (start + 2, 6)
1718
- Code(Zero) at (prev + 2, 6) to (start + 0, 7)
1819
- Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2)
20+
Highest counter ID seen: c1
1921

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

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

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

4449
Function name: async2::non_async_func
4550
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]
@@ -51,4 +56,5 @@ Number of file 0 mappings: 4
5156
- Code(Counter(1)) at (prev + 3, 10) to (start + 2, 6)
5257
- Code(Zero) at (prev + 2, 6) to (start + 0, 7)
5358
- Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2)
59+
Highest counter ID seen: c1
5460

Diff for: tests/coverage/async_block.cov-map

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Number of file 0 mappings: 6
1212
- Code(Counter(1)) at (prev + 0, 20) to (start + 1, 22)
1313
- Code(Counter(1)) at (prev + 7, 10) to (start + 2, 6)
1414
- Code(Counter(0)) at (prev + 3, 1) to (start + 0, 2)
15+
Highest counter ID seen: c1
1516

1617
Function name: async_block::main::{closure#0}
1718
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]
@@ -25,4 +26,5 @@ Number of file 0 mappings: 4
2526
- Code(Expression(0, Sub)) at (prev + 2, 20) to (start + 2, 14)
2627
= (c0 - c1)
2728
- Code(Counter(0)) at (prev + 3, 9) to (start + 0, 10)
29+
Highest counter ID seen: c1
2830

Diff for: tests/coverage/attr/impl.cov-map

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Number of files: 1
55
Number of expressions: 0
66
Number of file 0 mappings: 1
77
- Code(Zero) at (prev + 14, 5) to (start + 0, 19)
8+
Highest counter ID seen: (none)
89

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

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

0 commit comments

Comments
 (0)