|
@@ -244,6 +244,32 @@ impl<T: UserEvent> Context<T> {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#[cfg(feature = "tracing")]
|
|
|
|
+#[derive(Debug, Clone, Default)]
|
|
|
|
+pub struct ActiveTraceSpanStore(Rc<RefCell<Vec<ActiveTracingSpan>>>);
|
|
|
|
+
|
|
|
|
+#[cfg(feature = "tracing")]
|
|
|
|
+impl ActiveTraceSpanStore {
|
|
|
|
+ pub fn remove_window_draw(&self, window_id: WindowId) {
|
|
|
|
+ let mut store = self.0.borrow_mut();
|
|
|
|
+ if let Some(index) = store
|
|
|
|
+ .iter()
|
|
|
|
+ .position(|t| matches!(t, ActiveTracingSpan::WindowDraw { id, span: _ } if id == &window_id))
|
|
|
|
+ {
|
|
|
|
+ store.remove(index);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+#[cfg(feature = "tracing")]
|
|
|
|
+#[derive(Debug)]
|
|
|
|
+pub enum ActiveTracingSpan {
|
|
|
|
+ WindowDraw {
|
|
|
|
+ id: WindowId,
|
|
|
|
+ span: tracing::span::EnteredSpan,
|
|
|
|
+ },
|
|
|
|
+}
|
|
|
|
+
|
|
#[derive(Debug, Clone)]
|
|
#[derive(Debug, Clone)]
|
|
pub struct DispatcherMainThreadContext<T: UserEvent> {
|
|
pub struct DispatcherMainThreadContext<T: UserEvent> {
|
|
pub window_target: EventLoopWindowTarget<Message<T>>,
|
|
pub window_target: EventLoopWindowTarget<Message<T>>,
|
|
@@ -255,6 +281,8 @@ pub struct DispatcherMainThreadContext<T: UserEvent> {
|
|
pub windows: Rc<RefCell<HashMap<WebviewId, WindowWrapper>>>,
|
|
pub windows: Rc<RefCell<HashMap<WebviewId, WindowWrapper>>>,
|
|
#[cfg(all(desktop, feature = "system-tray"))]
|
|
#[cfg(all(desktop, feature = "system-tray"))]
|
|
system_tray_manager: SystemTrayManager,
|
|
system_tray_manager: SystemTrayManager,
|
|
|
|
+ #[cfg(feature = "tracing")]
|
|
|
|
+ pub active_tracing_spans: ActiveTraceSpanStore,
|
|
}
|
|
}
|
|
|
|
|
|
// SAFETY: we ensure this type is only used on the main thread.
|
|
// SAFETY: we ensure this type is only used on the main thread.
|
|
@@ -1135,7 +1163,10 @@ pub enum WindowMessage {
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
#[derive(Debug, Clone)]
|
|
pub enum WebviewMessage {
|
|
pub enum WebviewMessage {
|
|
|
|
+ #[cfg(not(feature = "tracing"))]
|
|
EvaluateScript(String),
|
|
EvaluateScript(String),
|
|
|
|
+ #[cfg(feature = "tracing")]
|
|
|
|
+ EvaluateScript(String, Sender<()>, tracing::Span),
|
|
#[allow(dead_code)]
|
|
#[allow(dead_code)]
|
|
WebviewEvent(WebviewEvent),
|
|
WebviewEvent(WebviewEvent),
|
|
Print,
|
|
Print,
|
|
@@ -1651,6 +1682,21 @@ impl<T: UserEvent> Dispatch<T> for WryDispatcher<T> {
|
|
)
|
|
)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ #[cfg(feature = "tracing")]
|
|
|
|
+ fn eval_script<S: Into<String>>(&self, script: S) -> Result<()> {
|
|
|
|
+ // use a channel so the EvaluateScript task uses the current span as parent
|
|
|
|
+ let (tx, rx) = channel();
|
|
|
|
+ getter!(
|
|
|
|
+ self,
|
|
|
|
+ rx,
|
|
|
|
+ Message::Webview(
|
|
|
|
+ self.window_id,
|
|
|
|
+ WebviewMessage::EvaluateScript(script.into(), tx, tracing::Span::current()),
|
|
|
|
+ )
|
|
|
|
+ )
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ #[cfg(not(feature = "tracing"))]
|
|
fn eval_script<S: Into<String>>(&self, script: S) -> Result<()> {
|
|
fn eval_script<S: Into<String>>(&self, script: S) -> Result<()> {
|
|
send_user_message(
|
|
send_user_message(
|
|
&self.context,
|
|
&self.context,
|
|
@@ -1962,6 +2008,8 @@ impl<T: UserEvent> Wry<T> {
|
|
windows,
|
|
windows,
|
|
#[cfg(all(desktop, feature = "system-tray"))]
|
|
#[cfg(all(desktop, feature = "system-tray"))]
|
|
system_tray_manager,
|
|
system_tray_manager,
|
|
|
|
+ #[cfg(feature = "tracing")]
|
|
|
|
+ active_tracing_spans: Default::default(),
|
|
},
|
|
},
|
|
};
|
|
};
|
|
|
|
|
|
@@ -2165,6 +2213,9 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
|
|
#[cfg(all(desktop, feature = "system-tray"))]
|
|
#[cfg(all(desktop, feature = "system-tray"))]
|
|
let system_tray_manager = self.context.main_thread.system_tray_manager.clone();
|
|
let system_tray_manager = self.context.main_thread.system_tray_manager.clone();
|
|
|
|
|
|
|
|
+ #[cfg(feature = "tracing")]
|
|
|
|
+ let active_tracing_spans = self.context.main_thread.active_tracing_spans.clone();
|
|
|
|
+
|
|
#[cfg(all(desktop, feature = "global-shortcut"))]
|
|
#[cfg(all(desktop, feature = "global-shortcut"))]
|
|
let global_shortcut_manager = self.context.main_thread.global_shortcut_manager.clone();
|
|
let global_shortcut_manager = self.context.main_thread.global_shortcut_manager.clone();
|
|
#[cfg(all(desktop, feature = "global-shortcut"))]
|
|
#[cfg(all(desktop, feature = "global-shortcut"))]
|
|
@@ -2202,6 +2253,8 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
|
|
clipboard_manager: clipboard_manager.clone(),
|
|
clipboard_manager: clipboard_manager.clone(),
|
|
#[cfg(all(desktop, feature = "system-tray"))]
|
|
#[cfg(all(desktop, feature = "system-tray"))]
|
|
system_tray_manager: system_tray_manager.clone(),
|
|
system_tray_manager: system_tray_manager.clone(),
|
|
|
|
+ #[cfg(feature = "tracing")]
|
|
|
|
+ active_tracing_spans: active_tracing_spans.clone(),
|
|
},
|
|
},
|
|
web_context,
|
|
web_context,
|
|
);
|
|
);
|
|
@@ -2226,6 +2279,8 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
|
|
clipboard_manager: clipboard_manager.clone(),
|
|
clipboard_manager: clipboard_manager.clone(),
|
|
#[cfg(all(desktop, feature = "system-tray"))]
|
|
#[cfg(all(desktop, feature = "system-tray"))]
|
|
system_tray_manager: system_tray_manager.clone(),
|
|
system_tray_manager: system_tray_manager.clone(),
|
|
|
|
+ #[cfg(feature = "tracing")]
|
|
|
|
+ active_tracing_spans: active_tracing_spans.clone(),
|
|
},
|
|
},
|
|
web_context,
|
|
web_context,
|
|
);
|
|
);
|
|
@@ -2240,6 +2295,9 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
|
|
let web_context = self.context.main_thread.web_context;
|
|
let web_context = self.context.main_thread.web_context;
|
|
let mut plugins = self.plugins;
|
|
let mut plugins = self.plugins;
|
|
|
|
|
|
|
|
+ #[cfg(feature = "tracing")]
|
|
|
|
+ let active_tracing_spans = self.context.main_thread.active_tracing_spans.clone();
|
|
|
|
+
|
|
#[cfg(all(desktop, feature = "system-tray"))]
|
|
#[cfg(all(desktop, feature = "system-tray"))]
|
|
let system_tray_manager = self.context.main_thread.system_tray_manager;
|
|
let system_tray_manager = self.context.main_thread.system_tray_manager;
|
|
|
|
|
|
@@ -2272,6 +2330,8 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
|
|
clipboard_manager: clipboard_manager.clone(),
|
|
clipboard_manager: clipboard_manager.clone(),
|
|
#[cfg(all(desktop, feature = "system-tray"))]
|
|
#[cfg(all(desktop, feature = "system-tray"))]
|
|
system_tray_manager: system_tray_manager.clone(),
|
|
system_tray_manager: system_tray_manager.clone(),
|
|
|
|
+ #[cfg(feature = "tracing")]
|
|
|
|
+ active_tracing_spans: active_tracing_spans.clone(),
|
|
},
|
|
},
|
|
&web_context,
|
|
&web_context,
|
|
);
|
|
);
|
|
@@ -2295,6 +2355,8 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
|
|
clipboard_manager: clipboard_manager.clone(),
|
|
clipboard_manager: clipboard_manager.clone(),
|
|
#[cfg(all(desktop, feature = "system-tray"))]
|
|
#[cfg(all(desktop, feature = "system-tray"))]
|
|
system_tray_manager: system_tray_manager.clone(),
|
|
system_tray_manager: system_tray_manager.clone(),
|
|
|
|
+ #[cfg(feature = "tracing")]
|
|
|
|
+ active_tracing_spans: active_tracing_spans.clone(),
|
|
},
|
|
},
|
|
&web_context,
|
|
&web_context,
|
|
);
|
|
);
|
|
@@ -2314,6 +2376,8 @@ pub struct EventLoopIterationContext<'a, T: UserEvent> {
|
|
pub clipboard_manager: Arc<Mutex<Clipboard>>,
|
|
pub clipboard_manager: Arc<Mutex<Clipboard>>,
|
|
#[cfg(all(desktop, feature = "system-tray"))]
|
|
#[cfg(all(desktop, feature = "system-tray"))]
|
|
pub system_tray_manager: SystemTrayManager,
|
|
pub system_tray_manager: SystemTrayManager,
|
|
|
|
+ #[cfg(feature = "tracing")]
|
|
|
|
+ pub active_tracing_spans: ActiveTraceSpanStore,
|
|
}
|
|
}
|
|
|
|
|
|
struct UserMessageContext {
|
|
struct UserMessageContext {
|
|
@@ -2590,6 +2654,19 @@ fn handle_user_message<T: UserEvent>(
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Message::Webview(id, webview_message) => match webview_message {
|
|
Message::Webview(id, webview_message) => match webview_message {
|
|
|
|
+ #[cfg(feature = "tracing")]
|
|
|
|
+ WebviewMessage::EvaluateScript(script, tx, span) => {
|
|
|
|
+ let _span = span.entered();
|
|
|
|
+ if let Some(WindowHandle::Webview { inner: webview, .. }) =
|
|
|
|
+ windows.borrow().get(&id).and_then(|w| w.inner.as_ref())
|
|
|
|
+ {
|
|
|
|
+ if let Err(e) = webview.evaluate_script(&script) {
|
|
|
|
+ debug_eprintln!("{}", e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ tx.send(()).unwrap();
|
|
|
|
+ }
|
|
|
|
+ #[cfg(not(feature = "tracing"))]
|
|
WebviewMessage::EvaluateScript(script) => {
|
|
WebviewMessage::EvaluateScript(script) => {
|
|
if let Some(WindowHandle::Webview { inner: webview, .. }) =
|
|
if let Some(WindowHandle::Webview { inner: webview, .. }) =
|
|
windows.borrow().get(&id).and_then(|w| w.inner.as_ref())
|
|
windows.borrow().get(&id).and_then(|w| w.inner.as_ref())
|
|
@@ -2758,6 +2835,8 @@ fn handle_event_loop<T: UserEvent>(
|
|
clipboard_manager,
|
|
clipboard_manager,
|
|
#[cfg(all(desktop, feature = "system-tray"))]
|
|
#[cfg(all(desktop, feature = "system-tray"))]
|
|
system_tray_manager,
|
|
system_tray_manager,
|
|
|
|
+ #[cfg(feature = "tracing")]
|
|
|
|
+ active_tracing_spans,
|
|
} = context;
|
|
} = context;
|
|
if *control_flow != ControlFlow::Exit {
|
|
if *control_flow != ControlFlow::Exit {
|
|
*control_flow = ControlFlow::Wait;
|
|
*control_flow = ControlFlow::Wait;
|
|
@@ -2780,6 +2859,11 @@ fn handle_event_loop<T: UserEvent>(
|
|
callback(RunEvent::Exit);
|
|
callback(RunEvent::Exit);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ #[cfg(feature = "tracing")]
|
|
|
|
+ Event::RedrawRequested(id) => {
|
|
|
|
+ active_tracing_spans.remove_window_draw(id);
|
|
|
|
+ }
|
|
|
|
+
|
|
#[cfg(all(desktop, feature = "global-shortcut"))]
|
|
#[cfg(all(desktop, feature = "global-shortcut"))]
|
|
Event::GlobalShortcutEvent(accelerator_id) => {
|
|
Event::GlobalShortcutEvent(accelerator_id) => {
|
|
for (id, handler) in &*global_shortcut_manager_handle.listeners.lock().unwrap() {
|
|
for (id, handler) in &*global_shortcut_manager_handle.listeners.lock().unwrap() {
|
|
@@ -3123,6 +3207,14 @@ fn create_webview<T: UserEvent>(
|
|
#[cfg(windows)]
|
|
#[cfg(windows)]
|
|
let proxy = context.proxy.clone();
|
|
let proxy = context.proxy.clone();
|
|
|
|
|
|
|
|
+ #[cfg(feature = "tracing")]
|
|
|
|
+ let _webview_create_span = tracing::debug_span!("wry::webview::create").entered();
|
|
|
|
+ #[cfg(feature = "tracing")]
|
|
|
|
+ let window_draw_span = tracing::debug_span!("wry::window::draw").entered();
|
|
|
|
+ #[cfg(feature = "tracing")]
|
|
|
|
+ let window_create_span =
|
|
|
|
+ tracing::debug_span!(parent: &window_draw_span, "wry::window::create").entered();
|
|
|
|
+
|
|
let window_event_listeners = WindowEventListeners::default();
|
|
let window_event_listeners = WindowEventListeners::default();
|
|
|
|
|
|
#[cfg(windows)]
|
|
#[cfg(windows)]
|
|
@@ -3157,6 +3249,21 @@ fn create_webview<T: UserEvent>(
|
|
let focused = window_builder.inner.window.focused;
|
|
let focused = window_builder.inner.window.focused;
|
|
let window = window_builder.inner.build(event_loop).unwrap();
|
|
let window = window_builder.inner.build(event_loop).unwrap();
|
|
|
|
|
|
|
|
+ #[cfg(feature = "tracing")]
|
|
|
|
+ {
|
|
|
|
+ drop(window_create_span);
|
|
|
|
+
|
|
|
|
+ context
|
|
|
|
+ .main_thread
|
|
|
|
+ .active_tracing_spans
|
|
|
|
+ .0
|
|
|
|
+ .borrow_mut()
|
|
|
|
+ .push(ActiveTracingSpan::WindowDraw {
|
|
|
|
+ id: window.id(),
|
|
|
|
+ span: window_draw_span,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
webview_id_map.insert(window.id(), window_id);
|
|
webview_id_map.insert(window.id(), window_id);
|
|
|
|
|
|
if window_builder.center {
|
|
if window_builder.center {
|