From d053e65a39ca1f908e2231e4cb4d4e580dc501d6 Mon Sep 17 00:00:00 2001 From: Scott Bell Date: Fri, 16 Feb 2024 12:04:18 +0100 Subject: [PATCH] add memory debugging --- src/api/telemetry/TelemetryAPI.js | 20 +++++++++++++++++++- src/plugins/plot/configuration/PlotSeries.js | 14 ++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/api/telemetry/TelemetryAPI.js b/src/api/telemetry/TelemetryAPI.js index e6aa50bda6..0d34fb7b2d 100644 --- a/src/api/telemetry/TelemetryAPI.js +++ b/src/api/telemetry/TelemetryAPI.js @@ -108,6 +108,15 @@ export default class TelemetryAPI { this.#isGreedyLAD = true; this.BatchingWebSocket = BatchingWebSocket; this.#subscribeCache = {}; + this.itemsGarbageCollected = 0; + + // eslint-disable-next-line no-undef + this.registry = new FinalizationRegistry((heldValue) => { + this.itemsGarbageCollected++; + console.debug( + `🗑️ 🛜 TELEMETRY API garbage collected: ${this.itemsGarbageCollected} - ${JSON.stringify(heldValue)}` + ); + }); } abortAllRequests() { @@ -383,6 +392,10 @@ export default class TelemetryAPI { arguments[1] = await this.applyRequestInterceptors(domainObject, arguments[1]); try { const telemetry = await provider.request(...arguments); + // add each piece of data individually to be registry + telemetry.forEach((datum) => { + this.registry.register(datum, `${new Date()} Data with: ${JSON.stringify(datum)}`); + }); return telemetry; } catch (error) { @@ -462,9 +475,14 @@ export default class TelemetryAPI { } else { subscriber.latestCallbacks.push(callback); } - + const telemetryAPI = this; // Guarantees that view receive telemetry in the expected form function invokeCallbackWithRequestedStrategy(data) { + // add each piece of data individually to be registry + data.forEach((datum) => { + const heldValue = `${new Date()} Data with: ${JSON.stringify(datum)}`; + telemetryAPI.registry.register(datum, heldValue); + }); invokeCallbacksWithArray(data, subscriber.batchCallbacks); invokeCallbacksWithSingleValue(data, subscriber.latestCallbacks); } diff --git a/src/plugins/plot/configuration/PlotSeries.js b/src/plugins/plot/configuration/PlotSeries.js index fdc26d277e..7d625fc0a0 100644 --- a/src/plugins/plot/configuration/PlotSeries.js +++ b/src/plugins/plot/configuration/PlotSeries.js @@ -87,6 +87,15 @@ export default class PlotSeries extends Model { this.onYKeyChange(this.get('yKey')); this.unPlottableValues = [undefined, Infinity, -Infinity]; + this.itemsGarbageCollected = 0; + + // eslint-disable-next-line no-undef + this.registry = new FinalizationRegistry((heldValue) => { + this.itemsGarbageCollected++; + console.debug( + `🗑️ 📈 PLOT garbage collected: ${this.itemsGarbageCollected} - ${JSON.stringify(heldValue)}` + ); + }); } getLogMode(options) { @@ -225,6 +234,7 @@ export default class PlotSeries extends Model { try { const points = await this.openmct.telemetry.request(this.domainObject, options); + const data = this.getSeriesData(); // eslint-disable-next-line you-dont-need-lodash-underscore/concat const newPoints = _(data) @@ -232,6 +242,7 @@ export default class PlotSeries extends Model { .sortBy(this.getXVal) .uniq(true, (point) => [this.getXVal(point), this.getYVal(point)].join()) .value(); + this.reset(newPoints); } catch (error) { console.warn('Error fetching data', error); @@ -426,6 +437,9 @@ export default class PlotSeries extends Model { * a point to the end without dupe checking. */ add(newData, sorted = false) { + const heldValue = `${new Date()} Data with ${JSON.stringify(newData)}`; + this.registry.register(newData, heldValue); + let data = this.getSeriesData(); let insertIndex = data.length; const currentYVal = this.getYVal(newData);