@Override public File dumpHeap() { if (!isExternalStorageWritable()) { Log.d(TAG, "Could not dump heap, external storage not mounted."); } File heapDumpFile = getHeapDumpFile(); if (heapDumpFile.exists()) { Log.d(TAG, "Could not dump heap, previous analysis still is in progress."); // Heap analysis in progress, let's not put too much pressure on the device. return null; } try { Debug.dumpHprofData(heapDumpFile.getAbsolutePath()); return heapDumpFile; } catch (IOException e) { cleanup(); Log.e(TAG, "Could not perform heap dump", e); // Abort heap dump return null; } }
/** * Creates a {@link RefWatcher} with a default configuration suitable for Android. */ public static RefWatcher androidWatcher(HeapDump.Listener heapDumpListener, ExcludedRefs excludedRefs) { DebuggerControl debuggerControl = new AndroidDebuggerControl(); AndroidHeapDumper heapDumper = new AndroidHeapDumper(); heapDumper.cleanup(); return new RefWatcher(new AndroidWatchExecutor(), debuggerControl, GcTrigger.DEFAULT, heapDumper, heapDumpListener, excludedRefs); }