public HeapDump build() { checkNotNull(excludedRefs, "excludedRefs"); checkNotNull(heapDumpFile, "heapDumpFile"); checkNotNull(referenceKey, "referenceKey"); checkNotNull(reachabilityInspectorClasses, "reachabilityInspectorClasses"); return new HeapDump(this); } }
private HeapDump renameHeapdump(HeapDump heapDump) { String fileName = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss_SSS'.hprof'", Locale.US).format(new Date()); File newFile = new File(heapDump.heapDumpFile.getParent(), fileName); boolean renamed = heapDump.heapDumpFile.renameTo(newFile); if (!renamed) { CanaryLog.d("Could not rename heap dump file %s to %s", heapDump.heapDumpFile.getPath(), newFile.getPath()); } return heapDump.buildUpon().heapDumpFile(newFile).build(); }
HeapDump heapDump = HeapDump.builder() .heapDumpFile(heapDumpFile) .referenceKey(trackedReference.key)
@SuppressWarnings("ReferenceEquality") // Explicitly checking for named null. Retryable.Result ensureGone(final KeyedWeakReference reference, final long watchStartNanoTime) { long gcStartNanoTime = System.nanoTime(); long watchDurationMs = NANOSECONDS.toMillis(gcStartNanoTime - watchStartNanoTime); removeWeaklyReachableReferences(); if (debuggerControl.isDebuggerAttached()) { // The debugger can create false leaks. return RETRY; } if (gone(reference)) { return DONE; } gcTrigger.runGc(); removeWeaklyReachableReferences(); if (!gone(reference)) { long startDumpHeap = System.nanoTime(); long gcDurationMs = NANOSECONDS.toMillis(startDumpHeap - gcStartNanoTime); File heapDumpFile = heapDumper.dumpHeap(); if (heapDumpFile == RETRY_LATER) { // Could not dump the heap. return RETRY; } long heapDumpDurationMs = NANOSECONDS.toMillis(System.nanoTime() - startDumpHeap); heapdumpListener.analyze( new HeapDump(heapDumpFile, reference.key, reference.name, excludedRefs, watchDurationMs, gcDurationMs, heapDumpDurationMs)); } return DONE; }