Flipper Network Plugin change timestamps source

Summary:
Flipper Network plugin uses timestamps for various usages e.g. start time of network requests, request duration, etc.

This diff changes the origin of such timestamps.

[NSDate timeIntervalSinceReferenceDate] in favour of FBMonotonicDeviceTimeGetCurrentMilliseconds().

The former uses a timestamp based on date. The latter uses the system boot time.

This translates in errors when the Flipper Desktop app tries to make sense of such timestamps.

This change also adds parity with the Android network plugin that uses System.currentTimeMillis().

The result is multiplied by 1000 as JavaScript expects a timestamp in millseconds.

Reviewed By: fabiomassimo

Differential Revision: D29029192

fbshipit-source-id: b38a4798ecf1564f5801ff3549ffeb9671fa32d6
This commit is contained in:
Lorenzo Blasa
2021-06-11 10:31:19 -07:00
committed by Facebook GitHub Bot
parent 33d5d0082c
commit 1cf7456133
2 changed files with 5 additions and 15 deletions

View File

@@ -19,7 +19,8 @@
@interface NSDate (SonarUtility)
+ (uint64_t)timestamp;
+ (NSTimeInterval)timestamp;
@end
@interface FLEXUtility : NSObject

View File

@@ -110,20 +110,9 @@
@implementation NSDate (SonarUtility)
+ (uint64_t)getTimeNanoseconds {
static struct mach_timebase_info tb_info = {0};
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
__unused int ret = mach_timebase_info(&tb_info);
assert(0 == ret);
});
return (mach_absolute_time() * tb_info.numer) / tb_info.denom;
}
+ (uint64_t)timestamp {
const uint64_t nowNanoSeconds = [self getTimeNanoseconds];
return nowNanoSeconds / 1000000;
+ (NSTimeInterval)timestamp {
const NSTimeInterval timestamp = [[NSDate date] timeIntervalSince1970];
return timestamp * 1000;
}
@end