Skip to content

Commit 29eb0dd

Browse files
committed
Add tracing spans to UIKit backend
1 parent 9ae846c commit 29eb0dd

File tree

4 files changed

+50
-5
lines changed

4 files changed

+50
-5
lines changed

winit-uikit/src/event_loop.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use objc2_ui_kit::{
1212
UIApplicationWillResignActiveNotification, UIApplicationWillTerminateNotification, UIScreen,
1313
};
1414
use rwh_06::HasDisplayHandle;
15+
use tracing::debug_span;
1516
use winit_common::core_foundation::{MainRunLoop, MainRunLoopObserver, tracing_observers};
1617
use winit_core::application::ApplicationHandler;
1718
use winit_core::cursor::{CustomCursor, CustomCursorSource};
@@ -160,26 +161,35 @@ impl EventLoop {
160161
// `application:didFinishLaunchingWithOptions:`
161162
unsafe { UIApplicationDidFinishLaunchingNotification },
162163
move |_| {
164+
let _entered = debug_span!("UIApplicationDidFinishLaunchingNotification").entered();
163165
app_state::did_finish_launching(mtm);
164166
},
165167
);
166168
let _did_become_active_observer = create_observer(
167169
&center,
168170
// `applicationDidBecomeActive:`
169171
unsafe { UIApplicationDidBecomeActiveNotification },
170-
move |_| app_state::handle_resumed(mtm),
172+
move |_| {
173+
let _entered = debug_span!("UIApplicationDidBecomeActiveNotification").entered();
174+
app_state::handle_resumed(mtm)
175+
},
171176
);
172177
let _will_resign_active_observer = create_observer(
173178
&center,
174179
// `applicationWillResignActive:`
175180
unsafe { UIApplicationWillResignActiveNotification },
176-
move |_| app_state::handle_suspended(mtm),
181+
move |_| {
182+
let _entered = debug_span!("UIApplicationWillResignActiveNotification").entered();
183+
app_state::handle_suspended(mtm)
184+
},
177185
);
178186
let _will_enter_foreground_observer = create_observer(
179187
&center,
180188
// `applicationWillEnterForeground:`
181189
unsafe { UIApplicationWillEnterForegroundNotification },
182190
move |notification| {
191+
let _entered =
192+
debug_span!("UIApplicationWillEnterForegroundNotification").entered();
183193
let app = notification.object().expect(
184194
"UIApplicationWillEnterForegroundNotification to have application object",
185195
);
@@ -194,6 +204,7 @@ impl EventLoop {
194204
// `applicationDidEnterBackground:`
195205
unsafe { UIApplicationDidEnterBackgroundNotification },
196206
move |notification| {
207+
let _entered = debug_span!("UIApplicationDidEnterBackgroundNotification").entered();
197208
let app = notification.object().expect(
198209
"UIApplicationDidEnterBackgroundNotification to have application object",
199210
);
@@ -208,6 +219,7 @@ impl EventLoop {
208219
// `applicationWillTerminate:`
209220
unsafe { UIApplicationWillTerminateNotification },
210221
move |notification| {
222+
let _entered = debug_span!("UIApplicationWillTerminateNotification").entered();
211223
let app = notification
212224
.object()
213225
.expect("UIApplicationWillTerminateNotification to have application object");
@@ -221,7 +233,11 @@ impl EventLoop {
221233
&center,
222234
// `applicationDidReceiveMemoryWarning:`
223235
unsafe { UIApplicationDidReceiveMemoryWarningNotification },
224-
move |_| app_state::handle_memory_warning(mtm),
236+
move |_| {
237+
let _entered =
238+
debug_span!("UIApplicationDidReceiveMemoryWarningNotification").entered();
239+
app_state::handle_memory_warning(mtm)
240+
},
225241
);
226242

227243
let main_loop = MainRunLoop::get(mtm);

winit-uikit/src/view.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use objc2_ui_kit::{
1313
UIResponder, UIRotationGestureRecognizer, UITapGestureRecognizer, UITextInputTraits, UITouch,
1414
UITouchPhase, UITouchType, UITraitEnvironment, UIView,
1515
};
16-
use tracing::debug;
16+
use tracing::{debug, debug_span, trace_span};
1717
use winit_core::event::{
1818
ButtonSource, ElementState, FingerId, Force, KeyEvent, PointerKind, PointerSource,
1919
TabletToolAngle, TabletToolButton, TabletToolData, TabletToolKind, TouchPhase, WindowEvent,
@@ -48,6 +48,7 @@ define_class!(
4848
impl WinitView {
4949
#[unsafe(method(drawRect:))]
5050
fn draw_rect(&self, rect: CGRect) {
51+
let _entered = debug_span!("drawRect:").entered();
5152
let mtm = MainThreadMarker::new().unwrap();
5253
let window = self.window().unwrap();
5354
app_state::handle_nonuser_event(mtm, EventWrapper::Window {
@@ -59,6 +60,7 @@ define_class!(
5960

6061
#[unsafe(method(layoutSubviews))]
6162
fn layout_subviews(&self) {
63+
let _entered = debug_span!("layoutSubviews").entered();
6264
let mtm = MainThreadMarker::new().unwrap();
6365
let _: () = unsafe { msg_send![super(self), layoutSubviews] };
6466

@@ -79,6 +81,7 @@ define_class!(
7981

8082
#[unsafe(method(setContentScaleFactor:))]
8183
fn set_content_scale_factor(&self, untrusted_scale_factor: CGFloat) {
84+
let _entered = debug_span!("setContentScaleFactor:").entered();
8285
let mtm = MainThreadMarker::new().unwrap();
8386
let _: () =
8487
unsafe { msg_send![super(self), setContentScaleFactor: untrusted_scale_factor] };
@@ -124,33 +127,39 @@ define_class!(
124127

125128
#[unsafe(method(safeAreaInsetsDidChange))]
126129
fn safe_area_changed(&self) {
130+
let _entered = debug_span!("safeAreaInsetsDidChange").entered();
127131
debug!("safeAreaInsetsDidChange was called, requesting redraw");
128132
// When the safe area changes we want to make sure to emit a redraw event
129133
self.setNeedsDisplay();
130134
}
131135

132136
#[unsafe(method(touchesBegan:withEvent:))]
133137
fn touches_began(&self, touches: &NSSet<UITouch>, _event: Option<&UIEvent>) {
138+
let _entered = debug_span!("touchesBegan:withEvent:").entered();
134139
self.handle_touches(touches)
135140
}
136141

137142
#[unsafe(method(touchesMoved:withEvent:))]
138143
fn touches_moved(&self, touches: &NSSet<UITouch>, _event: Option<&UIEvent>) {
144+
let _entered = debug_span!("touchesMoved:withEvent:").entered();
139145
self.handle_touches(touches)
140146
}
141147

142148
#[unsafe(method(touchesEnded:withEvent:))]
143149
fn touches_ended(&self, touches: &NSSet<UITouch>, _event: Option<&UIEvent>) {
150+
let _entered = debug_span!("touchesEnded:withEvent:").entered();
144151
self.handle_touches(touches)
145152
}
146153

147154
#[unsafe(method(touchesCancelled:withEvent:))]
148155
fn touches_cancelled(&self, touches: &NSSet<UITouch>, _event: Option<&UIEvent>) {
156+
let _entered = debug_span!("touchesCancelled:withEvent:").entered();
149157
self.handle_touches(touches)
150158
}
151159

152160
#[unsafe(method(pinchGesture:))]
153161
fn pinch_gesture(&self, recognizer: &UIPinchGestureRecognizer) {
162+
let _entered = debug_span!("pinchGesture:").entered();
154163
let window = self.window().unwrap();
155164

156165
let (phase, delta) = match recognizer.state() {
@@ -185,6 +194,7 @@ define_class!(
185194

186195
#[unsafe(method(doubleTapGesture:))]
187196
fn double_tap_gesture(&self, recognizer: &UITapGestureRecognizer) {
197+
let _entered = debug_span!("doubleTapGesture:").entered();
188198
let window = self.window().unwrap();
189199

190200
if recognizer.state() == UIGestureRecognizerState::Ended {
@@ -200,6 +210,7 @@ define_class!(
200210

201211
#[unsafe(method(rotationGesture:))]
202212
fn rotation_gesture(&self, recognizer: &UIRotationGestureRecognizer) {
213+
let _entered = debug_span!("rotationGesture:").entered();
203214
let window = self.window().unwrap();
204215

205216
let (phase, delta) = match recognizer.state() {
@@ -244,6 +255,7 @@ define_class!(
244255

245256
#[unsafe(method(panGesture:))]
246257
fn pan_gesture(&self, recognizer: &UIPanGestureRecognizer) {
258+
let _entered = debug_span!("panGesture:").entered();
247259
let window = self.window().unwrap();
248260

249261
let translation = recognizer.translationInView(Some(self));
@@ -296,6 +308,7 @@ define_class!(
296308

297309
#[unsafe(method(canBecomeFirstResponder))]
298310
fn can_become_first_responder(&self) -> bool {
311+
let _entered = trace_span!("canBecomeFirstResponder").entered();
299312
true
300313
}
301314
}
@@ -309,6 +322,10 @@ define_class!(
309322
_gesture_recognizer: &UIGestureRecognizer,
310323
_other_gesture_recognizer: &UIGestureRecognizer,
311324
) -> bool {
325+
let _entered = trace_span!(
326+
"gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:"
327+
)
328+
.entered();
312329
true
313330
}
314331
}
@@ -318,16 +335,19 @@ define_class!(
318335
unsafe impl UIKeyInput for WinitView {
319336
#[unsafe(method(hasText))]
320337
fn has_text(&self) -> bool {
338+
let _entered = debug_span!("hasText").entered();
321339
true
322340
}
323341

324342
#[unsafe(method(insertText:))]
325343
fn insert_text(&self, text: &NSString) {
344+
let _entered = debug_span!("insertText:").entered();
326345
self.handle_insert_text(text)
327346
}
328347

329348
#[unsafe(method(deleteBackward))]
330349
fn delete_backward(&self) {
350+
let _entered = debug_span!("deleteBackward").entered();
331351
self.handle_delete_backward()
332352
}
333353
}

winit-uikit/src/view_controller.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use objc2_ui_kit::{
77
UIDevice, UIInterfaceOrientationMask, UIRectEdge, UIResponder, UIStatusBarStyle,
88
UIUserInterfaceIdiom, UIView, UIViewController,
99
};
10+
use tracing::trace_span;
1011

1112
use crate::{ScreenEdge, StatusBarStyle, ValidOrientations, WindowAttributesIos};
1213

@@ -28,31 +29,37 @@ define_class!(
2829
impl WinitViewController {
2930
#[unsafe(method(shouldAutorotate))]
3031
fn should_autorotate(&self) -> bool {
32+
let _entered = trace_span!("shouldAutorotate").entered();
3133
true
3234
}
3335

3436
#[unsafe(method(prefersStatusBarHidden))]
3537
fn prefers_status_bar_hidden(&self) -> bool {
38+
let _entered = trace_span!("prefersStatusBarHidden").entered();
3639
self.ivars().prefers_status_bar_hidden.get()
3740
}
3841

3942
#[unsafe(method(preferredStatusBarStyle))]
4043
fn preferred_status_bar_style(&self) -> UIStatusBarStyle {
44+
let _entered = trace_span!("preferredStatusBarStyle").entered();
4145
self.ivars().preferred_status_bar_style.get()
4246
}
4347

4448
#[unsafe(method(prefersHomeIndicatorAutoHidden))]
4549
fn prefers_home_indicator_auto_hidden(&self) -> bool {
50+
let _entered = trace_span!("prefersHomeIndicatorAutoHidden").entered();
4651
self.ivars().prefers_home_indicator_auto_hidden.get()
4752
}
4853

4954
#[unsafe(method(supportedInterfaceOrientations))]
5055
fn supported_orientations(&self) -> UIInterfaceOrientationMask {
56+
let _entered = trace_span!("supportedInterfaceOrientations").entered();
5157
self.ivars().supported_orientations.get()
5258
}
5359

5460
#[unsafe(method(preferredScreenEdgesDeferringSystemGestures))]
5561
fn preferred_screen_edges_deferring_system_gestures(&self) -> UIRectEdge {
62+
let _entered = trace_span!("preferredScreenEdgesDeferringSystemGestures").entered();
5663
self.ivars().preferred_screen_edges_deferring_system_gestures.get()
5764
}
5865
}

winit-uikit/src/window.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use objc2_ui_kit::{
1616
UIApplication, UICoordinateSpace, UIEdgeInsets, UIResponder, UIScreen,
1717
UIScreenOverscanCompensation, UIViewController, UIWindow,
1818
};
19-
use tracing::{debug, warn};
19+
use tracing::{debug, debug_span, warn};
2020
use winit_core::cursor::Cursor;
2121
use winit_core::error::{NotSupportedError, RequestError};
2222
use winit_core::event::WindowEvent;
@@ -46,6 +46,7 @@ define_class!(
4646
impl WinitUIWindow {
4747
#[unsafe(method(becomeKeyWindow))]
4848
fn become_key_window(&self) {
49+
let _entered = debug_span!("becomeKeyWindow").entered();
4950
let mtm = MainThreadMarker::new().unwrap();
5051
app_state::handle_nonuser_event(mtm, EventWrapper::Window {
5152
window_id: self.id(),
@@ -56,6 +57,7 @@ define_class!(
5657

5758
#[unsafe(method(resignKeyWindow))]
5859
fn resign_key_window(&self) {
60+
let _entered = debug_span!("resignKeyWindow").entered();
5961
let mtm = MainThreadMarker::new().unwrap();
6062
app_state::handle_nonuser_event(mtm, EventWrapper::Window {
6163
window_id: self.id(),

0 commit comments

Comments
 (0)