diff options
author | theanarkh <2923878201@qq.com> | 2022-05-12 08:24:48 +0300 |
---|---|---|
committer | legendecas <legendecas@gmail.com> | 2022-05-26 17:13:31 +0300 |
commit | cb4a558eeb3abfb3af360ab4ffa779a2bb9b113d (patch) | |
tree | 923791092f8cc1e213cf645e33e5f98a1c9a9d4e | |
parent | a346572b952e7942078af4105d34e049d28d3ea2 (diff) |
perf_hooks: fix start_time of perf_hooks
PR-URL: https://github.com/nodejs/node/pull/43069
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
-rw-r--r-- | lib/_http_client.js | 4 | ||||
-rw-r--r-- | lib/_http_server.js | 4 | ||||
-rw-r--r-- | lib/internal/http.js | 7 | ||||
-rw-r--r-- | lib/internal/perf/observe.js | 9 | ||||
-rw-r--r-- | src/node_http2.cc | 4 | ||||
-rw-r--r-- | src/node_perf.cc | 5 |
6 files changed, 19 insertions, 14 deletions
diff --git a/lib/_http_client.js b/lib/_http_client.js index 41f183aa524..59329ff2436 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -83,6 +83,8 @@ const { hasObserver, } = require('internal/perf/observe'); +const { now } = require('internal/perf/utils'); + const kClientRequestStatistics = Symbol('ClientRequestStatistics'); const { addAbortSignal, finished } = require('stream'); @@ -351,7 +353,7 @@ ClientRequest.prototype._finish = function _finish() { FunctionPrototypeCall(OutgoingMessage.prototype._finish, this); if (hasObserver('http')) { this[kClientRequestStatistics] = { - startTime: process.hrtime(), + startTime: now(), type: 'HttpClient', }; } diff --git a/lib/_http_server.js b/lib/_http_server.js index 615ee4c670c..48f825f15cb 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -100,6 +100,8 @@ const { hasObserver, } = require('internal/perf/observe'); +const { now } = require('internal/perf/utils'); + const STATUS_CODES = { 100: 'Continue', // RFC 7231 6.2.1 101: 'Switching Protocols', // RFC 7231 6.2.2 @@ -198,7 +200,7 @@ function ServerResponse(req) { if (hasObserver('http')) { this[kServerResponseStatistics] = { - startTime: process.hrtime(), + startTime: now(), type: 'HttpRequest', }; } diff --git a/lib/internal/http.js b/lib/internal/http.js index 375118da49f..a92a985ffac 100644 --- a/lib/internal/http.js +++ b/lib/internal/http.js @@ -16,6 +16,8 @@ const { hasObserver, } = require('internal/perf/observe'); +const { now } = require('internal/perf/utils'); + let utcCache; function utcDate() { @@ -36,12 +38,11 @@ function resetCache() { function emitStatistics(statistics) { if (!hasObserver('http') || statistics == null) return; const startTime = statistics.startTime; - const diff = process.hrtime(startTime); const entry = new InternalPerformanceEntry( statistics.type, 'http', - startTime[0] * 1000 + startTime[1] / 1e6, - diff[0] * 1000 + diff[1] / 1e6, + startTime, + now() - startTime, undefined, ); enqueue(entry); diff --git a/lib/internal/perf/observe.js b/lib/internal/perf/observe.js index eedf84d1e7e..4b226c2930c 100644 --- a/lib/internal/perf/observe.js +++ b/lib/internal/perf/observe.js @@ -63,6 +63,8 @@ const { const { inspect } = require('util'); +const { now } = require('internal/perf/utils'); + const kDispatch = Symbol('kDispatch'); const kMaybeBuffer = Symbol('kMaybeBuffer'); const kDeprecatedFields = Symbol('kDeprecatedFields'); @@ -461,7 +463,7 @@ function startPerf(target, key, context = {}) { if (hasObserver(context.type)) { target[key] = { ...context, - startTime: process.hrtime(), + startTime: now(), }; } } @@ -470,12 +472,11 @@ function stopPerf(target, key, context = {}) { const ctx = target[key]; if (ctx && hasObserver(ctx.type)) { const startTime = ctx.startTime; - const diff = process.hrtime(startTime); const entry = new InternalPerformanceEntry( ctx.name, ctx.type, - startTime[0] * 1000 + startTime[1] / 1e6, - diff[0] * 1000 + diff[1] / 1e6, + startTime, + now() - startTime, { ...ctx.detail, ...context.detail }, ); enqueue(entry); diff --git a/src/node_http2.cc b/src/node_http2.cc index 2a4be08e55e..4c180c539a7 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -640,7 +640,7 @@ void Http2Stream::EmitStatistics() { std::unique_ptr<Http2StreamPerformanceEntry> entry = std::make_unique<Http2StreamPerformanceEntry>( "Http2Stream", - start, + start - (node::performance::timeOrigin / 1e6), duration, statistics_); @@ -660,7 +660,7 @@ void Http2Session::EmitStatistics() { std::unique_ptr<Http2SessionPerformanceEntry> entry = std::make_unique<Http2SessionPerformanceEntry>( "Http2Session", - start, + start - (node::performance::timeOrigin / 1e6), duration, statistics_); diff --git a/src/node_perf.cc b/src/node_perf.cc index 8bda1791fce..910e1e47efa 100644 --- a/src/node_perf.cc +++ b/src/node_perf.cc @@ -167,9 +167,8 @@ void MarkGarbageCollectionEnd( "gc", start_time, duration, - GCPerformanceEntry::Details( - static_cast<PerformanceGCKind>(type), - static_cast<PerformanceGCFlags>(flags))); + GCPerformanceEntry::Details(static_cast<PerformanceGCKind>(type), + static_cast<PerformanceGCFlags>(flags))); env->SetImmediate([entry = std::move(entry)](Environment* env) { entry->Notify(env); |