Skip to content

Commit b68a1f5

Browse files
authored
Merge pull request DioxusLabs#1436 from ealmloff/tracing
2 parents 18dca07 + bdaa284 commit b68a1f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+142
-97
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ generational-box = { path = "packages/generational-box" }
8282
dioxus-hot-reload = { path = "packages/hot-reload", version = "0.4.0" }
8383
dioxus-fullstack = { path = "packages/fullstack", version = "0.4.1" }
8484
dioxus_server_macro = { path = "packages/server-macro", version = "0.4.1" }
85-
log = "0.4.19"
85+
tracing = "0.1.37"
86+
tracing-futures = "0.2.5"
8687
tokio = "1.28"
8788
slab = "0.4.2"
8889
futures-channel = "0.3.21"

packages/core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ slab = { workspace = true }
2828
futures-channel = { workspace = true }
2929

3030
smallbox = "0.8.1"
31-
log = { workspace = true }
31+
tracing = { workspace = true }
3232

3333
# Serialize the Edits for use in Webview/Liveview instances
3434
serde = { version = "1", features = ["derive"], optional = true }

packages/core/src/any_props.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ unsafe impl<'a, P> AnyProps<'a> for VProps<'a, P> {
6868
Ok(None) => RenderReturn::default(),
6969
Err(err) => {
7070
let component_name = cx.name();
71-
log::error!("Error while rendering component `{component_name}`: {err:?}");
71+
tracing::error!("Error while rendering component `{component_name}`: {err:?}");
7272
RenderReturn::default()
7373
}
7474
}

packages/core/src/diff.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,20 @@ impl<'b> VirtualDom {
196196
right.scope.set(Some(scope_id));
197197

198198
// copy out the box for both
199-
let old = self.scopes[scope_id.0].props.as_ref();
199+
let old_scope = &self.scopes[scope_id.0];
200+
let old = old_scope.props.as_ref();
200201
let new: Box<dyn AnyProps> = right.props.take().unwrap();
201202
let new: Box<dyn AnyProps> = unsafe { std::mem::transmute(new) };
202203

203204
// If the props are static, then we try to memoize by setting the new with the old
204205
// The target scopestate still has the reference to the old props, so there's no need to update anything
205206
// This also implicitly drops the new props since they're not used
206207
if left.static_props && unsafe { old.as_ref().unwrap().memoize(new.as_ref()) } {
208+
tracing::trace!(
209+
"Memoized props for component {:#?} ({})",
210+
scope_id,
211+
old_scope.context().name
212+
);
207213
return;
208214
}
209215

packages/core/src/events.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<T: std::fmt::Debug> std::fmt::Debug for Event<T> {
118118
///
119119
/// ```rust, ignore
120120
/// rsx!{
121-
/// MyComponent { onclick: move |evt| log::info!("clicked") }
121+
/// MyComponent { onclick: move |evt| tracing::debug!("clicked") }
122122
/// }
123123
///
124124
/// #[derive(Props)]

packages/core/src/scope_arena.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ impl VirtualDom {
6464
let props: &dyn AnyProps = scope.props.as_ref().unwrap().as_ref();
6565
let props: &dyn AnyProps = std::mem::transmute(props);
6666

67+
let _span = tracing::trace_span!("render", scope = %scope.context().name);
6768
props.render(scope).extend_lifetime()
6869
};
6970

packages/core/src/scope_context.rs

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,27 +107,48 @@ impl ScopeContext {
107107
///
108108
/// Clones the state if it exists.
109109
pub fn consume_context<T: 'static + Clone>(&self) -> Option<T> {
110+
tracing::trace!(
111+
"looking for context {} ({:?}) in {}",
112+
std::any::type_name::<T>(),
113+
std::any::TypeId::of::<T>(),
114+
self.name
115+
);
110116
if let Some(this_ctx) = self.has_context() {
111117
return Some(this_ctx);
112118
}
113119

114120
let mut search_parent = self.parent_id;
115-
with_runtime(|runtime| {
121+
match with_runtime(|runtime: &crate::runtime::Runtime| {
116122
while let Some(parent_id) = search_parent {
117123
let parent = runtime.get_context(parent_id).unwrap();
118-
if let Some(shared) = parent
119-
.shared_contexts
120-
.borrow()
121-
.iter()
122-
.find_map(|any| any.downcast_ref::<T>())
123-
{
124+
tracing::trace!(
125+
"looking for context {} ({:?}) in {}",
126+
std::any::type_name::<T>(),
127+
std::any::TypeId::of::<T>(),
128+
parent.name
129+
);
130+
if let Some(shared) = parent.shared_contexts.borrow().iter().find_map(|any| {
131+
tracing::trace!("found context {:?}", any.type_id());
132+
any.downcast_ref::<T>()
133+
}) {
124134
return Some(shared.clone());
125135
}
126136
search_parent = parent.parent_id;
127137
}
128138
None
129139
})
130140
.flatten()
141+
{
142+
Some(ctx) => Some(ctx),
143+
None => {
144+
tracing::trace!(
145+
"context {} ({:?}) not found",
146+
std::any::type_name::<T>(),
147+
std::any::TypeId::of::<T>()
148+
);
149+
None
150+
}
151+
}
131152
}
132153

133154
/// Expose state to children further down the [`crate::VirtualDom`] Tree. Requires `Clone` on the context to allow getting values down the tree.
@@ -152,6 +173,12 @@ impl ScopeContext {
152173
/// }
153174
/// ```
154175
pub fn provide_context<T: 'static + Clone>(&self, value: T) -> T {
176+
tracing::trace!(
177+
"providing context {} ({:?}) in {}",
178+
std::any::type_name::<T>(),
179+
std::any::TypeId::of::<T>(),
180+
self.name
181+
);
155182
let mut contexts = self.shared_contexts.borrow_mut();
156183

157184
// If the context exists, swap it out for the new value

packages/core/src/virtual_dom.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ impl VirtualDom {
306306
pub fn mark_dirty(&mut self, id: ScopeId) {
307307
if let Some(scope) = self.get_scope(id) {
308308
let height = scope.height();
309+
tracing::trace!("Marking scope {:?} ({}) as dirty", id, scope.context().name);
309310
self.dirty_scopes.insert(DirtyScope { height, id });
310311
}
311312
}
@@ -558,7 +559,7 @@ impl VirtualDom {
558559
}
559560
// If an error occurs, we should try to render the default error component and context where the error occured
560561
RenderReturn::Aborted(placeholder) => {
561-
log::info!("Ran into suspended or aborted scope during rebuild");
562+
tracing::debug!("Ran into suspended or aborted scope during rebuild");
562563
let id = self.next_null();
563564
placeholder.id.set(Some(id));
564565
self.mutations.push(Mutation::CreatePlaceholder { id });

packages/desktop/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dioxus-hot-reload = { workspace = true, optional = true }
1818
serde = "1.0.136"
1919
serde_json = "1.0.79"
2020
thiserror = { workspace = true }
21-
log = { workspace = true }
21+
tracing = { workspace = true }
2222
wry = { version = "0.28.0" }
2323
futures-channel = { workspace = true }
2424
tokio = { workspace = true, features = [

packages/desktop/src/desktop_context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl DesktopService {
194194
/// launch print modal
195195
pub fn print(&self) {
196196
if let Err(e) = self.webview.print() {
197-
log::warn!("Open print modal failed: {e}");
197+
tracing::warn!("Open print modal failed: {e}");
198198
}
199199
}
200200

@@ -209,7 +209,7 @@ impl DesktopService {
209209
self.webview.open_devtools();
210210

211211
#[cfg(not(debug_assertions))]
212-
log::warn!("Devtools are disabled in release builds");
212+
tracing::warn!("Devtools are disabled in release builds");
213213
}
214214

215215
/// Create a wry event handler that listens for wry events.

0 commit comments

Comments
 (0)