From fa7e500a2b7b0795a60a15ff1a99ca5f06f9291d Mon Sep 17 00:00:00 2001 From: James M Snell Date: Wed, 10 Jan 2018 09:42:10 -0800 Subject: [PATCH 1/3] perf_hooks: add warning when too many entries in the timeline --- doc/api/perf_hooks.md | 12 ++++++ lib/perf_hooks.js | 49 +++++++++++++++++++++-- test/parallel/test-performance-warning.js | 29 ++++++++++++++ 3 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 test/parallel/test-performance-warning.js diff --git a/doc/api/perf_hooks.md b/doc/api/perf_hooks.md index 2f2910af93db34..807f63e87d2617 100644 --- a/doc/api/perf_hooks.md +++ b/doc/api/perf_hooks.md @@ -125,6 +125,18 @@ Creates a new `PerformanceMark` entry in the Performance Timeline. A `performanceEntry.duration` is always `0`. Performance marks are used to mark specific significant moments in the Performance Timeline. +### performance.maxBufferSize + + +Value: {number} + +The maximum number of Performance Entry items that should be added to the +Performance Timeline. This limit is not strictly enforced, but a process +warning will be emitted if the number of entries in the timeline exceeds +this limit. + ### performance.measure(name, startMark, endMark) diff --git a/lib/perf_hooks.js b/lib/perf_hooks.js index 837cc734200fa6..6fd6e4a6b768ce 100644 --- a/lib/perf_hooks.js +++ b/lib/perf_hooks.js @@ -403,7 +403,7 @@ class Performance extends PerformanceObserverEntryList { this[kInsertEntry](nodeTiming); } - set maxBufferSize(val) { + set maxEntries(val) { if (typeof val !== 'number' || val >>> 0 !== val) { const errors = lazyErrors(); throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'val', 'number'); @@ -411,7 +411,7 @@ class Performance extends PerformanceObserverEntryList { this[kMaxCount] = Math.max(1, val >>> 0); } - get maxBufferSize() { + get maxEntries() { return this[kMaxCount]; } @@ -432,8 +432,8 @@ class Performance extends PerformanceObserverEntryList { `There ${text} in the ` + 'Performance Timeline. Use the clear methods ' + 'to remove entries that are no longer needed or ' + - 'set performance.maxBufferSize equal to a higher ' + - 'value (currently the maxBufferSize is ' + + 'set performance.maxEntries equal to a higher ' + + 'value (currently the maxEntries is ' + `${this[kMaxCount]}).`); } } diff --git a/test/parallel/test-performance-warning.js b/test/parallel/test-performance-warning.js index 908679d906df9e..f3104677a7c649 100644 --- a/test/parallel/test-performance-warning.js +++ b/test/parallel/test-performance-warning.js @@ -6,13 +6,13 @@ const { performance } = require('perf_hooks'); const assert = require('assert'); assert.strictEqual(performance.length, 1); -assert.strictEqual(performance.maxBufferSize, 150); +assert.strictEqual(performance.maxEntries, 150); -performance.maxBufferSize = 1; +performance.maxEntries = 1; [-1, 0xffffffff + 1, '', null, undefined, Infinity].forEach((i) => { common.expectsError( - () => performance.maxBufferSize = i, + () => performance.maxEntries = i, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError @@ -23,7 +23,7 @@ performance.maxBufferSize = 1; common.expectWarning('Warning', [ 'Possible perf_hooks memory leak detected. There are 2 entries in the ' + 'Performance Timeline. Use the clear methods to remove entries that are no ' + - 'longer needed or set performance.maxBufferSize equal to a higher value ' + - '(currently the maxBufferSize is 1).']); + 'longer needed or set performance.maxEntries equal to a higher value ' + + '(currently the maxEntries is 1).']); performance.mark('test'); From 75771f626acf25a3a21a069d2793990f840e2f13 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Wed, 24 Jan 2018 10:43:32 -0800 Subject: [PATCH 3/3] [Squash] Include default --- doc/api/perf_hooks.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/api/perf_hooks.md b/doc/api/perf_hooks.md index ca7fef8c205d11..62b035f6789921 100644 --- a/doc/api/perf_hooks.md +++ b/doc/api/perf_hooks.md @@ -137,6 +137,8 @@ Performance Timeline. This limit is not strictly enforced, but a process warning will be emitted if the number of entries in the timeline exceeds this limit. +Defaults to 150. + ### performance.measure(name, startMark, endMark)