add memory debugging

This commit is contained in:
Scott Bell 2024-02-16 12:04:18 +01:00
parent bc36a93b9b
commit d053e65a39
2 changed files with 33 additions and 1 deletions

View File

@ -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);
}

View File

@ -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);