summaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
authorSébastien d'Herbais de Thun <sebastien.d.herbais@gmail.com>2023-04-23 14:33:56 +0200
committerGitHub <noreply@github.com>2023-04-23 14:33:56 +0200
commit561ff979d574f496415c0499345d41da2e1f6e1e (patch)
tree037479ac000bd87a1cb2149e5389b28f08d24051 /src/model
parent2fbb14f712708188649181525813b3ac5a02e0fb (diff)
Add instrumentation (Part 1) (#761)
Diffstat (limited to 'src/model')
-rw-r--r--src/model/content.rs8
-rw-r--r--src/model/introspect.rs7
-rw-r--r--src/model/mod.rs4
-rw-r--r--src/model/styles.rs14
4 files changed, 29 insertions, 4 deletions
diff --git a/src/model/content.rs b/src/model/content.rs
index 619793ec..c2c70f9d 100644
--- a/src/model/content.rs
+++ b/src/model/content.rs
@@ -39,16 +39,19 @@ enum Attr {
impl Content {
/// Create an empty element.
+ #[tracing::instrument()]
pub fn new(func: ElemFunc) -> Self {
Self { func, attrs: EcoVec::new() }
}
/// Create empty content.
+ #[tracing::instrument()]
pub fn empty() -> Self {
Self::new(SequenceElem::func())
}
/// Create a new sequence element from multiples elements.
+ #[tracing::instrument(skip_all)]
pub fn sequence(iter: impl IntoIterator<Item = Self>) -> Self {
let mut iter = iter.into_iter();
let Some(first) = iter.next() else { return Self::empty() };
@@ -91,6 +94,7 @@ impl Content {
}
/// Access the child and styles.
+ #[tracing::instrument(skip_all)]
pub fn to_styled(&self) -> Option<(&Content, &Styles)> {
if !self.is::<StyledElem>() {
return None;
@@ -116,6 +120,7 @@ impl Content {
/// Cast to a trait object if the contained element has the given
/// capability.
+ #[tracing::instrument(skip_all)]
pub fn with<C>(&self) -> Option<&C>
where
C: ?Sized + 'static,
@@ -127,6 +132,7 @@ impl Content {
/// Cast to a mutable trait object if the contained element has the given
/// capability.
+ #[tracing::instrument(skip_all)]
pub fn with_mut<C>(&mut self) -> Option<&mut C>
where
C: ?Sized + 'static,
@@ -174,6 +180,7 @@ impl Content {
}
/// Access a field on the content.
+ #[tracing::instrument(skip_all)]
pub fn field(&self, name: &str) -> Option<Value> {
if let (Some(iter), "children") = (self.to_sequence(), name) {
Some(Value::Array(iter.cloned().map(Value::Content).collect()))
@@ -360,6 +367,7 @@ impl Content {
/// Queries the content tree for all elements that match the given selector.
///
/// Elements produced in `show` rules will not be included in the results.
+ #[tracing::instrument(skip_all)]
pub fn query(&self, selector: Selector) -> Vec<&Content> {
let mut results = Vec::new();
self.traverse(&mut |element| {
diff --git a/src/model/introspect.rs b/src/model/introspect.rs
index 031f2d5e..5a286ec9 100644
--- a/src/model/introspect.rs
+++ b/src/model/introspect.rs
@@ -94,6 +94,7 @@ pub struct Introspector {
impl Introspector {
/// Create a new introspector.
+ #[tracing::instrument(skip(frames))]
pub fn new(frames: &[Frame]) -> Self {
let mut introspector = Self {
pages: frames.len(),
@@ -113,6 +114,7 @@ impl Introspector {
}
/// Extract metadata from a frame.
+ #[tracing::instrument(skip_all)]
fn extract(&mut self, frame: &Frame, page: NonZeroUsize, ts: Transform) {
for (pos, item) in frame.items() {
match item {
@@ -154,6 +156,7 @@ impl Introspector {
}
/// Query for all matching elements.
+ #[tracing::instrument(skip_all)]
pub fn query<'a>(&'a self, selector: &'a Selector) -> Vec<Content> {
match selector {
Selector::Location(location) => self
@@ -168,6 +171,7 @@ impl Introspector {
}
/// Query for the first matching element.
+ #[tracing::instrument(skip_all)]
pub fn query_first<'a>(&'a self, selector: &'a Selector) -> Option<Content> {
match selector {
Selector::Location(location) => {
@@ -178,6 +182,7 @@ impl Introspector {
}
/// Query for a unique element with the label.
+ #[tracing::instrument(skip(self))]
pub fn query_label(&self, label: &Label) -> StrResult<Content> {
let mut found = None;
for elem in self.all().filter(|elem| elem.label() == Some(label)) {
@@ -200,12 +205,14 @@ impl Introspector {
}
/// Gets the page numbering for the given location, if any.
+ #[tracing::instrument(skip(self))]
pub fn page_numbering(&self, location: Location) -> Value {
let page = self.page(location);
self.page_numberings.get(page.get() - 1).cloned().unwrap_or_default()
}
/// Find the position for the given location.
+ #[tracing::instrument(skip(self))]
pub fn position(&self, location: Location) -> Position {
self.elems
.get(&location)
diff --git a/src/model/mod.rs b/src/model/mod.rs
index 7458dc3c..4ec7311a 100644
--- a/src/model/mod.rs
+++ b/src/model/mod.rs
@@ -23,11 +23,13 @@ use crate::World;
/// Typeset content into a fully layouted document.
#[comemo::memoize]
+#[tracing::instrument(skip(world, tracer, content))]
pub fn typeset(
world: Tracked<dyn World>,
mut tracer: TrackedMut<Tracer>,
content: &Content,
) -> SourceResult<Document> {
+ tracing::info!("Starting layout");
let library = world.library();
let styles = StyleChain::new(&library.styles);
@@ -38,6 +40,8 @@ pub fn typeset(
// Relayout until all introspections stabilize.
// If that doesn't happen within five attempts, we give up.
loop {
+ tracing::info!("Layout iteration {iter}");
+
let constraint = Constraint::new();
let mut provider = StabilityProvider::new();
let mut vt = Vt {
diff --git a/src/model/styles.rs b/src/model/styles.rs
index 8b7a829f..9ef74276 100644
--- a/src/model/styles.rs
+++ b/src/model/styles.rs
@@ -360,7 +360,7 @@ impl Selector {
Self::Before { selector, end: location, inclusive } => {
if let Some(content) = introspector.query_first(location) {
let loc = content.location().unwrap();
- Box::new(selector.match_iter_inner(introspector, parent).filter(
+ Box::new(selector.match_iter_inner(introspector, parent).take_while(
move |elem| {
introspector.is_before(
elem.location().unwrap(),
@@ -376,12 +376,12 @@ impl Selector {
Self::After { selector, start: location, inclusive } => {
if let Some(content) = introspector.query_first(location) {
let loc = content.location().unwrap();
- Box::new(selector.match_iter_inner(introspector, parent).filter(
+ Box::new(selector.match_iter_inner(introspector, parent).skip_while(
move |elem| {
- introspector.is_after(
+ introspector.is_before(
elem.location().unwrap(),
loc,
- *inclusive,
+ !*inclusive,
)
},
))
@@ -586,6 +586,7 @@ impl<'a> StyleChain<'a> {
/// The resulting style chain contains styles from `local` as well as
/// `self`. The ones from `local` take precedence over the ones from
/// `self`. For folded properties `local` contributes the inner value.
+ #[tracing::instrument(skip_all)]
pub fn chain<'b>(&'b self, local: &'b Styles) -> StyleChain<'b> {
if local.is_empty() {
*self
@@ -595,6 +596,7 @@ impl<'a> StyleChain<'a> {
}
/// Cast the first value for the given property in the chain.
+ #[tracing::instrument(skip_all)]
pub fn get<T: Cast>(
self,
func: ElemFunc,
@@ -608,6 +610,7 @@ impl<'a> StyleChain<'a> {
}
/// Cast the first value for the given property in the chain.
+ #[tracing::instrument(skip_all)]
pub fn get_resolve<T: Cast + Resolve>(
self,
func: ElemFunc,
@@ -619,6 +622,7 @@ impl<'a> StyleChain<'a> {
}
/// Cast the first value for the given property in the chain.
+ #[tracing::instrument(skip_all)]
pub fn get_fold<T: Cast + Fold>(
self,
func: ElemFunc,
@@ -640,6 +644,7 @@ impl<'a> StyleChain<'a> {
}
/// Cast the first value for the given property in the chain.
+ #[tracing::instrument(skip_all)]
pub fn get_resolve_fold<T>(
self,
func: ElemFunc,
@@ -674,6 +679,7 @@ impl<'a> StyleChain<'a> {
}
/// Iterate over all values for the given property in the chain.
+ #[tracing::instrument(skip_all)]
pub fn properties<T: Cast + 'a>(
self,
func: ElemFunc,