@@ -35,11 +35,9 @@ using v8::Value;
3535
3636// Microseconds in a millisecond, as a float.
3737#define MICROS_PER_MILLIS 1e3
38+ // Nanoseconds in a millisecond, as a float.
39+ #define NANOS_PER_MILLIS 1e6
3840
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();
4341uint64_t performance_v8_start;
4442
4543PerformanceState::PerformanceState (Isolate* isolate,
@@ -160,9 +158,10 @@ void MarkGarbageCollectionEnd(
160158 return ;
161159
162160 double start_time =
163- (state->performance_last_gc_start_mark - timeOrigin) / 1e6 ;
164- double duration =
165- (PERFORMANCE_NOW () / 1e6 ) - (state->performance_last_gc_start_mark / 1e6 );
161+ (state->performance_last_gc_start_mark - env->time_origin ()) /
162+ NANOS_PER_MILLIS;
163+ double duration = (PERFORMANCE_NOW () / NANOS_PER_MILLIS) -
164+ (state->performance_last_gc_start_mark / NANOS_PER_MILLIS);
166165
167166 std::unique_ptr<GCPerformanceEntry> entry =
168167 std::make_unique<GCPerformanceEntry>(
@@ -257,12 +256,15 @@ void CreateELDHistogram(const FunctionCallbackInfo<Value>& args) {
257256}
258257
259258void GetTimeOrigin (const FunctionCallbackInfo<Value>& args) {
260- args.GetReturnValue ().Set (Number::New (args.GetIsolate (), timeOrigin / 1e6 ));
259+ Environment* env = Environment::GetCurrent (args);
260+ args.GetReturnValue ().Set (
261+ Number::New (args.GetIsolate (), env->time_origin () / 1e6 ));
261262}
262263
263264void GetTimeOriginTimeStamp (const FunctionCallbackInfo<Value>& args) {
264- args.GetReturnValue ().Set (
265- Number::New (args.GetIsolate (), timeOriginTimestamp / MICROS_PER_MILLIS));
265+ Environment* env = Environment::GetCurrent (args);
266+ args.GetReturnValue ().Set (Number::New (
267+ args.GetIsolate (), env->time_origin_timestamp () / MICROS_PER_MILLIS));
266268}
267269
268270void Initialize (Local<Object> target,
0 commit comments