diff --git a/lib/_http_client.js b/lib/_http_client.js index 0c1c60de278462..469c9a332d72c1 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -79,6 +79,8 @@ const { hasObserver, } = require('internal/perf/observe'); +const { now } = require('internal/perf/utils'); + const kClientRequestStatistics = Symbol('ClientRequestStatistics'); const { addAbortSignal, finished } = require('stream'); @@ -345,7 +347,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 2e285f5fd74cb3..27fe9dcfbd7a82 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -96,6 +96,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 @@ -193,7 +195,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 375118da49f59b..a92a985ffacccc 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 c3ce8345b156ea..cc548af4af3754 100644 --- a/lib/internal/perf/observe.js +++ b/lib/internal/perf/observe.js @@ -65,6 +65,8 @@ const { inspect } = require('util'); const kBuffer = Symbol('kBuffer'); const kCallback = Symbol('kCallback'); +const { now } = require('internal/perf/utils'); + const kDispatch = Symbol('kDispatch'); const kEntryTypes = Symbol('kEntryTypes'); const kMaybeBuffer = Symbol('kMaybeBuffer'); @@ -454,7 +456,7 @@ function startPerf(target, key, context = {}) { if (hasObserver(context.type)) { target[key] = { ...context, - startTime: process.hrtime(), + startTime: now(), }; } } @@ -463,12 +465,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 b1665782a90c12..8df924a29028e2 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -640,7 +640,7 @@ void Http2Stream::EmitStatistics() { std::unique_ptr entry = std::make_unique( "Http2Stream", - start, + start - (node::performance::timeOrigin / 1e6), duration, statistics_); @@ -660,7 +660,7 @@ void Http2Session::EmitStatistics() { std::unique_ptr entry = std::make_unique( "Http2Session", - start, + start - (node::performance::timeOrigin / 1e6), duration, statistics_); diff --git a/src/node_perf.cc b/src/node_perf.cc index 8bda1791fce7db..910e1e47efa0a5 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(type), - static_cast(flags))); + GCPerformanceEntry::Details(static_cast(type), + static_cast(flags))); env->SetImmediate([entry = std::move(entry)](Environment* env) { entry->Notify(env);