Open
Conversation
3c40c67 to
bb405cc
Compare
Tracing subscribers must be set up before `EventLoop::new()`.
Add two run loop observers that:
- Create a TRACE-level span when the run loop enters a new state.
- Drops the span when the run loop exits that state.
These spans attach information to events, such that e.g. resizing a view
produces messages like:
```
TRACE inside runloop{mode=NSEventTrackingRunLoopMode}:timers:
winit_appkit::util: Triggered `drawRect:` target="winit_appkit::view"
TRACE inside runloop{mode=NSEventTrackingRunLoopMode}:timers:
winit_appkit::util: Completed `drawRect:` target="winit_appkit::view"
```
Spans are more powerful, and can even optionally be emitted as events by using `.with_span_events(tracing_subscriber::fmt::format::FmtSpan::*)`.
This allows the examples to work a bit better in WASM and on iOS.
bb405cc to
29eb0dd
Compare
Most events in AppKit go through `sendEvent:`, and they contain a lot of information, so it's nice to surface this when debugging. We could override `sendEvent:` in UIKit and track this in there too, but that's much less important, since there the relevant events are fairly narrowly scoped, see the link below, other events go through CFRunLoop. https://developer.apple.com/documentation/uikit/uievent/eventtype
b3cccb8 to
df2ccad
Compare
kchibisov
requested changes
Feb 24, 2026
| // FIXME(madsmtm): Use `std::ptr::fn_addr_eq` (Rust 1.85) once available in MSRV. | ||
| #[allow(unknown_lints, unpredictable_function_pointer_comparisons)] | ||
| if overridden == method.implementation() { | ||
| if ptr::fn_addr_eq(overridden, method.implementation()) { |
Member
There was a problem hiding this comment.
I think this should be sent as a separate patch? Wouldn't mind that much though.
| pub fn flush_requests(&self) -> Result<(), XError> { | ||
| unsafe { (self.xlib.XFlush)(self.display) }; | ||
| // println!("XFlush"); | ||
| // tracing::trace!("XFlush"); |
Member
There was a problem hiding this comment.
Suggested change
| // tracing::trace!("XFlush"); |
| pub fn sync_with_server(&self) -> Result<(), XError> { | ||
| unsafe { (self.xlib.XSync)(self.display, ffi::False) }; | ||
| // println!("XSync"); | ||
| // tracing::trace!("XSync"); |
Member
There was a problem hiding this comment.
Suggested change
| // tracing::trace!("XSync"); |
| ToUnicodeResult::Dead(dead_char) => { | ||
| // println!("{:?} - {:?} produced dead {:?}", key_code, mod_state, | ||
| // dead_char); | ||
| // trace!("{:?} - {:?} produced dead {:?}", key_code, mod_state, dead_char); |
Member
There was a problem hiding this comment.
Suggested change
| // trace!("{:?} - {:?} produced dead {:?}", key_code, mod_state, dead_char); |
| pub fn tracing_observers( | ||
| mtm: MainThreadMarker, | ||
| ) -> Option<(MainRunLoopObserver, MainRunLoopObserver)> { | ||
| // HINT: You can use something like the following to emit relevant events: |
Member
There was a problem hiding this comment.
This thing looks out of place?
| }; | ||
|
|
||
| extern "C-unwind" fn send_event(app: &NSApplication, sel: Sel, event: &NSEvent) { | ||
| // Pass `RUST_LOG='trace,winit_appkit::app=warn'` if you want TRACE logs but not this. |
Member
There was a problem hiding this comment.
Not sure who'll read this, maybe it should be somewhere more visible or do you left it for yourself?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Use
tracing::spanin clever ways to improve the logging infrastructure in the AppKit and UIKit backends. See the commits for details.Running
RUST_LOG='trace,winit_appkit::app=off' cargo run --example windowand resizing now produces traces like:With this, one can glance that
RedrawRequestedis called insidedrawRect:, and that it is in turn run insideNSEventTrackingRunLoopModeas a timer - which should in turn help debug why we're issuingRedrawRequestedtwice.Tested AppKit backend on macOS 15.7.3 and UIKit briefly with Mac Catalyst.
I didn't include a changelog entry since these are meant to be internal.