NSProccessInfo systemUptime gives massively different values in iOS simulator versus device

I am detecting "all touches in an application" by overriding the sendEvent method in my UIApplication subclass. As part of this I've included a click debouncer that discards old events if the main thread gets clogged up somehow. Apple's own documentation says to compare it to NSProccessInfo.systemUptime. https://developer.apple.com/documentation/uikit/uievent/1613790-timestamp?language=objc

For an actual device this works just fine. But for the iOS simulator (iOS 15.4 simulator from Xcode 13.3) I'm getting some weird results where NSProcessInfo.systemUptime is 10's of thousands of seconds off. Anyone know what's causing this?

-(void)sendEvent:(UIEvent *)event { 
    NSTimeInterval eventTime = event.timestamp; // In simulator this ~= 6700
    NSTimeInterval nowTime = NSProcessInfo.processInfo.systemUptime; // In simulator this ~= 280,000

    // don't count old events, if possible (due to massive time discrepancies this if block is always hit in simulator
    if(nowTime - eventTime > 50) {
        [super sendEvent:event];
        return;
    }
    
    // Do the actual thing I want to do

    ```
}

By experiment with the Swift REPL, I’m seeing that the simulator’s ProcessInfo.processInfo.systemUptime is just a passthrough to the same property on macOS. It seems to indicate the time the Mac has been awake, as documented.

But testing your code here, I’m seeing that systemUptime and every event timestamp are in sync, differing only by milliseconds as expected instead of thousands of seconds.

Does this problem repro for you in a minimalist test app, in addition to your main app? And what is this “main thread clogged up somehow” condition that motivated this in the first place? Needing to debounce system click events like this is very unusual.

  • I did try this on a simple app as well as several different simulators and yes it's still off. I did notice something odd though... When I add a log file:
    NSLog(@"event time = %lf and system uptime = %lf",eventTime,nowTime);

and then start tapping rapidly with the mouse in the simulator my output isn't incrementing at the same rate:

  • 2022-07-12 14:57:52.383638-0500 Sample[94195:7441534] event time = 7680.477537 and system uptime = 320019.899535
  • 2022-07-12 14:57:52.466105-0500 Sample[94195:7441534] event time = 7680.479539 and system uptime = 320019.982002
  • 2022-07-12 14:57:52.558809-0500 Sample[94195:7441534] event time = 7680.481744 and system uptime = 320020.074706
  • 2022-07-12 14:57:52.650938-0500 Sample[94195:7441534] event time = 7680.483937 and system uptime = 320020.166832
  • 2022-07-12 14:57:52.760327-0500 Sample[94195:7441534] event time = 7680.486561 and system uptime = 320020.276215
  • 2022-07-12 14:57:52.858784-0500 Sample[94195:7441534] event time = 7680.488940 and system uptime = 320020.374671

It's almost like it's multiplied by a certain amount.

  • Our app has been around for a while and this was apparently an issue in the very very early versions of iOS (ie the code has been around for a long time). If the answer I have to go with is "delete the timing code as it's no longer needed" I can probably get that to fly in house.
NSProccessInfo systemUptime gives massively different values in iOS simulator versus device
 
 
Q