From 30b7d3fcc29ccd8a0c406929119ac0502cbb57c4 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Fri, 25 Nov 2022 11:51:32 -0500 Subject: [PATCH] wip --- oxide/crates/core/Cargo.toml | 1 + oxide/crates/core/src/lib.rs | 29 +++++++++++++++++++++++++++++ oxide/crates/core/src/parser.rs | 8 ++++++++ 3 files changed, 38 insertions(+) diff --git a/oxide/crates/core/Cargo.toml b/oxide/crates/core/Cargo.toml index 0b36fc5cb..4e9160f91 100644 --- a/oxide/crates/core/Cargo.toml +++ b/oxide/crates/core/Cargo.toml @@ -11,6 +11,7 @@ rayon = "1.5.3" fxhash = "0.2.1" crossbeam = "0.8.2" tracing = { version = "0.1.37", features = ["max_level_trace", "release_max_level_warn"] } +tracing-subscriber = "0.3.16" [dev-dependencies] criterion = { version = "0.3", features = ['html_reports'] } diff --git a/oxide/crates/core/src/lib.rs b/oxide/crates/core/src/lib.rs index f6e006f30..559c1acb7 100644 --- a/oxide/crates/core/src/lib.rs +++ b/oxide/crates/core/src/lib.rs @@ -1,5 +1,6 @@ use crate::parser::Extractor; use rayon::prelude::*; +use tracing::event; use std::path::PathBuf; pub mod candidate; @@ -18,10 +19,19 @@ pub struct ChangedContent { } pub fn parse_candidate_strings_from_files(changed_content: Vec) -> Vec { + tracing_subscriber::fmt() + .with_max_level(tracing::Level::INFO) + .with_span_events(tracing_subscriber::fmt::format::FmtSpan::ACTIVE) + .compact() + .init(); + parse_all_blobs(read_all_files(changed_content)) } +#[tracing::instrument(skip(changed_content))] fn read_all_files(changed_content: Vec) -> Vec> { + event!(tracing::Level::INFO, "Reading {:?} file(s)", changed_content.len()); + changed_content .into_par_iter() .map(|c| match (c.file, c.content) { @@ -52,3 +62,22 @@ fn parse_all_blobs(blobs: Vec>) -> Vec { }) .collect() } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_parse_candidate_strings_from_files() { + let changed_content = vec![ChangedContent { + file: Some(PathBuf::from("benches/fixtures/template-000.html")), + content: None, + extension: "html".to_string(), + }]; + + let candidates = parse_candidate_strings_from_files(changed_content); + + assert_eq!(candidates.len(), 808); + assert_eq!(candidates[0], "md:h-72"); + } +} diff --git a/oxide/crates/core/src/parser.rs b/oxide/crates/core/src/parser.rs index aa9ec1ea8..41ba212ed 100644 --- a/oxide/crates/core/src/parser.rs +++ b/oxide/crates/core/src/parser.rs @@ -438,6 +438,14 @@ impl<'a> Iterator for Extractor<'a> { mod test { use super::*; + fn please_trace() { + tracing_subscriber::fmt() + .with_max_level(tracing::Level::TRACE) + .with_span_events(tracing_subscriber::fmt::format::FmtSpan::ACTIVE) + .compact() + .init(); + } + fn run(input: &str, loose: bool) -> Vec<&str> { Extractor::new( input.as_bytes(),