summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlegendecas <legendecas@gmail.com>2023-02-10 01:00:32 +0800
committerlegendecas <legendecas@gmail.com>2023-03-03 00:15:28 +0800
commita8c3d03df0e839178f1046f9123d29c31779f2dd (patch)
treeb6fab955c6d757231d106f477f561507ea429efe /src
parent53116b3b4d77a50a499495344943c1a383ff405f (diff)
downloadnode-new-a8c3d03df0e839178f1046f9123d29c31779f2dd.tar.gz
src: fix negative nodeTiming milestone values
PR-URL: https://github.com/nodejs/node/pull/46588 Fixes: https://github.com/nodejs/node/issues/45958 Refs: https://github.com/nodejs/node/pull/43781 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/env.cc7
-rw-r--r--src/env.h17
-rw-r--r--src/node_perf.cc5
-rw-r--r--src/node_perf_common.h2
4 files changed, 23 insertions, 8 deletions
diff --git a/src/env.cc b/src/env.cc
index 8af50e2f1b..efeccad346 100644
--- a/src/env.cc
+++ b/src/env.cc
@@ -671,8 +671,9 @@ Environment::Environment(IsolateData* isolate_data,
stream_base_state_(isolate_,
StreamBase::kNumStreamBaseStateFields,
MAYBE_FIELD_PTR(env_info, stream_base_state)),
- time_origin_(PERFORMANCE_NOW()),
- time_origin_timestamp_(GetCurrentTimeInMicroseconds()),
+ time_origin_(performance::performance_process_start),
+ time_origin_timestamp_(performance::performance_process_start_timestamp),
+ environment_start_(PERFORMANCE_NOW()),
flags_(flags),
thread_id_(thread_id.id == static_cast<uint64_t>(-1)
? AllocateEnvironmentThreadId().id
@@ -803,7 +804,7 @@ void Environment::InitializeMainContext(Local<Context> context,
set_exiting(false);
performance_state_->Mark(performance::NODE_PERFORMANCE_MILESTONE_ENVIRONMENT,
- time_origin_);
+ environment_start_);
performance_state_->Mark(performance::NODE_PERFORMANCE_MILESTONE_NODE_START,
per_process::node_start_time);
diff --git a/src/env.h b/src/env.h
index c0e28d6c2e..bf16b48fa2 100644
--- a/src/env.h
+++ b/src/env.h
@@ -846,9 +846,11 @@ class Environment : public MemoryRetainer {
inline HandleWrapQueue* handle_wrap_queue() { return &handle_wrap_queue_; }
inline ReqWrapQueue* req_wrap_queue() { return &req_wrap_queue_; }
+ // https://w3c.github.io/hr-time/#dfn-time-origin
inline uint64_t time_origin() {
return time_origin_;
}
+ // https://w3c.github.io/hr-time/#dfn-get-time-origin-timestamp
inline double time_origin_timestamp() {
return time_origin_timestamp_;
}
@@ -1057,10 +1059,17 @@ class Environment : public MemoryRetainer {
AliasedInt32Array stream_base_state_;
- // https://w3c.github.io/hr-time/#dfn-time-origin
- uint64_t time_origin_;
- // https://w3c.github.io/hr-time/#dfn-get-time-origin-timestamp
- double time_origin_timestamp_;
+ // As PerformanceNodeTiming is exposed in worker_threads, the per_process
+ // time origin is exposed in the worker threads. This is an intentional
+ // diverge from the HTML spec of web workers.
+ // Process start time from the monotonic clock. This should not be used as an
+ // absolute time, but only as a time relative to another monotonic clock time.
+ const uint64_t time_origin_;
+ // Process start timestamp from the wall clock. This is an absolute time
+ // exposed as `performance.timeOrigin`.
+ const double time_origin_timestamp_;
+ // This is the time when the environment is created.
+ const uint64_t environment_start_;
std::unique_ptr<performance::PerformanceState> performance_state_;
bool has_serialized_options_ = false;
diff --git a/src/node_perf.cc b/src/node_perf.cc
index 8e8173e16c..1a97f25b6c 100644
--- a/src/node_perf.cc
+++ b/src/node_perf.cc
@@ -38,6 +38,9 @@ using v8::Value;
// Nanoseconds in a millisecond, as a float.
#define NANOS_PER_MILLIS 1e6
+const uint64_t performance_process_start = PERFORMANCE_NOW();
+const double performance_process_start_timestamp =
+ GetCurrentTimeInMicroseconds();
uint64_t performance_v8_start;
PerformanceState::PerformanceState(Isolate* isolate,
@@ -271,7 +274,7 @@ void CreateELDHistogram(const FunctionCallbackInfo<Value>& args) {
void GetTimeOrigin(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
args.GetReturnValue().Set(
- Number::New(args.GetIsolate(), env->time_origin() / 1e6));
+ Number::New(args.GetIsolate(), env->time_origin() / NANOS_PER_MILLIS));
}
void GetTimeOriginTimeStamp(const FunctionCallbackInfo<Value>& args) {
diff --git a/src/node_perf_common.h b/src/node_perf_common.h
index f457d73c57..d519222616 100644
--- a/src/node_perf_common.h
+++ b/src/node_perf_common.h
@@ -20,6 +20,8 @@ namespace performance {
// These occur before the environment is created. Cache them
// here and add them to the milestones when the env is init'd.
+extern const uint64_t performance_process_start;
+extern const double performance_process_start_timestamp;
extern uint64_t performance_v8_start;
#define NODE_PERFORMANCE_MILESTONES(V) \