| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a62b042 commit e192ba1
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,45 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const common = require('../common.js'); | ||
| 5 | + | ||
| 6 | + const bench = common.createBenchmark(main, { | ||
| 7 | + n: [1e6], | ||
| 8 | + method: ['timeOrigin', 'toJSON'], | ||
| 9 | + }); | ||
| 10 | + | ||
| 11 | + function main({ method, n }) { | ||
| 12 | + switch (method) { | ||
| 13 | + case 'timeOrigin': | ||
| 14 | + benchTimeOrigin(n); | ||
| 15 | + break; | ||
| 16 | + case 'toJSON': | ||
| 17 | + benchToJSON(n); | ||
| 18 | + break; | ||
| 19 | + default: | ||
| 20 | + throw new Error(`Unsupported method ${method}`); | ||
| 21 | + } | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + function benchTimeOrigin(n) { | ||
| 25 | + const arr = []; | ||
| 26 | + for (let i = 0; i < n; ++i) { | ||
| 27 | + arr.push(performance.timeOrigin); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + bench.start(); | ||
| 31 | + for (let i = 0; i < n; i++) { | ||
| 32 | + arr[i] = performance.timeOrigin; | ||
| 33 | + } | ||
| 34 | + bench.end(n); | ||
| 35 | + | ||
| 36 | + assert.strictEqual(arr.length, n); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + function benchToJSON(n) { | ||
| 40 | + bench.start(); | ||
| 41 | + for (let i = 0; i < n; i++) { | ||
| 42 | + performance.toJSON(); | ||
| 43 | + } | ||
| 44 | + bench.end(n); | ||
| 45 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,7 +22,7 @@ const { | |||
| 22 | 22 | defineEventHandler, | |
| 23 | 23 | } = require('internal/event_target'); | |
| 24 | 24 | ||
| 25 | - const { now } = require('internal/perf/utils'); | ||
| 25 | + const { now, getTimeOriginTimestamp } = require('internal/perf/utils'); | ||
| 26 | 26 | ||
| 27 | 27 | const { markResourceTiming } = require('internal/perf/resource_timing'); | |
| 28 | 28 | ||
@@ -46,10 +46,6 @@ const { inspect } = require('util'); | |||
| 46 | 46 | const { validateInternalField } = require('internal/validators'); | |
| 47 | 47 | const { convertToInt } = require('internal/webidl'); | |
| 48 | 48 | ||
| 49 | - const { | ||
| 50 | - getTimeOriginTimestamp, | ||
| 51 | - } = internalBinding('performance'); | ||
| 52 | - | ||
| 53 | 49 | const kPerformanceBrand = Symbol('performance'); | |
| 54 | 50 | ||
| 55 | 51 | class Performance extends EventTarget { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | const { | |
| 4 | 4 | constants: { | |
| 5 | 5 | NODE_PERFORMANCE_MILESTONE_TIME_ORIGIN, | |
| 6 | + NODE_PERFORMANCE_MILESTONE_TIME_ORIGIN_TIMESTAMP, | ||
| 6 | 7 | }, | |
| 7 | 8 | milestones, | |
| 8 | 9 | now, | |
@@ -22,7 +23,12 @@ function getMilestoneTimestamp(milestoneIdx) { | |||
| 22 | 23 | return ns / 1e6 - getTimeOrigin(); | |
| 23 | 24 | } | |
| 24 | 25 | ||
| 26 | + function getTimeOriginTimestamp() { | ||
| 27 | + return milestones[NODE_PERFORMANCE_MILESTONE_TIME_ORIGIN_TIMESTAMP] / 1e3; | ||
| 28 | + } | ||
| 29 | + | ||
| 25 | 30 | module.exports = { | |
| 26 | 31 | now, | |
| 27 | 32 | getMilestoneTimestamp, | |
| 33 | + getTimeOriginTimestamp, | ||
| 28 | 34 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -880,7 +880,10 @@ Environment::Environment(IsolateData* isolate_data, | |||
| 880 | 880 | destroy_async_id_list_.reserve(512); | |
| 881 | 881 | ||
| 882 | 882 | performance_state_ = std::make_unique<performance::PerformanceState>( | |
| 883 | - isolate, time_origin_, MAYBE_FIELD_PTR(env_info, performance_state)); | ||
| 883 | + isolate, | ||
| 884 | + time_origin_, | ||
| 885 | + time_origin_timestamp_, | ||
| 886 | + MAYBE_FIELD_PTR(env_info, performance_state)); | ||
| 884 | 887 | ||
| 885 | 888 | if (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( | |
| 886 | 889 | TRACING_CATEGORY_NODE1(environment)) != 0) { | |
@@ -1837,7 +1840,7 @@ void Environment::DeserializeProperties(const EnvSerializeInfo* info) { | |||
| 1837 | 1840 | immediate_info_.Deserialize(ctx); | |
| 1838 | 1841 | timeout_info_.Deserialize(ctx); | |
| 1839 | 1842 | tick_info_.Deserialize(ctx); | |
| 1840 | - performance_state_->Deserialize(ctx, time_origin_); | ||
| 1843 | + performance_state_->Deserialize(ctx, time_origin_, time_origin_timestamp_); | ||
| 1841 | 1844 | exit_info_.Deserialize(ctx); | |
| 1842 | 1845 | stream_base_state_.Deserialize(ctx); | |
| 1843 | 1846 | should_abort_on_uncaught_toggle_.Deserialize(ctx); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,7 +24,6 @@ using v8::Integer; | |||
| 24 | 24 | using v8::Isolate; | |
| 25 | 25 | using v8::Local; | |
| 26 | 26 | using v8::MaybeLocal; | |
| 27 | - using v8::Number; | ||
| 28 | 27 | using v8::Object; | |
| 29 | 28 | using v8::ObjectTemplate; | |
| 30 | 29 | using v8::PropertyAttribute; | |
@@ -43,6 +42,7 @@ uint64_t performance_v8_start; | |||
| 43 | 42 | ||
| 44 | 43 | PerformanceState::PerformanceState(Isolate* isolate, | |
| 45 | 44 | uint64_t time_origin, | |
| 45 | + double time_origin_timestamp, | ||
| 46 | 46 | const PerformanceState::SerializeInfo* info) | |
| 47 | 47 | : root(isolate, | |
| 48 | 48 | sizeof(performance_state_internal), | |
@@ -63,7 +63,7 @@ PerformanceState::PerformanceState(Isolate* isolate, | |||
| 63 | 63 | // For deserialized performance states, we will do the | |
| 64 | 64 | // initialization in the deserialize callback. | |
| 65 | 65 | ResetMilestones(); | |
| 66 | - Initialize(time_origin); | ||
| 66 | + Initialize(time_origin, time_origin_timestamp); | ||
| 67 | 67 | } | |
| 68 | 68 | } | |
| 69 | 69 | ||
@@ -86,23 +86,27 @@ PerformanceState::SerializeInfo PerformanceState::Serialize( | |||
| 86 | 86 | return info; | |
| 87 | 87 | } | |
| 88 | 88 | ||
| 89 | - void PerformanceState::Initialize(uint64_t time_origin) { | ||
| 90 | - // We are only reusing the milestone array to store the time origin, so do | ||
| 91 | - // not use the Mark() method. The time origin milestone is not exposed | ||
| 92 | - // to user land. | ||
| 89 | + void PerformanceState::Initialize(uint64_t time_origin, | ||
| 90 | + double time_origin_timestamp) { | ||
| 91 | + // We are only reusing the milestone array to store the time origin | ||
| 92 | + // and time origin timestamp, so do not use the Mark() method. | ||
| 93 | + // The time origin milestone is not exposed to user land. | ||
| 93 | 94 | this->milestones[NODE_PERFORMANCE_MILESTONE_TIME_ORIGIN] = | |
| 94 | 95 | static_cast<double>(time_origin); | |
| 96 | + this->milestones[NODE_PERFORMANCE_MILESTONE_TIME_ORIGIN_TIMESTAMP] = | ||
| 97 | + time_origin_timestamp; | ||
| 95 | 98 | } | |
| 96 | 99 | ||
| 97 | 100 | void PerformanceState::Deserialize(v8::Local<v8::Context> context, | |
| 98 | - uint64_t time_origin) { | ||
| 101 | + uint64_t time_origin, | ||
| 102 | + double time_origin_timestamp) { | ||
| 99 | 103 | // Resets the pointers. | |
| 100 | 104 | root.Deserialize(context); | |
| 101 | 105 | milestones.Deserialize(context); | |
| 102 | 106 | observers.Deserialize(context); | |
| 103 | 107 | ||
| 104 | - // Re-initialize the time origin i.e. the process start time. | ||
| 105 | - Initialize(time_origin); | ||
| 108 | + // Re-initialize the time origin and timestamp i.e. the process start time. | ||
| 109 | + Initialize(time_origin, time_origin_timestamp); | ||
| 106 | 110 | } | |
| 107 | 111 | ||
| 108 | 112 | std::ostream& operator<<(std::ostream& o, | |
@@ -254,7 +258,7 @@ void Notify(const FunctionCallbackInfo<Value>& args) { | |||
| 254 | 258 | void LoopIdleTime(const FunctionCallbackInfo<Value>& args) { | |
| 255 | 259 | Environment* env = Environment::GetCurrent(args); | |
| 256 | 260 | uint64_t idle_time = uv_metrics_idle_time(env->event_loop()); | |
| 257 | - args.GetReturnValue().Set(1.0 * idle_time / 1e6); | ||
| 261 | + args.GetReturnValue().Set(1.0 * idle_time / NANOS_PER_MILLIS); | ||
| 258 | 262 | } | |
| 259 | 263 | ||
| 260 | 264 | void CreateELDHistogram(const FunctionCallbackInfo<Value>& args) { | |
@@ -278,12 +282,6 @@ void CreateELDHistogram(const FunctionCallbackInfo<Value>& args) { | |||
| 278 | 282 | args.GetReturnValue().Set(histogram->object()); | |
| 279 | 283 | } | |
| 280 | 284 | ||
| 281 | - void GetTimeOriginTimeStamp(const FunctionCallbackInfo<Value>& args) { | ||
| 282 | - Environment* env = Environment::GetCurrent(args); | ||
| 283 | - args.GetReturnValue().Set(Number::New( | ||
| 284 | - args.GetIsolate(), env->time_origin_timestamp() / MICROS_PER_MILLIS)); | ||
| 285 | - } | ||
| 286 | - | ||
| 287 | 285 | void MarkBootstrapComplete(const FunctionCallbackInfo<Value>& args) { | |
| 288 | 286 | Realm* realm = Realm::GetCurrent(args); | |
| 289 | 287 | CHECK_EQ(realm->kind(), Realm::Kind::kPrincipal); | |
@@ -324,7 +322,6 @@ static void CreatePerIsolateProperties(IsolateData* isolate_data, | |||
| 324 | 322 | RemoveGarbageCollectionTracking); | |
| 325 | 323 | SetMethod(isolate, target, "notify", Notify); | |
| 326 | 324 | SetMethod(isolate, target, "loopIdleTime", LoopIdleTime); | |
| 327 | - SetMethod(isolate, target, "getTimeOriginTimestamp", GetTimeOriginTimeStamp); | ||
| 328 | 325 | SetMethod(isolate, target, "createELDHistogram", CreateELDHistogram); | |
| 329 | 326 | SetMethod(isolate, target, "markBootstrapComplete", MarkBootstrapComplete); | |
| 330 | 327 | SetFastMethodNoSideEffect( | |
@@ -391,7 +388,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) { | |||
| 391 | 388 | registry->Register(RemoveGarbageCollectionTracking); | |
| 392 | 389 | registry->Register(Notify); | |
| 393 | 390 | registry->Register(LoopIdleTime); | |
| 394 | - registry->Register(GetTimeOriginTimeStamp); | ||
| 395 | 391 | registry->Register(CreateELDHistogram); | |
| 396 | 392 | registry->Register(MarkBootstrapComplete); | |
| 397 | 393 | registry->Register(SlowPerformanceNow); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,6 +25,7 @@ extern const double performance_process_start_timestamp; | |||
| 25 | 25 | extern uint64_t performance_v8_start; | |
| 26 | 26 | ||
| 27 | 27 | #define NODE_PERFORMANCE_MILESTONES(V) \ | |
| 28 | + V(TIME_ORIGIN_TIMESTAMP, "timeOriginTimestamp") \ | ||
| 28 | 29 | V(TIME_ORIGIN, "timeOrigin") \ | |
| 29 | 30 | V(ENVIRONMENT, "environment") \ | |
| 30 | 31 | V(NODE_START, "nodeStart") \ | |
@@ -64,10 +65,13 @@ class PerformanceState { | |||
| 64 | 65 | ||
| 65 | 66 | explicit PerformanceState(v8::Isolate* isolate, | |
| 66 | 67 | uint64_t time_origin, | |
| 68 | + double time_origin_timestamp, | ||
| 67 | 69 | const SerializeInfo* info); | |
| 68 | 70 | SerializeInfo Serialize(v8::Local<v8::Context> context, | |
| 69 | 71 | v8::SnapshotCreator* creator); | |
| 70 | - void Deserialize(v8::Local<v8::Context> context, uint64_t time_origin); | ||
| 72 | + void Deserialize(v8::Local<v8::Context> context, | ||
| 73 | + uint64_t time_origin, | ||
| 74 | + double time_origin_timestamp); | ||
| 71 | 75 | friend std::ostream& operator<<(std::ostream& o, const SerializeInfo& i); | |
| 72 | 76 | ||
| 73 | 77 | AliasedUint8Array root; | |
@@ -81,7 +85,7 @@ class PerformanceState { | |||
| 81 | 85 | uint64_t ts = PERFORMANCE_NOW()); | |
| 82 | 86 | ||
| 83 | 87 | private: | |
| 84 | - void Initialize(uint64_t time_origin); | ||
| 88 | + void Initialize(uint64_t time_origin, double time_origin_timestamp); | ||
| 85 | 89 | void ResetMilestones(); | |
| 86 | 90 | struct performance_state_internal { | |
| 87 | 91 | // doubles first so that they are always sizeof(double)-aligned | |
| Back | FazBrowse Home | New Git URL |
0 commit comments