/** @see ExcludedRefs */ public final T excludedRefs(ExcludedRefs excludedRefs) { heapDumpBuilder.excludedRefs(excludedRefs); return self(); }
/** @see Reachability.Inspector */ public final T stethoscopeClasses( List<Class<? extends Reachability.Inspector>> stethoscopeClasses) { heapDumpBuilder.reachabilityInspectorClasses(stethoscopeClasses); return self(); }
public HeapDump build() { checkNotNull(excludedRefs, "excludedRefs"); checkNotNull(heapDumpFile, "heapDumpFile"); checkNotNull(referenceKey, "referenceKey"); checkNotNull(reachabilityInspectorClasses, "reachabilityInspectorClasses"); return new HeapDump(this); } }
/** * In theory, this test doesn't have a 100% chance of success. In practice, {@link * GcTrigger#DEFAULT} is good enough. */ @Test public void unreachableObject_noDump() { TestDumper dumper = new TestDumper(); TestExecutor executor = new TestExecutor(); RefWatcher refWatcher = defaultWatcher(dumper, executor); refWatcher.watch(new Object()); executor.retryable.run(); assertFalse(dumper.called); }
/** * Identical to {@link #watch(Object, String)} with an empty string reference name. * * @see #watch(Object, String) */ public void watch(Object watchedReference) { watch(watchedReference, ""); }
private void detectLeaks() { if (skipLeakDetectionReason != null) { CanaryLog.d("Skipping leak detection because the test %s", skipLeakDetectionReason); skipLeakDetectionReason = null; return; } InstrumentationLeakDetector leakDetector = new InstrumentationLeakDetector(); InstrumentationLeakResults results = leakDetector.detectLeaks(); reportLeaks(results); }
/** Ignores all fields and static fields of all subclasses of the provided class name. */ @Override public BuilderWithParams clazz(String className) { checkNotNull(className, "className"); lastParams = new ParamsBuilder("any subclass of " + className); classNames.put(className, lastParams); return this; }
private RefWatcher defaultWatcher(TestDumper dumper, TestExecutor executor) { return new RefWatcherBuilder<>().watchExecutor(executor) .heapDumper(dumper) .heapDumpListener(new TestListener()) .build(); } }
KeyedWeakReference(Object referent, String key, String name, ReferenceQueue<Object> referenceQueue) { super(checkNotNull(referent, "referent"), checkNotNull(referenceQueue, "referenceQueue")); this.key = checkNotNull(key, "key"); this.name = checkNotNull(name, "name"); } }
ExcludedRefs(BuilderWithParams builder) { this.fieldNameByClassName = unmodifiableRefStringMap(builder.fieldNameByClassName); this.staticFieldNameByClassName = unmodifiableRefStringMap(builder.staticFieldNameByClassName); this.threadNames = unmodifiableRefMap(builder.threadNames); this.classNames = unmodifiableRefMap(builder.classNames); }
/** @see HeapDump.Listener */ public final T heapDumpListener(HeapDump.Listener heapDumpListener) { this.heapDumpListener = heapDumpListener; return self(); }
/** * Whether LeakCanary should compute the retained heap size when a leak is detected. False by * default, because computing the retained heap size takes a long time. */ public final T computeRetainedHeapSize(boolean computeRetainedHeapSize) { heapDumpBuilder.computeRetainedHeapSize(computeRetainedHeapSize); return self(); }
private void ensureGoneAsync(final long watchStartNanoTime, final KeyedWeakReference reference) { watchExecutor.execute(new Retryable() { @Override public Retryable.Result run() { return ensureGone(reference, watchStartNanoTime); } }); }
@Test public void retainedObject_triggersDump() { TestDumper dumper = new TestDumper(); TestExecutor executor = new TestExecutor(); RefWatcher refWatcher = defaultWatcher(dumper, executor); ref = new Object(); refWatcher.watch(ref); executor.retryable.run(); assertTrue(dumper.called); }
@Override public BuilderWithParams thread(String threadName) { checkNotNull(threadName, "threadName"); lastParams = new ParamsBuilder("any threads named " + threadName); threadNames.put(threadName, lastParams); return this; }
/** @see HeapDumper */ public final T heapDumper(HeapDumper heapDumper) { this.heapDumper = heapDumper; return self(); }
/** @see DebuggerControl */ public final T debuggerControl(DebuggerControl debuggerControl) { this.debuggerControl = debuggerControl; return self(); }
/** @see WatchExecutor */ public final T watchExecutor(WatchExecutor watchExecutor) { this.watchExecutor = watchExecutor; return self(); }
/** @see GcTrigger */ public final T gcTrigger(GcTrigger gcTrigger) { this.gcTrigger = gcTrigger; return self(); }