diff options
Diffstat (limited to 'lib/perf_hooks.js')
-rw-r--r-- | lib/perf_hooks.js | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/lib/perf_hooks.js b/lib/perf_hooks.js index 453fc54eb95..1bf635790e1 100644 --- a/lib/perf_hooks.js +++ b/lib/perf_hooks.js @@ -15,7 +15,8 @@ const { timeOriginTimestamp, timerify, constants, - setupGarbageCollectionTracking + installGarbageCollectionTracking, + removeGarbageCollectionTracking } = internalBinding('performance'); const { @@ -281,8 +282,6 @@ class PerformanceObserverEntryList { } } -let gcTrackingIsEnabled = false; - class PerformanceObserver extends AsyncResource { constructor(callback) { if (typeof callback !== 'function') { @@ -319,6 +318,7 @@ class PerformanceObserver extends AsyncResource { } disconnect() { + const observerCountsGC = observerCounts[NODE_PERFORMANCE_ENTRY_TYPE_GC]; const types = this[kTypes]; const keys = Object.keys(types); for (var n = 0; n < keys.length; n++) { @@ -329,6 +329,10 @@ class PerformanceObserver extends AsyncResource { } } this[kTypes] = {}; + if (observerCountsGC === 1 && + observerCounts[NODE_PERFORMANCE_ENTRY_TYPE_GC] === 0) { + removeGarbageCollectionTracking(); + } } observe(options) { @@ -342,12 +346,8 @@ class PerformanceObserver extends AsyncResource { if (entryTypes.length === 0) { throw new ERR_VALID_PERFORMANCE_ENTRY_TYPE(); } - if (entryTypes.includes(NODE_PERFORMANCE_ENTRY_TYPE_GC) && - !gcTrackingIsEnabled) { - setupGarbageCollectionTracking(); - gcTrackingIsEnabled = true; - } this.disconnect(); + const observerCountsGC = observerCounts[NODE_PERFORMANCE_ENTRY_TYPE_GC]; this[kBuffer][kEntries] = []; L.init(this[kBuffer][kEntries]); this[kBuffering] = Boolean(options.buffered); @@ -359,6 +359,10 @@ class PerformanceObserver extends AsyncResource { L.append(list, item); observerCounts[entryType]++; } + if (observerCountsGC === 0 && + observerCounts[NODE_PERFORMANCE_ENTRY_TYPE_GC] === 1) { + installGarbageCollectionTracking(); + } } } |