Skip to content

Commit 7c1548b

Browse files
feat(timings): only parse UTF-8 when necessary
1 parent 109a6d9 commit 7c1548b

5 files changed

Lines changed: 178 additions & 71 deletions

File tree

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 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
@@ -143,9 +144,10 @@ fn process_log(
143144

144145
let extract_test_url_path =
145146
|test_url_path: &LogLineSpans,
146-
buf: &str|
147+
buf: &[u8]|
147148
-> Result<TestEntryPath<'static>, AlreadyReportedToCommandline> {
148149
let test_url_path = test_url_path.get_from(buf);
150+
let test_url_path = BStr::new(test_url_path).to_str().unwrap();
149151
TestEntryPath::from_execution_report(browser, test_url_path)
150152
.map(|p| p.into_owned())
151153
.map_err(|e| {
@@ -156,7 +158,7 @@ fn process_log(
156158
};
157159

158160
// TODO: Use control flow, not parser state? 🤔
159-
let mut next_line = |buf: &mut String| {
161+
let mut next_line = |buf: &mut Vec<u8>| {
160162
buf.clear();
161163
next_line(buf)
162164
};
@@ -294,7 +296,7 @@ impl From<LogLineSpans> for SourceSpan {
294296
}
295297
}
296298

297-
fn render_test_log_line_err(log_path: &Path, buf: &str, e: RecognizedLogLineParseError) {
299+
fn render_test_log_line_err(log_path: &Path, buf: &BStr, e: RecognizedLogLineParseError) {
298300
let RecognizedLogLineParseError { line_num, kind } = e;
299301
// TODO: use `camino` paths, save everyone some pain 😭
300302
let log_and_line_prepend =
@@ -349,6 +351,15 @@ fn render_test_log_line_err(log_path: &Path, buf: &str, e: RecognizedLogLinePars
349351
labels = test_path_parse_labels(inner),
350352
"{log_and_line_prepend}failed to parse `START`ed test path"
351353
),
354+
ParseTestStartError::ReadTestPathAsUtf8 { valid_up_to_span } => {
355+
miette::diagnostic!(
356+
labels = vec![LabeledSpan::new_primary_with_span(
357+
Some("valid up to here".to_owned()),
358+
valid_up_to_span
359+
)],
360+
"sdasdsadasdad"
361+
)
362+
}
352363
},
353364
RecognizedLogLineParseErrorKind::ExpectedTestEnd(e) => match e {
354365
ParseExpectedTestEndError::SectionDividerBwDiscriminantAndTestPath { span } => {
@@ -413,6 +424,6 @@ fn render_test_log_line_err(log_path: &Path, buf: &str, e: RecognizedLogLinePars
413424
env!("CARGO_BIN_NAME"),
414425
"`. You should file an issue upstream!"
415426
));
416-
let diagnostic = Report::new(diagnostic).with_source_code(buf.to_owned());
427+
let diagnostic = Report::new(diagnostic).with_source_code(Vec::from(buf.to_owned()));
417428
eprintln!("{diagnostic:?}")
418429
}

0 commit comments

Comments
 (0)