Skip to content

Commit 85d6da4

Browse files
committed
perf_hooks: fix_performance_start_time
fix #43062
1 parent 8e0f3ff commit 85d6da4

File tree

6 files changed

+18
-12
lines changed

6 files changed

+18
-12
lines changed

lib/_http_client.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ const {
7979
hasObserver,
8080
} = require('internal/perf/observe');
8181

82+
const { now } = require('internal/perf/utils');
83+
8284
const kClientRequestStatistics = Symbol('ClientRequestStatistics');
8385

8486
const { addAbortSignal, finished } = require('stream');
@@ -345,7 +347,7 @@ ClientRequest.prototype._finish = function _finish() {
345347
FunctionPrototypeCall(OutgoingMessage.prototype._finish, this);
346348
if (hasObserver('http')) {
347349
this[kClientRequestStatistics] = {
348-
startTime: process.hrtime(),
350+
startTime: now(),
349351
type: 'HttpClient',
350352
};
351353
}

lib/_http_server.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ const {
9696
hasObserver,
9797
} = require('internal/perf/observe');
9898

99+
const { now } = require('internal/perf/utils');
100+
99101
const STATUS_CODES = {
100102
100: 'Continue', // RFC 7231 6.2.1
101103
101: 'Switching Protocols', // RFC 7231 6.2.2
@@ -194,7 +196,7 @@ function ServerResponse(req) {
194196

195197
if (hasObserver('http')) {
196198
this[kServerResponseStatistics] = {
197-
startTime: process.hrtime(),
199+
startTime: now(),
198200
type: 'HttpRequest',
199201
};
200202
}

lib/internal/http.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const {
1616
hasObserver,
1717
} = require('internal/perf/observe');
1818

19+
const { now } = require('internal/perf/utils');
20+
1921
let utcCache;
2022

2123
function utcDate() {
@@ -36,12 +38,11 @@ function resetCache() {
3638
function emitStatistics(statistics) {
3739
if (!hasObserver('http') || statistics == null) return;
3840
const startTime = statistics.startTime;
39-
const diff = process.hrtime(startTime);
4041
const entry = new InternalPerformanceEntry(
4142
statistics.type,
4243
'http',
43-
startTime[0] * 1000 + startTime[1] / 1e6,
44-
diff[0] * 1000 + diff[1] / 1e6,
44+
startTime,
45+
now() - startTime,
4546
undefined,
4647
);
4748
enqueue(entry);

lib/internal/perf/observe.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ const {
6363

6464
const { inspect } = require('util');
6565

66+
const { now } = require('internal/perf/utils');
67+
6668
const kDispatch = Symbol('kDispatch');
6769
const kMaybeBuffer = Symbol('kMaybeBuffer');
6870
const kDeprecatedFields = Symbol('kDeprecatedFields');
@@ -451,7 +453,7 @@ function startPerf(target, key, context = {}) {
451453
if (hasObserver(context.type)) {
452454
target[key] = {
453455
...context,
454-
startTime: process.hrtime(),
456+
startTime: now(),
455457
};
456458
}
457459
}
@@ -460,12 +462,11 @@ function stopPerf(target, key, context = {}) {
460462
const ctx = target[key];
461463
if (ctx && hasObserver(ctx.type)) {
462464
const startTime = ctx.startTime;
463-
const diff = process.hrtime(startTime);
464465
const entry = new InternalPerformanceEntry(
465466
ctx.name,
466467
ctx.type,
467-
startTime[0] * 1000 + startTime[1] / 1e6,
468-
diff[0] * 1000 + diff[1] / 1e6,
468+
startTime,
469+
now() - startTime,
469470
{ ...ctx.detail, ...context.detail },
470471
);
471472
enqueue(entry);

src/node_http2.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ void Http2Stream::EmitStatistics() {
641641
std::unique_ptr<Http2StreamPerformanceEntry> entry =
642642
std::make_unique<Http2StreamPerformanceEntry>(
643643
"Http2Stream",
644-
start,
644+
start - (node::performance::timeOrigin / 1e6),
645645
duration,
646646
statistics_);
647647

@@ -661,7 +661,7 @@ void Http2Session::EmitStatistics() {
661661
std::unique_ptr<Http2SessionPerformanceEntry> entry =
662662
std::make_unique<Http2SessionPerformanceEntry>(
663663
"Http2Session",
664-
start,
664+
start - (node::performance::timeOrigin / 1e6),
665665
duration,
666666
statistics_);
667667

src/node_perf.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ void MarkGarbageCollectionEnd(
165165
std::unique_ptr<GCPerformanceEntry> entry =
166166
std::make_unique<GCPerformanceEntry>(
167167
"gc",
168-
start_time,
168+
start_time - (timeOrigin / 1e6),
169169
duration,
170170
GCPerformanceEntry::Details(
171171
static_cast<PerformanceGCKind>(type),

0 commit comments

Comments
 (0)