@Override public void dump(DumperContext dumpContext) throws DumpException { final PrintStream output = dumpContext.getStdout(); Iterator<String> argsIter = dumpContext.getArgsAsList().iterator(); String outputPath = argsIter.hasNext() ? argsIter.next() : null; if (outputPath == null) { usage(output); } else { if ("-".equals(outputPath)) { handlePipeOutput(output); } else { File outputFile = new File(outputPath); if (!outputFile.isAbsolute()) { outputFile = mContext.getFileStreamPath(outputPath); } writeHprof(outputFile); output.println("Wrote to " + outputFile); } } }
private void writeHprof(File outputPath) throws DumpException { try { // Test that we can write here. dumpHprofData appears to hang if it cannot write // to the target location on ART. truncateAndDeleteFile(outputPath); Debug.dumpHprofData(outputPath.getAbsolutePath()); } catch (IOException e) { throw new DumpException("Failure writing to " + outputPath + ": " + e.getMessage()); } }
private void handlePipeOutput(OutputStream output) throws DumpException { File hprofFile = mContext.getFileStreamPath("hprof-dump.hprof"); try { writeHprof(hprofFile); try { InputStream input = new FileInputStream(hprofFile); try { Util.copy(input, output, new byte[2048]); } finally { input.close(); } } catch (IOException e) { throw new DumpException("Failure copying " + hprofFile + " to dumper output"); } } finally { if (hprofFile.exists()) { hprofFile.delete(); } } }
public Iterable<DumperPlugin> finish() { provideIfDesired(new HprofDumperPlugin(mContext)); provideIfDesired(new SharedPreferencesDumperPlugin(mContext)); provideIfDesired(new CrashDumperPlugin()); provideIfDesired(new FilesDumperPlugin(mContext)); return mDelegate.finish(); } }