Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Add sourceline dumping to example
Browse files Browse the repository at this point in the history
  • Loading branch information
ranweiler committed Jan 19, 2023
1 parent dc0f7ab commit 7167cb3
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/agent/coverage/examples/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ struct Args {
#[arg(short, long)]
timeout: Option<u64>,

#[arg(short, long)]
source: bool,

command: Vec<String>,
}

Expand Down Expand Up @@ -54,7 +57,11 @@ fn main() -> Result<()> {
.timeout(timeout)
.record()?;

dump_modoff(&recorded.coverage)?;
if args.source {
dump_source_line(&recorded.coverage)?;
} else {
dump_modoff(&recorded.coverage)?;
}

Ok(())
}
Expand All @@ -70,3 +77,15 @@ fn dump_modoff(coverage: &BinaryCoverage) -> Result<()> {

Ok(())
}

fn dump_source_line(binary: &BinaryCoverage) -> Result<()> {
let source = coverage::source::binary_to_source_coverage(binary)?;

for (path, file) in &source.files {
for (line, count) in &file.lines {
println!("{}:{} {}", path, line.number(), count.0);
}
}

Ok(())
}

0 comments on commit 7167cb3

Please sign in to comment.