@@ -35,11 +35,9 @@ using v8::Value;
35
35
36
36
// Microseconds in a millisecond, as a float.
37
37
#define MICROS_PER_MILLIS 1e3
38
+ // Nanoseconds in a millisecond, as a float.
39
+ #define NANOS_PER_MILLIS 1e6
38
40
39
- // https://w3c.github.io/hr-time/#dfn-time-origin
40
- const uint64_t timeOrigin = PERFORMANCE_NOW();
41
- // https://w3c.github.io/hr-time/#dfn-time-origin-timestamp
42
- const double timeOriginTimestamp = GetCurrentTimeInMicroseconds();
43
41
uint64_t performance_v8_start;
44
42
45
43
PerformanceState::PerformanceState (Isolate* isolate,
@@ -160,9 +158,9 @@ void MarkGarbageCollectionEnd(
160
158
return ;
161
159
162
160
double start_time =
163
- (state->performance_last_gc_start_mark - timeOrigin) / 1e6 ;
161
+ (state->performance_last_gc_start_mark - env-> time_origin ()) / NANOS_PER_MILLIS ;
164
162
double duration =
165
- (PERFORMANCE_NOW () / 1e6 ) - (state->performance_last_gc_start_mark / 1e6 );
163
+ (PERFORMANCE_NOW () / NANOS_PER_MILLIS ) - (state->performance_last_gc_start_mark / NANOS_PER_MILLIS );
166
164
167
165
std::unique_ptr<GCPerformanceEntry> entry =
168
166
std::make_unique<GCPerformanceEntry>(
@@ -257,12 +255,14 @@ void CreateELDHistogram(const FunctionCallbackInfo<Value>& args) {
257
255
}
258
256
259
257
void GetTimeOrigin (const FunctionCallbackInfo<Value>& args) {
260
- args.GetReturnValue ().Set (Number::New (args.GetIsolate (), timeOrigin / 1e6 ));
258
+ Environment* env = Environment::GetCurrent (args);
259
+ args.GetReturnValue ().Set (Number::New (args.GetIsolate (), env->time_origin () / 1e6 ));
261
260
}
262
261
263
262
void GetTimeOriginTimeStamp (const FunctionCallbackInfo<Value>& args) {
263
+ Environment* env = Environment::GetCurrent (args);
264
264
args.GetReturnValue ().Set (
265
- Number::New (args.GetIsolate (), timeOriginTimestamp / MICROS_PER_MILLIS));
265
+ Number::New (args.GetIsolate (), env-> time_origin_timestamp () / MICROS_PER_MILLIS));
266
266
}
267
267
268
268
void Initialize (Local<Object> target,
0 commit comments