Make disk cache inspection toggleable

Summary: Adds a toggle switch to show/hide disk cache images defaulting to inactive. The image data is only sent on the adb connection when the toggle is activated.

Reviewed By: defHLT

Differential Revision: D20002059

fbshipit-source-id: 05c9e515ffe09441e5cfb6f66eb14559ac4a322c
This commit is contained in:
Mathias Fleig Mortensen
2020-07-27 09:43:25 -07:00
committed by Facebook GitHub Bot
parent cfcb6837d1
commit e466bc4aed
5 changed files with 62 additions and 32 deletions

View File

@@ -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<DiskStorage.DiskDumpInfoEntry> 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(

View File

@@ -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",

View File

@@ -87,6 +87,8 @@ type ImagesCacheOverviewProps = {
events: Array<ImageEventWithId>;
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"
/>
<Toggle
toggled={this.props.showDiskImages}
onClick={this.props.onShowDiskImages}
label="Show Disk Images"
/>
<Spacer />
<input
type="range"

View File

@@ -59,6 +59,7 @@ function mockPersistedState(
closeableReferenceLeaks: [],
isLeakTrackingEnabled: false,
nextEventId: 0,
showDiskImages: false,
};
}
@@ -247,6 +248,7 @@ test('the metric reducer with the multiple events', () => {
imagesMap,
closeableReferenceLeaks: [],
isLeakTrackingEnabled: true,
showDiskImages: false,
};
const metricsReducer = FrescoPlugin.metricsReducer;
expect(metricsReducer).toBeDefined();

View File

@@ -45,6 +45,7 @@ export type PersistedState = {
imagesMap: ImagesMap;
closeableReferenceLeaks: Array<AndroidCloseableReferenceLeakEvent>;
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}
/>
<DetailSidebar>{this.renderSidebar()}</DetailSidebar>
</React.Fragment>