1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-25 09:17:58 +00:00

Simplification

This commit is contained in:
M66B 2022-04-18 09:06:25 +02:00
parent bbe7184a55
commit 3cc9856daf

View file

@ -40,65 +40,38 @@ public class CoalMine {
static void setup(boolean enabled) {
List<ObjectInspector> inspectors = new ArrayList<>(LeakCanary.getConfig().getObjectInspectors());
inspectors.add(new ObjectInspector() {
@Override
public void inspect(@NonNull ObjectReporter reporter) {
String clazz = SimpleTask.class.getName();
reporter.whenInstanceOf(clazz, new Function2<ObjectReporter, HeapObject.HeapInstance, Unit>() {
@Override
public Unit invoke(ObjectReporter reporter, HeapObject.HeapInstance instance) {
HeapField fname = instance.get(clazz, "name");
if (fname != null) {
String name = fname.getValue().readAsJavaString();
reporter.getNotLeakingReasons().add("name=" + name);
}
HeapField fstarted = instance.get(clazz, "started");
if (fstarted != null) {
Long started = fstarted.getValue().getAsLong();
if (started != null)
reporter.getNotLeakingReasons().add("started=" + new Date(started));
}
return null;
}
});
}
});
// https://square.github.io/leakcanary/recipes/#identifying-leaking-objects-and-labeling-objects
for (Class<?> clazz : new Class<?>[]{SimpleTask.class, TwoStateOwner.class, RunnableEx.class})
inspectors.add(new ObjectInspector() {
@Override
public void inspect(@NonNull ObjectReporter reporter) {
String className = clazz.getName();
reporter.whenInstanceOf(className, new Function2<ObjectReporter, HeapObject.HeapInstance, Unit>() {
@Override
public Unit invoke(ObjectReporter reporter, HeapObject.HeapInstance instance) {
HeapField hfName = instance.get(className, "name");
if (hfName != null) {
String label = hfName.getValue().readAsJavaString();
reporter.getLabels().add("name=" + label);
}
inspectors.add(new ObjectInspector() {
@Override
public void inspect(@NonNull ObjectReporter reporter) {
String clazz = TwoStateOwner.class.getName();
reporter.whenInstanceOf(clazz, new Function2<ObjectReporter, HeapObject.HeapInstance, Unit>() {
@Override
public Unit invoke(ObjectReporter reporter, HeapObject.HeapInstance instance) {
HeapField fname = instance.get(clazz, "name");
if (fname != null) {
String name = fname.getValue().readAsJavaString();
reporter.getNotLeakingReasons().add("name=" + name);
}
return null;
}
});
}
});
// Could be different class loader
if (className.equals(SimpleTask.class.getName())) {
HeapField hfStarted = instance.get(className, "started");
if (hfStarted != null) {
Long started = hfStarted.getValue().getAsLong();
if (started != null) {
String label = (started == 0 ? null : new Date(started).toString());
reporter.getLabels().add("started=" + label);
}
}
}
inspectors.add(new ObjectInspector() {
@Override
public void inspect(@NonNull ObjectReporter reporter) {
String clazz = RunnableEx.class.getName();
reporter.whenInstanceOf(clazz, new Function2<ObjectReporter, HeapObject.HeapInstance, Unit>() {
@Override
public Unit invoke(ObjectReporter reporter, HeapObject.HeapInstance instance) {
HeapField fname = instance.get(clazz, "name");
if (fname != null) {
String name = fname.getValue().readAsJavaString();
reporter.getNotLeakingReasons().add("name=" + name);
return null;
}
return null;
}
});
}
});
});
}
});
LeakCanary.Config config = LeakCanary.getConfig().newBuilder()
.dumpHeap(enabled && BuildConfig.DEBUG)