Skip to content

Commit

Permalink
Add basic tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
matthunz committed Jan 21, 2024
1 parent 0179a3d commit 03a5230
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions crates/concoct/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ description = "Cross-platform UI framework"
repository = "https://github.com/concoct-rs/concoct"

[features]
full = []
full = ["tracing"]

[dependencies]
futures = "0.3.30"
rustc-hash = "1.1.0"
slotmap = "1.0.7"
tracing = "0.1.40"
tracing = { version ="0.1.40", optional = true }

[package.metadata.docs.rs]
features = ["full"]
Expand Down
3 changes: 3 additions & 0 deletions crates/concoct/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ use std::cell::RefCell;

pub mod hook;

#[macro_use]
pub(crate) mod macros;

mod rt;
pub(crate) use self::rt::{Runtime, Scope};

Expand Down
8 changes: 8 additions & 0 deletions crates/concoct/src/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//! Internal macros

macro_rules! trace {
($($tt:tt)*) => {
#[cfg(feature = "tracing")]
tracing::trace!($($tt)*)
}
}
15 changes: 14 additions & 1 deletion crates/concoct/src/tree/node.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::{Runtime, Scope, Tree, ViewBuilder};
use slotmap::DefaultKey;
use std::{any::Any, mem};
use std::{
any::{self, Any},
mem,
};

pub struct Node<V, B, F> {
pub(crate) view: V,
Expand Down Expand Up @@ -33,6 +36,8 @@ where
cx_ref.scope = Some(self.scope.clone().unwrap());
drop(cx_ref);

trace!("rebuilding from {}", any::type_name::<V>());

let view = unsafe { mem::transmute(&self.view) };
let body = (self.builder)(view);

Expand Down Expand Up @@ -60,6 +65,8 @@ where
cx_ref.scope = Some(self.scope.clone().unwrap());
drop(cx_ref);

trace!("building {}", any::type_name::<V>());

let view = unsafe { mem::transmute(&self.view) };
let body = (self.builder)(view);

Expand Down Expand Up @@ -100,6 +107,8 @@ where
cx_ref.scope = Some(self.scope.clone().unwrap());
drop(cx_ref);

trace!("rebuilding {}", any::type_name::<V>());

let view = unsafe { mem::transmute(&self.view) };
let body = (self.builder)(view);

Expand All @@ -120,11 +129,15 @@ where
let mut cx_ref = cx.inner.borrow_mut();
cx_ref.contexts = parent_contexts;
} else {
trace!("skipping {}", any::type_name::<V>());

self.body = last.body.take();
}
}

unsafe fn remove(&mut self) {
trace!("removing {}", any::type_name::<V>());

let cx = Runtime::current();
let mut cx_ref = cx.inner.borrow_mut();
let key = self.key.unwrap();
Expand Down

0 comments on commit 03a5230

Please sign in to comment.