diff --git a/android/plugins/fresco/src/main/java/com/facebook/flipper/plugins/fresco/FrescoFlipperPlugin.java b/android/plugins/fresco/src/main/java/com/facebook/flipper/plugins/fresco/FrescoFlipperPlugin.java index ac156b6ac..d61b79634 100644 --- a/android/plugins/fresco/src/main/java/com/facebook/flipper/plugins/fresco/FrescoFlipperPlugin.java +++ b/android/plugins/fresco/src/main/java/com/facebook/flipper/plugins/fresco/FrescoFlipperPlugin.java @@ -169,6 +169,7 @@ public class FrescoFlipperPlugin extends BufferingFlipperPlugin } mPerfLogger.startMarker("Sonar.Fresco.listImages"); + final boolean showDiskImages = params.getBoolean("showDiskImages"); final ImagePipelineFactory imagePipelineFactory = Fresco.getImagePipelineFactory(); final CountingMemoryCacheInspector.DumpInfo bitmapMemoryCache = @@ -182,10 +183,7 @@ public class FrescoFlipperPlugin extends BufferingFlipperPlugin try { responder.success( - getImageList( - bitmapMemoryCache, - encodedMemoryCache, - imagePipelineFactory.getMainFileCache().getDumpInfo().entries)); + getImageList(bitmapMemoryCache, encodedMemoryCache, showDiskImages)); mPerfLogger.endMarker("Sonar.Fresco.listImages"); } finally { bitmapMemoryCache.release(); @@ -406,21 +404,24 @@ public class FrescoFlipperPlugin extends BufferingFlipperPlugin private FlipperObject getImageList( final CountingMemoryCacheInspector.DumpInfo bitmapMemoryCache, final CountingMemoryCacheInspector.DumpInfo encodedMemoryCache, - final List diskEntries) { - return new FlipperObject.Builder() - .put( - "levels", - new FlipperArray.Builder() - // bitmap - .put(getUsedStats("On screen bitmaps", bitmapMemoryCache)) - .put(getCachedStats("Bitmap memory cache", bitmapMemoryCache)) - // encoded - .put(getUsedStats("Used encoded images", encodedMemoryCache)) - .put(getCachedStats("Cached encoded images", encodedMemoryCache)) - // disk - .put(getDiskStats("Disk images", diskEntries)) - .build()) - .build(); + final boolean showDiskImages) + throws IOException { + FlipperArray.Builder levelsBuilder = + new FlipperArray.Builder() + // bitmap + .put(getUsedStats("On screen bitmaps", bitmapMemoryCache)) + .put(getCachedStats("Bitmap memory cache", bitmapMemoryCache)) + // encoded + .put(getUsedStats("Used encoded images", encodedMemoryCache)) + .put(getCachedStats("Cached encoded images", encodedMemoryCache)); + if (showDiskImages) { + levelsBuilder.put( + getDiskStats( + "Disk images", + Fresco.getImagePipelineFactory().getMainFileCache().getDumpInfo().entries)); + } + + return new FlipperObject.Builder().put("levels", levelsBuilder.build()).build(); } private FlipperObject getUsedStats( diff --git a/desktop/package.json b/desktop/package.json index 579b1c352..36fcff2d2 100644 --- a/desktop/package.json +++ b/desktop/package.json @@ -109,8 +109,8 @@ "devDependencies": { "@babel/code-frame": "^7.10.4", "@jest-runner/electron": "^3.0.0", - "@testing-library/react": "^10.4.3", "@testing-library/dom": "^7.20.2", + "@testing-library/react": "^10.4.3", "@types/algoliasearch": "^3.30.19", "@types/babel__code-frame": "^7.0.0", "@types/babel__core": "^7.1.6", diff --git a/desktop/plugins/fresco/ImagesCacheOverview.tsx b/desktop/plugins/fresco/ImagesCacheOverview.tsx index ac327789a..7785ddaf0 100644 --- a/desktop/plugins/fresco/ImagesCacheOverview.tsx +++ b/desktop/plugins/fresco/ImagesCacheOverview.tsx @@ -87,6 +87,8 @@ type ImagesCacheOverviewProps = { events: Array; onTrackLeaks: (enabled: boolean) => void; isLeakTrackingEnabled: boolean; + onShowDiskImages: (enabled: boolean) => void; + showDiskImages: boolean; }; type ImagesCacheOverviewState = { @@ -231,6 +233,11 @@ export default class ImagesCacheOverview extends PureComponent< onClick={this.props.onTrackLeaks} label="Track Leaks" /> + { imagesMap, closeableReferenceLeaks: [], isLeakTrackingEnabled: true, + showDiskImages: false, }; const metricsReducer = FrescoPlugin.metricsReducer; expect(metricsReducer).toBeDefined(); diff --git a/desktop/plugins/fresco/index.tsx b/desktop/plugins/fresco/index.tsx index ba1a36107..d0a84d82a 100644 --- a/desktop/plugins/fresco/index.tsx +++ b/desktop/plugins/fresco/index.tsx @@ -45,6 +45,7 @@ export type PersistedState = { imagesMap: ImagesMap; closeableReferenceLeaks: Array; isLeakTrackingEnabled: boolean; + showDiskImages: boolean; nextEventId: number; }; @@ -96,6 +97,7 @@ export default class FlipperImagesPlugin extends FlipperPlugin< surfaceList: new Set(), closeableReferenceLeaks: [], isLeakTrackingEnabled: false, + showDiskImages: false, nextEventId: 0, }; @@ -112,7 +114,7 @@ export default class FlipperImagesPlugin extends FlipperPlugin< return defaultPromise; } return Promise.all([ - callClient('listImages'), + callClient('listImages', {showDiskImages: persistedState.showDiskImages}), callClient('getAllImageEventsInfo'), ]).then(async ([responseImages, responseEvents]) => { const levels: ImagesList = responseImages.levels; @@ -360,17 +362,23 @@ export default class FlipperImagesPlugin extends FlipperPlugin< }; updateCaches = (reason: string) => { debugLog('Requesting images list (reason=' + reason + ')'); - this.client.call('listImages').then((response: ImagesListResponse) => { - response.levels.forEach((data) => - this.imagePool ? this.imagePool.fetchImages(data.imageIds) : undefined, - ); - this.props.setPersistedState({images: response.levels}); - this.updateImagesOnUI( - this.props.persistedState.images, - this.state.selectedSurfaces, - this.state.coldStartFilter, - ); - }); + this.client + .call('listImages', { + showDiskImages: this.props.persistedState.showDiskImages, + }) + .then((response: ImagesListResponse) => { + response.levels.forEach((data) => + this.imagePool + ? this.imagePool.fetchImages(data.imageIds) + : undefined, + ); + this.props.setPersistedState({images: response.levels}); + this.updateImagesOnUI( + this.props.persistedState.images, + this.state.selectedSurfaces, + this.state.coldStartFilter, + ); + }); }; onClear = (type: string) => { @@ -455,6 +463,16 @@ export default class FlipperImagesPlugin extends FlipperPlugin< }); }; + onShowDiskImages = (checked: boolean) => { + this.props.logger.track('usage', 'fresco:onShowDiskImages', { + enabled: checked, + }); + this.props.setPersistedState({ + showDiskImages: checked, + }); + this.updateCaches('refresh'); + }; + render() { const options = [...this.props.persistedState.surfaceList].reduce( (acc, item) => { @@ -492,6 +510,8 @@ export default class FlipperImagesPlugin extends FlipperPlugin< this.props.persistedState.isLeakTrackingEnabled } onTrackLeaks={this.onTrackLeaks} + showDiskImages={this.props.persistedState.showDiskImages} + onShowDiskImages={this.onShowDiskImages} /> {this.renderSidebar()}