Search in sources :

Example 1 with DumpException

use of com.facebook.stetho.dumpapp.DumpException in project stetho by facebook.

the class HprofDumperPlugin method writeHprof.

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());
    }
}
Also used : DumpException(com.facebook.stetho.dumpapp.DumpException) IOException(java.io.IOException)

Example 2 with DumpException

use of com.facebook.stetho.dumpapp.DumpException in project stetho by facebook.

the class CrashDumperPlugin method doUncaughtException.

private void doUncaughtException(Iterator<String> argsIter) throws DumpException {
    String throwableClassString = ArgsHelper.nextOptionalArg(argsIter, OPTION_THROW_DEFAULT);
    try {
        Class<? extends Throwable> throwableClass = (Class<? extends Throwable>) Class.forName(throwableClassString);
        Throwable t;
        Constructor<? extends Throwable> ctorWithMessage = tryGetDeclaredConstructor(throwableClass, String.class);
        if (ctorWithMessage != null) {
            t = ctorWithMessage.newInstance("Uncaught exception triggered by Stetho");
        } else {
            Constructor<? extends Throwable> ctorParameterless = throwableClass.getDeclaredConstructor();
            t = ctorParameterless.newInstance();
        }
        Thread crashThread = new Thread(new ThrowRunnable(t));
        crashThread.start();
        Util.joinUninterruptibly(crashThread);
    } catch (ClassNotFoundException | ClassCastException | NoSuchMethodException | IllegalAccessException | InstantiationException e) {
        throw new DumpException("Invalid supplied Throwable class: " + e);
    } catch (InvocationTargetException e) {
        // reflect that as a normal unchecked exception in dumpapp output.
        throw ExceptionUtil.propagate(e.getCause());
    }
}
Also used : InvocationTargetException(java.lang.reflect.InvocationTargetException) DumpException(com.facebook.stetho.dumpapp.DumpException)

Example 3 with DumpException

use of com.facebook.stetho.dumpapp.DumpException in project stetho by facebook.

the class CrashDumperPlugin method doKill.

private void doKill(DumperContext dumpContext, Iterator<String> argsIter) throws DumpException {
    String signal = ArgsHelper.nextOptionalArg(argsIter, OPTION_KILL_DEFAULT);
    try {
        Process kill = new ProcessBuilder().command("/system/bin/kill", "-" + signal, String.valueOf(android.os.Process.myPid())).redirectErrorStream(true).start();
        // actually take out our process...
        try {
            InputStream in = kill.getInputStream();
            Util.copy(in, dumpContext.getStdout(), new byte[1024]);
        } finally {
            kill.destroy();
        }
    } catch (IOException e) {
        throw new DumpException("Failed to invoke kill: " + e);
    }
}
Also used : InputStream(java.io.InputStream) DumpException(com.facebook.stetho.dumpapp.DumpException) IOException(java.io.IOException)

Example 4 with DumpException

use of com.facebook.stetho.dumpapp.DumpException in project fresco by facebook.

the class BaseFrescoStethoPlugin method diskcache.

private void diskcache(FileCache cache, String title, PrintStream writer, List<String> args) throws DumpException {
    DiskStorage.DiskDumpInfo intDiskDumpInfo;
    try {
        intDiskDumpInfo = cache.getDumpInfo();
    } catch (IOException e) {
        throw new DumpException(e.getMessage());
    }
    if (!args.isEmpty() && args.get(0).equals("-s")) {
        writeDiskDumpInfoScriptReadable(writer, intDiskDumpInfo);
    } else {
        writer.println();
        writer.println(title + " disk cache contents:");
        writeDiskDumpInfo(writer, intDiskDumpInfo);
    }
}
Also used : DumpException(com.facebook.stetho.dumpapp.DumpException) IOException(java.io.IOException) DiskStorage(com.facebook.cache.disk.DiskStorage)

Example 5 with DumpException

use of com.facebook.stetho.dumpapp.DumpException in project fresco by facebook.

the class BaseFrescoStethoPlugin method getFiles.

private void getFiles(PrintStream writer, CountingMemoryCacheInspector.DumpInfo<CacheKey, CloseableImage> dumpInfo) throws DumpException, IOException {
    writer.println("\nStoring all images in the memory cache into /sdcard/imagedumperfiles/ ...");
    File dir = new File(Environment.getExternalStorageDirectory().getPath() + "/imagedumperfiles/");
    if (dir.exists() && dir.isDirectory()) {
        File[] files = dir.listFiles();
        if (files != null) {
            for (File file : files) {
                file.delete();
            }
        }
        if (!dir.delete()) {
            throw new DumpException("Failed to clear existing /sdcard/imagedumperfiles directory");
        }
    }
    if (!dir.mkdirs()) {
        throw new DumpException("Failed to create /sdcard/imagedumperfiles directory");
    }
    if (!dumpInfo.lruEntries.isEmpty()) {
        writer.println("LRU Entries:");
        storeEntries(dumpInfo.lruEntries, 1, writer, dir);
    }
    if (!dumpInfo.sharedEntries.isEmpty()) {
        writer.println("Shared Entries:");
        storeEntries(dumpInfo.sharedEntries, dumpInfo.lruEntries.size() + 1, writer, dir);
    }
    writer.println("Done!");
}
Also used : DumpException(com.facebook.stetho.dumpapp.DumpException) File(java.io.File)

Aggregations

DumpException (com.facebook.stetho.dumpapp.DumpException)6 IOException (java.io.IOException)4 CacheKey (com.facebook.cache.common.CacheKey)1 DiskStorage (com.facebook.cache.disk.DiskStorage)1 BitmapMemoryCacheKey (com.facebook.imagepipeline.cache.BitmapMemoryCacheKey)1 CountingMemoryCacheInspector (com.facebook.imagepipeline.cache.CountingMemoryCacheInspector)1 CloseableImage (com.facebook.imagepipeline.image.CloseableImage)1 File (java.io.File)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1