Add active leak tracking in Fresco

Summary:
Adds a "Track Leaks" option that will show notifications (even retroactively)
for `CloseableReferences` that were tracked.

Reviewed By: danielbuechele

Differential Revision: D15622596

fbshipit-source-id: ef610379aa96f9a5e541f741af608db30bee74e1
This commit is contained in:
Pascal Hartig
2019-06-05 11:31:40 -07:00
committed by Facebook Github Bot
parent bef1ff26bc
commit 1973432f78
3 changed files with 70 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ import FrescoPlugin from '../index.js';
import type {PersistedState, ImageEventWithId} from '../index.js';
import type {AndroidCloseableReferenceLeakEvent} from '../api.js';
import type {MetricType} from 'flipper';
import type {Notification} from '../../../plugin';
function mockPersistedState(
imageSizes: Array<{
@@ -52,6 +53,7 @@ function mockPersistedState(
events,
imagesMap,
closeableReferenceLeaks: [],
isLeakTrackingEnabled: false,
};
}
@@ -276,3 +278,36 @@ test('closeable reference metrics on input', () => {
const metrics = metricsReducer(persistedState);
expect(metrics).resolves.toMatchObject({CLOSEABLE_REFERENCE_LEAKS: 2});
});
test('notifications for leaks', () => {
const notificationReducer: (
persistedState: PersistedState,
) => Array<Notification> = (FrescoPlugin.getActiveNotifications: any);
const closeableReferenceLeaks: Array<AndroidCloseableReferenceLeakEvent> = [
{
identityHashCode: 'deadbeef',
className: 'com.facebook.imagepipeline.memory.NativeMemoryChunk',
},
{
identityHashCode: 'f4c3b00c',
className: 'com.facebook.flipper.SomeMemoryAbstraction',
},
];
const persistedStateWithoutTracking = {
...mockPersistedState(),
closeableReferenceLeaks,
isLeakTrackingEnabled: false,
};
const emptyNotifs = notificationReducer(persistedStateWithoutTracking);
expect(emptyNotifs).toHaveLength(0);
const persistedStateWithTracking = {
...mockPersistedState(),
closeableReferenceLeaks,
isLeakTrackingEnabled: true,
};
const notifs = notificationReducer(persistedStateWithTracking);
expect(notifs).toHaveLength(2);
expect(notifs[0].message).toContain('deadbeef');
expect(notifs[1].title).toContain('SomeMemoryAbstraction');
});