Skip to content

Commit cfcbb52

Browse files
feat(timings): only parse UTF-8 when necessary
1 parent 115d9e0 commit cfcbb52

File tree

5 files changed

+177
-70
lines changed

5 files changed

+177
-70
lines changed

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

moz-webgpu-cts/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ eula = false
1919

2020
[dependencies]
2121
anyhow = "1.0.95"
22+
bstr = "1.11.3"
2223
camino = { version = "1.1.6", features = ["serde1"] }
2324
chrono = "0.4.38"
2425
clap = { version = "4.4.2", features = ["derive"] }

moz-webgpu-cts/src/aggregate_timings_from_logs.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::{
99
};
1010

1111
use anyhow::Context;
12+
use bstr::{BStr, ByteSlice as _};
1213
use chrono::{DateTime, FixedOffset};
1314
use lazy_format::lazy_format;
1415
use log_line_reader::{
@@ -39,7 +40,7 @@ pub(crate) fn aggregate_timings_from_logs(
3940
// TODO: Do 'em all in parallel!
4041

4142
let mut test_timings_by_file = BTreeMap::new();
42-
let mut buf = String::with_capacity(512);
43+
let mut buf = Vec::with_capacity(512);
4344
for log_path in log_paths.iter() {
4445
let log_path_entry = test_timings_by_file.entry(log_path).or_default();
4546
match process_log(browser, log_path, log_path_entry, &mut buf) {
@@ -68,7 +69,7 @@ fn process_log(
6869
browser: Browser,
6970
log_path: &Path,
7071
log_path_entry: &mut BTreeMap<TestEntryPath<'_>, Duration>,
71-
buf: &mut String,
72+
buf: &mut Vec<u8>,
7273
) -> Result<(), AlreadyReportedToCommandline> {
7374
let mut reader = LogLineReader::new(browser, BufReader::new(File::open(log_path).unwrap()));
7475
let mut next_line = |buf: &mut _| {
@@ -81,7 +82,7 @@ fn process_log(
8182
})
8283
.map_err(|e| {
8384
for e in errs {
84-
render_test_log_line_err(log_path, &*buf, e);
85+
render_test_log_line_err(log_path, BStr::new(&*buf), e);
8586
}
8687
log::error!("{e:?}");
8788
AlreadyReportedToCommandline
@@ -132,9 +133,10 @@ fn process_log(
132133

133134
let extract_test_url_path =
134135
|test_url_path: &LogLineSpans,
135-
buf: &str|
136+
buf: &[u8]|
136137
-> Result<TestEntryPath<'static>, AlreadyReportedToCommandline> {
137138
let test_url_path = test_url_path.get_from(buf);
139+
let test_url_path = BStr::new(test_url_path).to_str().unwrap();
138140
TestEntryPath::from_execution_report(browser, test_url_path)
139141
.map(|p| p.into_owned())
140142
.map_err(|e| {
@@ -145,7 +147,7 @@ fn process_log(
145147
};
146148

147149
// TODO: Use control flow, not parser state? 🤔
148-
let mut next_line = |buf: &mut String| {
150+
let mut next_line = |buf: &mut Vec<u8>| {
149151
buf.clear();
150152
next_line(buf)
151153
};
@@ -277,7 +279,7 @@ impl From<LogLineSpans> for SourceSpan {
277279
}
278280
}
279281

280-
fn render_test_log_line_err(log_path: &Path, buf: &str, e: RecognizedLogLineParseError) {
282+
fn render_test_log_line_err(log_path: &Path, buf: &BStr, e: RecognizedLogLineParseError) {
281283
let RecognizedLogLineParseError { line_num, kind } = e;
282284
// TODO: use `camino` paths, save everyone some pain 😭
283285
let log_and_line_prepend =
@@ -332,6 +334,15 @@ fn render_test_log_line_err(log_path: &Path, buf: &str, e: RecognizedLogLinePars
332334
labels = test_path_parse_labels(inner),
333335
"{log_and_line_prepend}failed to parse `START`ed test path"
334336
),
337+
ParseTestStartError::ReadTestPathAsUtf8 { valid_up_to_span } => {
338+
miette::diagnostic!(
339+
labels = vec![LabeledSpan::new_primary_with_span(
340+
Some("valid up to here".to_owned()),
341+
valid_up_to_span
342+
)],
343+
"sdasdsadasdad"
344+
)
345+
}
335346
},
336347
RecognizedLogLineParseErrorKind::ExpectedTestEnd(e) => match e {
337348
ParseExpectedTestEndError::SectionDividerBwDiscriminantAndTestPath { span } => {
@@ -353,6 +364,6 @@ fn render_test_log_line_err(log_path: &Path, buf: &str, e: RecognizedLogLinePars
353364
env!("CARGO_BIN_NAME"),
354365
"`. You should file an issue upstream!"
355366
));
356-
let diagnostic = Report::new(diagnostic).with_source_code(buf.to_owned());
367+
let diagnostic = Report::new(diagnostic).with_source_code(Vec::from(buf.to_owned()));
357368
eprintln!("{diagnostic:?}")
358369
}

0 commit comments

Comments
 (0)