1
1
#import " RNPerformanceManager.h"
2
2
#import < sys/sysctl.h>
3
3
#include < math.h>
4
+ #include < chrono>
4
5
#import < QuartzCore/QuartzCore.h>
5
6
#import < React/RCTRootView.h>
6
7
#import < React/RCTPerformanceLogger.h>
7
8
8
- static CFTimeInterval getProcessStartTime () {
9
+ static CFTimeInterval getProcessStartTime ()
10
+ {
9
11
size_t len = 4 ;
10
12
int mib[len];
11
13
struct kinfo_proc kp;
@@ -19,6 +21,11 @@ static CFTimeInterval getProcessStartTime() {
19
21
return startTime.tv_sec + startTime.tv_usec / 1e6 ;
20
22
}
21
23
24
+ static int64_t getTimestamp ()
25
+ {
26
+ return std::chrono::system_clock::now ().time_since_epoch () / std::chrono::milliseconds (1 );
27
+ }
28
+
22
29
static int64_t sNativeLaunchStart ;
23
30
static int64_t sNativeLaunchEnd ;
24
31
@@ -32,9 +39,8 @@ @implementation RNPerformanceManager
32
39
+ (void ) initialize
33
40
{
34
41
[super initialize ];
35
- CFTimeInterval absoluteTimeToRelativeTime = CACurrentMediaTime () - [NSDate date ].timeIntervalSince1970 ;
36
- sNativeLaunchStart = (getProcessStartTime () + absoluteTimeToRelativeTime) * 1000 ;
37
- sNativeLaunchEnd = CACurrentMediaTime () * 1000 ;
42
+ sNativeLaunchStart = (getProcessStartTime () - [NSDate date ].timeIntervalSince1970 ) * 1000 + getTimestamp ();
43
+ sNativeLaunchEnd = getTimestamp ();
38
44
}
39
45
40
46
- (void )setBridge : (RCTBridge *)bridge
@@ -49,7 +55,7 @@ - (void)setBridge:(RCTBridge *)bridge
49
55
50
56
- (void )contentDidAppear
51
57
{
52
- int64_t startTime = CACurrentMediaTime () * 1000 ;
58
+ int64_t startTime = getTimestamp () ;
53
59
[self emitMarkNamed: @" nativeLaunchStart" withStartTime: sNativeLaunchStart ];
54
60
[self emitMarkNamed: @" nativeLaunchEnd" withStartTime: sNativeLaunchEnd ];
55
61
[self emitTag: RCTPLScriptDownload withNamePrefix: @" download" ];
@@ -66,6 +72,7 @@ - (void)contentDidAppear
66
72
67
73
- (void )invalidate
68
74
{
75
+ [super invalidate ];
69
76
NSNotificationCenter *notificationCenter = NSNotificationCenter .defaultCenter ;
70
77
[notificationCenter removeObserver: self ];
71
78
}
@@ -88,6 +95,7 @@ - (void)emitTag:(RCTPLTag)tag withNamePrefix:(NSString *)namePrefix
88
95
NSLog (@" Ignoring marks prefixed %@ (%lu ) as data is unavailable (duration: %lld , end: %lld )" , namePrefix, (unsigned long )tag, duration, end);
89
96
return ;
90
97
}
98
+ end += getTimestamp () - (CACurrentMediaTime () * 1000 );
91
99
[self emitMarkNamed: [namePrefix stringByAppendingString: @" Start" ] withStartTime: end-duration];
92
100
[self emitMarkNamed: [namePrefix stringByAppendingString: @" End" ] withStartTime: end];
93
101
}
@@ -107,7 +115,7 @@ - (void)emitMetricNamed:(NSString *)name withValue:(NSNumber *)value
107
115
if (hasListeners) {
108
116
[self sendEventWithName: @" metric" body: @{
109
117
@" name" : name,
110
- @" startTime" : @(CACurrentMediaTime () * 1000 ),
118
+ @" startTime" : @(getTimestamp () ),
111
119
@" value" : value
112
120
}];
113
121
}
0 commit comments