Skip to content

Commit

Permalink
feat: Add tracing spans to most functions
Browse files Browse the repository at this point in the history
Signed-off-by: John Nunley <[email protected]>
  • Loading branch information
notgull committed Feb 28, 2024
1 parent a44e9f8 commit 4e5fb34
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ impl CustomCursor {
hotspot_x: u16,
hotspot_y: u16,
) -> Result<CustomCursorSource, BadImage> {
let span = tracing::debug_span!(
"winit::Cursor::from_rgba",
width,
height,
hotspot_x,
hotspot_y
);
let _guard = span.enter();

Ok(CustomCursorSource {
inner: PlatformCustomCursorSource::from_rgba(
rgba.into(),
Expand Down
4 changes: 3 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ impl OsError {
#[allow(unused_macros)]
macro_rules! os_error {
($error:expr) => {{
crate::error::OsError::new(line!(), file!(), $error)
let error = $error;
tracing::error!("encountered an OS error: {}", error);
crate::error::OsError::new(line!(), file!(), error)
}};
}

Expand Down
45 changes: 45 additions & 0 deletions src/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ impl<T> EventLoopBuilder<T> {
)]
#[inline]
pub fn build(&mut self) -> Result<EventLoop<T>, EventLoopError> {
let span = tracing::debug_span!("winit::EventLoopBuier::build");
let _guard = span.enter();

if EVENT_LOOP_CREATED.swap(true, Ordering::Relaxed) {
return Err(EventLoopError::RecreationAttempt);
}
Expand Down Expand Up @@ -248,6 +251,9 @@ impl<T> EventLoop<T> {
where
F: FnMut(Event<T>, &ActiveEventLoop),
{
let span = tracing::debug_span!("winit::EventLoop::run");
let _guard = span.enter();

self.event_loop.run(event_handler)
}

Expand All @@ -274,6 +280,12 @@ impl<T> EventLoop<T> {
///
/// [`DeviceEvent`]: crate::event::DeviceEvent
pub fn listen_device_events(&self, allowed: DeviceEvents) {
let span = tracing::debug_span!(
"winit::EventLoop::listen_device_events",
allowed = ?allowed
);
let _guard = span.enter();

self.event_loop
.window_target()
.p
Expand All @@ -295,6 +307,12 @@ impl<T> EventLoop<T> {
#[deprecated = "use `ActiveEventLoop::create_window` instead"]
#[inline]
pub fn create_window(&self, window_attributes: WindowAttributes) -> Result<Window, OsError> {
let span = tracing::debug_span!(
"winit::EventLoop::create_window",
window_attributes = ?window_attributes
);
let _guard = span.enter();

let window =
platform_impl::Window::new(&self.event_loop.window_target().p, window_attributes)?;
Ok(Window { window })
Expand Down Expand Up @@ -363,18 +381,30 @@ impl ActiveEventLoop {
/// see the web platform module for more information.
#[inline]
pub fn create_window(&self, window_attributes: WindowAttributes) -> Result<Window, OsError> {
let span = tracing::debug_span!(
"winit::ActiveEventLoop::create_window",
window_attributes = ?window_attributes
);
let _guard = span.enter();

let window = platform_impl::Window::new(&self.p, window_attributes)?;
Ok(Window { window })
}

/// Create custom cursor.
pub fn create_custom_cursor(&self, custom_cursor: CustomCursorSource) -> CustomCursor {
let span = tracing::debug_span!("winit::ActiveEventLoop::create_custom_cursor",);
let _guard = span.enter();

self.p.create_custom_cursor(custom_cursor)
}

/// Returns the list of all the monitors available on the system.
#[inline]
pub fn available_monitors(&self) -> impl Iterator<Item = MonitorHandle> {
let span = tracing::debug_span!("winit::ActiveEventLoop::available_monitors",);
let _guard = span.enter();

#[allow(clippy::useless_conversion)] // false positive on some platforms
self.p
.available_monitors()
Expand All @@ -391,6 +421,9 @@ impl ActiveEventLoop {
/// **Wayland / Web:** Always returns `None`.
#[inline]
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
let span = tracing::debug_span!("winit::ActiveEventLoop::primary_monitor",);
let _guard = span.enter();

self.p
.primary_monitor()
.map(|inner| MonitorHandle { inner })
Expand All @@ -408,6 +441,12 @@ impl ActiveEventLoop {
///
/// [`DeviceEvent`]: crate::event::DeviceEvent
pub fn listen_device_events(&self, allowed: DeviceEvents) {
let span = tracing::debug_span!(
"winit::ActiveEventLoop::listen_device_events",
allowed = ?allowed
);
let _guard = span.enter();

self.p.listen_device_events(allowed);
}

Expand All @@ -425,6 +464,9 @@ impl ActiveEventLoop {
///
/// See [`LoopExiting`](Event::LoopExiting).
pub fn exit(&self) {
let span = tracing::debug_span!("winit::ActiveEventLoop::exit",);
let _guard = span.enter();

self.p.exit()
}

Expand Down Expand Up @@ -530,6 +572,9 @@ impl<T: 'static> EventLoopProxy<T> {
///
/// [`UserEvent(event)`]: Event::UserEvent
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed<T>> {
let span = tracing::debug_span!("winit::EventLoopProxy::send_event",);
let _guard = span.enter();

self.event_loop_proxy.send_event(event)
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ impl Icon {
/// The length of `rgba` must be divisible by 4, and `width * height` must equal
/// `rgba.len() / 4`. Otherwise, this will return a `BadIcon` error.
pub fn from_rgba(rgba: Vec<u8>, width: u32, height: u32) -> Result<Self, BadIcon> {
let span = tracing::debug_span!("winit::Icon::from_rgba", width, height);
let _guard = span.enter();

Ok(Icon {
inner: PlatformIcon::from_rgba(rgba, width, height)?,
})
Expand Down
Loading

0 comments on commit 4e5fb34

Please sign in to comment.