Files
flipper/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Utilities/UIDTimeUtilities.m
Lorenzo Blasa db7aa9eeaf OSS
Summary: Move UIDebugger plugin to OSS space.

Reviewed By: passy

Differential Revision: D47634848

fbshipit-source-id: 90e8c0181a2434d0e5d76bdb99b902051e6d702e
2023-07-21 04:47:13 -07:00

53 lines
1.2 KiB
Objective-C

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#if FB_SONARKIT_ENABLED
#import "UIDTimeUtilities.h"
#include <mach/mach_time.h>
#ifdef __cplusplus
extern "C" {
#endif
static mach_timebase_info_data_t _get_timebase(void) {
static mach_timebase_info_data_t machInfo;
static dispatch_once_t machInfoOnceToken = 0;
dispatch_once(&machInfoOnceToken, ^{
const int ret = mach_timebase_info(&machInfo);
if (ret != KERN_SUCCESS) {
machInfo.numer = 0;
machInfo.denom = 1;
}
});
return machInfo;
}
double UIDMonotonicTimeConvertMachUnitsToMS(uint64_t elapsed) {
const mach_timebase_info_data_t tb_info = _get_timebase();
return (double)elapsed * (double)tb_info.numer / (double)tb_info.denom /
(1000.0 * 1000.0);
}
double UIDPerformanceTimeIntervalSince1970(void) {
return [[NSDate date] timeIntervalSince1970];
}
double UIDTimeIntervalToMS(NSTimeInterval timeInterval) {
return (timeInterval * 1000);
}
uint64_t UIDPerformanceNow(void) {
return mach_absolute_time();
}
#ifdef __cplusplus
}
#endif
#endif