Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#496] multiple outputs #893

Merged
merged 12 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 36 additions & 37 deletions benches/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,53 @@
extern crate test;

use grcov::{
output_activedata_etl, output_covdir, output_lcov, CovResult, CovResultIter, Function,
FunctionMap,
output_activedata_etl, output_covdir, output_lcov, CovResult, Function, FunctionMap,
ResultTuple,
};
use rustc_hash::FxHashMap;
use std::path::PathBuf;
use tempfile::tempdir;
use test::{black_box, Bencher};

fn generate_cov_result_iter() -> CovResultIter {
Box::new(
FxHashMap::default()
.into_iter()
.map(|(_, _): (PathBuf, CovResult)| {
(
PathBuf::from(""),
PathBuf::from(""),
CovResult {
branches: [].iter().cloned().collect(),
functions: {
let mut functions: FunctionMap = FxHashMap::default();
functions.insert(
"f1".to_string(),
Function {
start: 1,
executed: true,
},
);
functions.insert(
"f2".to_string(),
Function {
start: 2,
executed: false,
},
);
functions
},
lines: [(1, 21), (2, 7), (7, 0)].iter().cloned().collect(),
fn generate_cov_result_iter() -> Vec<ResultTuple> {
FxHashMap::default()
.into_iter()
.map(|(_, _): (PathBuf, CovResult)| {
(
PathBuf::from(""),
PathBuf::from(""),
CovResult {
branches: [].iter().cloned().collect(),
functions: {
let mut functions: FunctionMap = FxHashMap::default();
functions.insert(
"f1".to_string(),
Function {
start: 1,
executed: true,
},
);
functions.insert(
"f2".to_string(),
Function {
start: 2,
executed: false,
},
);
functions
},
)
}),
)
lines: [(1, 21), (2, 7), (7, 0)].iter().cloned().collect(),
},
)
})
.collect::<Vec<_>>()
}
#[bench]
fn bench_output_activedata_etl(b: &mut Bencher) {
let dir = tempdir().unwrap();
b.iter(|| {
black_box(output_activedata_etl(
generate_cov_result_iter(),
&generate_cov_result_iter(),
Some(&dir.path().join("temp")),
false,
))
Expand All @@ -62,7 +61,7 @@ fn bench_output_covdir(b: &mut Bencher) {
let dir = tempdir().unwrap();
b.iter(|| {
black_box(output_covdir(
generate_cov_result_iter(),
&generate_cov_result_iter(),
Some(&dir.path().join("temp")),
));
});
Expand All @@ -73,7 +72,7 @@ fn bench_output_lcov(b: &mut Bencher) {
let dir = tempdir().unwrap();
b.iter(|| {
black_box(output_lcov(
generate_cov_result_iter(),
&generate_cov_result_iter(),
Some(&dir.path().join("temp")),
false,
));
Expand Down
33 changes: 13 additions & 20 deletions src/cobertura.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::defs::*;
use quick_xml::{
events::{BytesDecl, BytesEnd, BytesStart, BytesText, Event},
Writer,
Expand All @@ -9,7 +10,6 @@ use std::time::{SystemTime, UNIX_EPOCH};
use symbolic_common::Name;
use symbolic_demangle::{Demangle, DemangleOptions};

use crate::defs::CovResultIter;
use crate::output::get_target_output_writable;

macro_rules! demangle {
Expand Down Expand Up @@ -229,12 +229,13 @@ impl ToString for ConditionType {
}

fn get_coverage(
results: CovResultIter,
results: &[ResultTuple],
sources: Vec<String>,
demangle: bool,
demangle_options: DemangleOptions,
) -> Coverage {
let packages: Vec<Package> = results
.iter()
.map(|(_, rel_path, result)| {
let all_lines: Vec<u32> = result.lines.iter().map(|(k, _)| k).cloned().collect();

Expand All @@ -246,13 +247,9 @@ fn get_coverage(
}
start_indexes.sort_unstable();

let functions = result.functions;
let result_lines = result.lines;
let result_branches = result.branches;

let line_from_number = |number| {
let hits = result_lines.get(&number).cloned().unwrap_or_default();
if let Some(branches) = result_branches.get(&number) {
let hits = result.lines.get(&number).cloned().unwrap_or_default();
if let Some(branches) = result.branches.get(&number) {
let conditions = branches
.iter()
.enumerate()
Expand All @@ -272,7 +269,8 @@ fn get_coverage(
}
};

let methods: Vec<Method> = functions
let methods: Vec<Method> = result
.functions
.iter()
.map(|(name, function)| {
let mut func_end = end;
Expand Down Expand Up @@ -329,7 +327,7 @@ fn get_coverage(

pub fn output_cobertura(
source_dir: Option<&Path>,
results: CovResultIter,
results: &[ResultTuple],
output_file: Option<&Path>,
demangle: bool,
) {
Expand Down Expand Up @@ -714,8 +712,7 @@ mod tests {
coverage_result(Result::Main),
)];

let results = Box::new(results.into_iter());
output_cobertura(None, results, Some(&file_path), true);
output_cobertura(None, &results, Some(&file_path), true);

let results = read_file(&file_path);

Expand Down Expand Up @@ -749,8 +746,7 @@ mod tests {
coverage_result(Result::Test),
)];

let results = Box::new(results.into_iter());
output_cobertura(None, results, Some(file_path.as_ref()), true);
output_cobertura(None, &results, Some(file_path.as_ref()), true);

let results = read_file(&file_path);

Expand Down Expand Up @@ -789,8 +785,7 @@ mod tests {
),
];

let results = Box::new(results.into_iter());
output_cobertura(None, results, Some(file_path.as_ref()), true);
output_cobertura(None, &results, Some(file_path.as_ref()), true);

let results = read_file(&file_path);

Expand Down Expand Up @@ -822,8 +817,7 @@ mod tests {
CovResult::default(),
)];

let results = Box::new(results.into_iter());
output_cobertura(None, results, Some(&file_path), true);
output_cobertura(None, &results, Some(&file_path), true);

let results = read_file(&file_path);

Expand All @@ -843,8 +837,7 @@ mod tests {
CovResult::default(),
)];

let results = Box::new(results.into_iter());
output_cobertura(Some(Path::new("src")), results, Some(&file_path), true);
output_cobertura(Some(Path::new("src")), &results, Some(&file_path), true);

let results = read_file(&file_path);

Expand Down
2 changes: 1 addition & 1 deletion src/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub type JobSender = Sender<Option<WorkItem>>;

pub type CovResultMap = FxHashMap<String, CovResult>;
pub type SyncCovResultMap = Mutex<CovResultMap>;
pub type CovResultIter = Box<dyn Iterator<Item = (PathBuf, PathBuf, CovResult)>>;
pub type ResultTuple = (PathBuf, PathBuf, CovResult);

#[derive(Debug, Default)]
pub struct CDStats {
Expand Down
Loading