GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — perf_hooks: fix truncation of uvMetricsInfo counters · nodejs/node@c418cf6

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • node_perf.cc
    • node_perf_common.h
  • test/parallel
    • test-performance-nodetiming-uvmetricsinfo-buffer.js
    • test-performance-nodetiming-uvmetricsinfo.js
  • typings/internalBinding
    • performance.d.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/node_perf.cc‎

Copy file name to clipboardExpand all lines: src/node_perf.cc
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,12 @@ void UvMetricsInfo(const FunctionCallbackInfo<Value>& args) {
280280
uv_metrics_t metrics;
281281
// uv_metrics_info always return 0
282282
CHECK_EQ(uv_metrics_info(env->event_loop(), &metrics), 0);
283-
AliasedInt32Array& buffer = env->performance_state()->uv_metrics;
284-
buffer[0] = static_cast<int32_t>(metrics.loop_count);
285-
buffer[1] = static_cast<int32_t>(metrics.events);
286-
buffer[2] = static_cast<int32_t>(metrics.events_waiting);
283+
// libuv reports 64-bit counters. Store them as doubles so that they are
284+
// exact up to Number.MAX_SAFE_INTEGER instead of wrapping at 2^31.
285+
AliasedFloat64Array& buffer = env->performance_state()->uv_metrics;
286+
buffer[0] = static_cast<double>(metrics.loop_count);
287+
buffer[1] = static_cast<double>(metrics.events);
288+
buffer[2] = static_cast<double>(metrics.events_waiting);
287289
}
288290

289291
void CreateELDHistogram(const FunctionCallbackInfo<Value>& args) {
Collapse file

‎src/node_perf_common.h‎

Copy file name to clipboardExpand all lines: src/node_perf_common.h
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class PerformanceState {
7979
AliasedUint8Array root;
8080
AliasedFloat64Array milestones;
8181
AliasedUint32Array observers;
82-
AliasedInt32Array uv_metrics;
82+
AliasedFloat64Array uv_metrics;
8383

8484
uint64_t performance_last_gc_start_mark = 0;
8585
uint16_t current_gc_type = 0;
@@ -93,8 +93,8 @@ class PerformanceState {
9393
struct performance_state_internal {
9494
// doubles first so that they are always sizeof(double)-aligned
9595
double milestones[NODE_PERFORMANCE_MILESTONE_INVALID];
96+
double uv_metrics[3];
9697
uint32_t observers[NODE_PERFORMANCE_ENTRY_TYPE_INVALID];
97-
int32_t uv_metrics[3];
9898
};
9999
};
100100

Collapse file

‎test/parallel/test-performance-nodetiming-uvmetricsinfo-buffer.js‎

Copy file name to clipboard
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Flags: --expose-internals
2+
'use strict';
3+
4+
require('../common');
5+
const assert = require('node:assert');
6+
const { internalBinding } = require('internal/test/binding');
7+
8+
// The event loop metrics reported by libuv are 64-bit counters. The buffer
9+
// used to transfer them to JavaScript must not truncate them to 32 bits.
10+
const { uvMetricsBuffer, uvMetricsInfo } = internalBinding('performance');
11+
assert.ok(uvMetricsBuffer instanceof Float64Array);
12+
assert.strictEqual(uvMetricsBuffer.length, 3);
13+
14+
uvMetricsInfo();
15+
for (const value of uvMetricsBuffer) {
16+
assert.ok(Number.isSafeInteger(value), `${value} is not a safe integer`);
17+
assert.ok(value >= 0, `${value} is negative`);
18+
}
Collapse file

‎test/parallel/test-performance-nodetiming-uvmetricsinfo.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-performance-nodetiming-uvmetricsinfo.js
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ const fixtures = require('../common/fixtures');
1313

1414
const file = fixtures.path('test-nodetiming-uvmetricsinfo.js');
1515

16-
{
16+
// Run both with and without the built-in startup snapshot, as the
17+
// performance state buffers are initialized differently in each case.
18+
for (const execArgv of [[], ['--no-node-snapshot']]) {
1719
const { status, stderr } = spawnSync(
1820
process.execPath,
1921
[
22+
...execArgv,
2023
file,
2124
],
2225
);
Collapse file

‎typings/internalBinding/performance.d.ts‎

Copy file name to clipboardExpand all lines: typings/internalBinding/performance.d.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,6 @@ export interface PerformanceBinding {
146146
): InternalPerformanceBinding.ELDHistogram;
147147
markBootstrapComplete(): void;
148148
uvMetricsInfo(): void;
149-
uvMetricsBuffer: Int32Array;
149+
uvMetricsBuffer: Float64Array;
150150
now(): number;
151151
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.