about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2024-10-08 13:13:05 +1100
committerZalathar <Zalathar@users.noreply.github.com>2024-10-11 21:04:37 +1100
commit599f95ecc26fb68cccbf79780dd1825a4cf73eb0 (patch)
treece4a2c66912ac798355db676724e3bb8957726f7 /src
parentce697f919d88b143d70312c0e7f3952fcb9869db (diff)
downloadrust-599f95ecc26fb68cccbf79780dd1825a4cf73eb0.tar.gz
rust-599f95ecc26fb68cccbf79780dd1825a4cf73eb0.zip
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.)
Diffstat (limited to 'src')
-rw-r--r--src/tools/coverage-dump/src/covfun.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/tools/coverage-dump/src/covfun.rs b/src/tools/coverage-dump/src/covfun.rs
index c779dd0583c..33fac3edccd 100644
--- a/src/tools/coverage-dump/src/covfun.rs
+++ b/src/tools/coverage-dump/src/covfun.rs
@@ -56,6 +56,7 @@ 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}");
@@ -63,6 +64,11 @@ pub(crate) fn dump_covfun_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.
@@ -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(())
@@ -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.