Hook up stacktraces to leak notification
Summary: Transfer it from the device, reformat the notification to make use of it. Reviewed By: danielbuechele Differential Revision: D15779267 fbshipit-source-id: 747dc7f895528618ff6a07c15b7f72bf6a1adde9
This commit is contained in:
committed by
Facebook Github Bot
parent
6168b3c604
commit
71575ce7cf
@@ -39,6 +39,8 @@ import com.facebook.imagepipeline.image.CloseableBitmap;
|
||||
import com.facebook.imagepipeline.image.CloseableImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -521,6 +523,16 @@ public class FrescoFlipperPlugin extends BufferingFlipperPlugin
|
||||
new FlipperObject.Builder()
|
||||
.put("identityHashCode", System.identityHashCode(reference))
|
||||
.put("className", reference.get().getClass().getName());
|
||||
if (stacktrace != null) {
|
||||
builder.put("stacktrace", getStackTraceString(stacktrace));
|
||||
}
|
||||
send(FRESCO_CLOSEABLE_REFERENCE_LEAK_EVENT, builder.build());
|
||||
}
|
||||
|
||||
public static String getStackTraceString(Throwable tr) {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
tr.printStackTrace(pw);
|
||||
return sw.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,10 +265,12 @@ test('closeable reference metrics on input', () => {
|
||||
{
|
||||
identityHashCode: 'deadbeef',
|
||||
className: 'com.facebook.imagepipeline.memory.NativeMemoryChunk',
|
||||
stacktrace: null,
|
||||
},
|
||||
{
|
||||
identityHashCode: 'f4c3b00c',
|
||||
className: 'com.facebook.flipper.SomeMemoryAbstraction',
|
||||
stacktrace: null,
|
||||
},
|
||||
];
|
||||
const persistedState = {
|
||||
@@ -287,10 +289,12 @@ test('notifications for leaks', () => {
|
||||
{
|
||||
identityHashCode: 'deadbeef',
|
||||
className: 'com.facebook.imagepipeline.memory.NativeMemoryChunk',
|
||||
stacktrace: null,
|
||||
},
|
||||
{
|
||||
identityHashCode: 'f4c3b00c',
|
||||
className: 'com.facebook.flipper.SomeMemoryAbstraction',
|
||||
stacktrace: null,
|
||||
},
|
||||
];
|
||||
const persistedStateWithoutTracking = {
|
||||
@@ -308,6 +312,6 @@ test('notifications for leaks', () => {
|
||||
};
|
||||
const notifs = notificationReducer(persistedStateWithTracking);
|
||||
expect(notifs).toHaveLength(2);
|
||||
expect(notifs[0].message).toContain('deadbeef');
|
||||
expect(notifs[0].message).toMatchSnapshot();
|
||||
expect(notifs[1].title).toContain('SomeMemoryAbstraction');
|
||||
});
|
||||
|
||||
@@ -71,4 +71,5 @@ export type FrescoDebugOverlayEvent = {|
|
||||
export type AndroidCloseableReferenceLeakEvent = {|
|
||||
identityHashCode: string,
|
||||
className: string,
|
||||
stacktrace: ?string,
|
||||
|};
|
||||
|
||||
@@ -15,6 +15,7 @@ import type {
|
||||
AndroidCloseableReferenceLeakEvent,
|
||||
CacheInfo,
|
||||
} from './api.js';
|
||||
import {Fragment} from 'react';
|
||||
import type {ImagesMap} from './ImagePool.js';
|
||||
import type {MetricType, MiddlewareAPI} from 'flipper';
|
||||
import React from 'react';
|
||||
@@ -60,6 +61,10 @@ const EmptySidebar = styled(FlexRow)({
|
||||
fontSize: 16,
|
||||
});
|
||||
|
||||
export const InlineFlexRow = styled(FlexRow)({
|
||||
display: 'inline-block',
|
||||
});
|
||||
|
||||
const surfaceDefaultText = 'SELECT ALL SURFACES';
|
||||
|
||||
const debugLog = (...args) => {
|
||||
@@ -196,8 +201,21 @@ export default class extends FlipperPlugin<PluginState, *, PersistedState> {
|
||||
.map((event: AndroidCloseableReferenceLeakEvent, index) => ({
|
||||
id: event.identityHashCode,
|
||||
title: `Leaked CloseableReference: ${event.className}`,
|
||||
message: `CloseableReference leaked for ${event.className}
|
||||
(identity hashcode: ${event.identityHashCode})`,
|
||||
message: (
|
||||
<Fragment>
|
||||
<InlineFlexRow>
|
||||
CloseableReference leaked for{' '}
|
||||
<Text code={true}>{event.className}</Text>
|
||||
(identity hashcode: {event.identityHashCode}).
|
||||
</InlineFlexRow>
|
||||
<InlineFlexRow>
|
||||
<Text bold={true}>Stacktrace:</Text>
|
||||
</InlineFlexRow>
|
||||
<InlineFlexRow>
|
||||
<Text code={true}>{event.stacktrace || '<unavailable>'}</Text>
|
||||
</InlineFlexRow>
|
||||
</Fragment>
|
||||
),
|
||||
severity: 'error',
|
||||
category: 'closeablereference_leak',
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user