Skip to content

Commit

Permalink
refactor(cli): process-reports: use rayon and channels to paralle…
Browse files Browse the repository at this point in the history
…lize report parsing
  • Loading branch information
ErichDonGubler committed Oct 31, 2023
1 parent 29dc7dc commit c886ac2
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 26 deletions.
75 changes: 75 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions moz-webgpu-cts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ log = { workspace = true }
miette = { version = "5.10.0", features = ["fancy"] }
natord = "1.0.9"
path-dsl = "0.6.1"
rayon = "1.8.0"
regex = "1.9.5"
serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.107"
Expand Down
56 changes: 30 additions & 26 deletions moz-webgpu-cts/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::{
io::{self, BufReader, BufWriter},
path::{Path, PathBuf},
process::ExitCode,
sync::Arc,
sync::{mpsc::channel, Arc},
};

use clap::Parser;
Expand All @@ -31,7 +31,7 @@ use format::lazy_format;
use indexmap::{IndexMap, IndexSet};
use miette::{miette, Diagnostic, IntoDiagnostic, NamedSource, Report, SourceSpan, WrapErr};
use path_dsl::path;

use rayon::prelude::{IntoParallelIterator, ParallelIterator};
use regex::Regex;
use wax::Glob;
use whippit::{metadata::SectionHeader, reexport::chumsky::prelude::Rich};
Expand Down Expand Up @@ -344,30 +344,34 @@ fn run(cli: Cli) -> ExitCode {

log::info!("gathering reported test outcomes for reconciliation with metadata…");

let exec_reports_iter = exec_report_paths.iter().map(|path| {
fs::File::open(path)
.map(BufReader::new)
.map_err(Report::msg)
.wrap_err("failed to open file")
.and_then(|reader| {
serde_json::from_reader::<_, ExecutionReport>(reader)
.into_diagnostic()
.wrap_err("failed to parse JSON")
})
.map(|parsed| (path, parsed))
.wrap_err_with(|| {
format!(
"failed to read WPT execution report from {}",
path.display()
)
})
.map_err(|e| {
log::error!("{e:?}");
AlreadyReportedToCommandline
})
});

for res in exec_reports_iter {
let (exec_reports_sender, exec_reports_receiver) = channel();
exec_report_paths
.into_par_iter()
.for_each_with(exec_reports_sender, |sender, path| {
let res = fs::File::open(&path)
.map(BufReader::new)
.map_err(Report::msg)
.wrap_err("failed to open file")
.and_then(|reader| {
serde_json::from_reader::<_, ExecutionReport>(reader)
.into_diagnostic()
.wrap_err("failed to parse JSON")
})
.wrap_err_with(|| {
format!(
"failed to read WPT execution report from {}",
path.display()
)
})
.map(|parsed| (path, parsed))
.map_err(|e| {
log::error!("{e:?}");
AlreadyReportedToCommandline
});
let _ = sender.send(res);
});

for res in exec_reports_receiver {
let (_path, exec_report) = match res {
Ok(ok) => ok,
Err(AlreadyReportedToCommandline) => return ExitCode::FAILURE,
Expand Down

0 comments on commit c886ac2

Please sign in to comment.