I’m implementing telemetry for our app, one of the things I’m trying to capture are the distinct blocks of time as described by Apple engineers in the Optimizing App Launch video of WWDC 2019. I’m having a hard time capturing precisely the time for the First frame and the extended stages.
I’m trying to capture them as in the snippet below and I’m using signposts to represent the points of logging (with every log..Started
and log...Finished
. The assumption I’m making are:
- That the
application:didFinishLaunchingWithOptions:
method is being called before the first frame is rendered (as described in the video) - The first frame will be finished rendering after the current runloop ends.
void PerformWhenIdle(dispatch_block_t block) {
CFRunLoopObserverCreateWithHandler(kCFAllocatorDefault,
kCFRunLoopAfterWaiting,
NO,
0, ^(CFRunLoopObserverRef observer, CFRunLoopActivity activity) {
block();
});
}
// ----------------------------
// AppDelegate.m
- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[logger logFirstFrameRenderingStarted];
PerformWhenIdle(^{
[logger logFirstFrameRenderingFinished];
[logger logExtendedStageStarted];
});
}
// ----------------------------
// in TableVC.m
- (void)viewDidAppear {
[self.tableView reloadData];
PerformWhenIdle(^{
[logger logExtendedStageFinished];
});
}
Seems like the starting point for the first frame is quite close when I inspect the signposts in instruments, however the first frame seems quite off and therefore the extended stage seems very short in comparison, where the signpost indicate a duration of 225.23ms the App lifecycle instrument shows it took 1.78ms:
I’d like to know
- Are my assumptions incorrect? if yes does it mean the instrument is wrong?
- If they are incorrect, how can I best capture the start and finish points of the first frame being rendered?