Search in sources :

Example 16 with FastPrintWriter

use of com.android.internal.util.FastPrintWriter in project android_frameworks_base by ResurrectionRemix.

the class TransactionTracker method writeTracesToFile.

public void writeTracesToFile(ParcelFileDescriptor fd) {
    if (mTraces.isEmpty()) {
        return;
    }
    PrintWriter pw = new FastPrintWriter(new FileOutputStream(fd.getFileDescriptor()));
    synchronized (this) {
        for (String trace : mTraces.keySet()) {
            pw.println("Count: " + mTraces.get(trace));
            pw.println("Trace: " + trace);
            pw.println();
        }
    }
    pw.flush();
}
Also used : FastPrintWriter(com.android.internal.util.FastPrintWriter) FileOutputStream(java.io.FileOutputStream) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

Example 17 with FastPrintWriter

use of com.android.internal.util.FastPrintWriter in project android_frameworks_base by ResurrectionRemix.

the class StrictMode method readAndHandleBinderCallViolations.

/**
     * Called from Parcel.readException() when the exception is EX_STRICT_MODE_VIOLATIONS,
     * we here read back all the encoded violations.
     */
/* package */
static void readAndHandleBinderCallViolations(Parcel p) {
    // Our own stack trace to append
    StringWriter sw = new StringWriter();
    sw.append("# via Binder call with stack:\n");
    PrintWriter pw = new FastPrintWriter(sw, false, 256);
    new LogStackTrace().printStackTrace(pw);
    pw.flush();
    String ourStack = sw.toString();
    final int policyMask = getThreadPolicyMask();
    final boolean currentlyGathering = (policyMask & PENALTY_GATHER) != 0;
    final int size = p.readInt();
    for (int i = 0; i < size; i++) {
        final ViolationInfo info = new ViolationInfo(p, !currentlyGathering);
        info.crashInfo.appendStackTrace(ourStack);
        BlockGuard.Policy policy = BlockGuard.getThreadPolicy();
        if (policy instanceof AndroidBlockGuardPolicy) {
            ((AndroidBlockGuardPolicy) policy).handleViolationWithTimingAttempt(info);
        }
    }
}
Also used : StringWriter(java.io.StringWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter) BlockGuard(dalvik.system.BlockGuard) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

Example 18 with FastPrintWriter

use of com.android.internal.util.FastPrintWriter in project android_frameworks_base by ResurrectionRemix.

the class BinderProxy method dumpAsync.

/**
     * Like {@link #dump(FileDescriptor, String[])}, but ensures the target
     * executes asynchronously.
     */
public void dumpAsync(final FileDescriptor fd, final String[] args) {
    final FileOutputStream fout = new FileOutputStream(fd);
    final PrintWriter pw = new FastPrintWriter(fout);
    Thread thr = new Thread("Binder.dumpAsync") {

        public void run() {
            try {
                dump(fd, pw, args);
            } finally {
                pw.flush();
            }
        }
    };
    thr.start();
}
Also used : FastPrintWriter(com.android.internal.util.FastPrintWriter) FileOutputStream(java.io.FileOutputStream) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

Example 19 with FastPrintWriter

use of com.android.internal.util.FastPrintWriter in project android_frameworks_base by ResurrectionRemix.

the class ProcessCpuTracker method printCurrentLoad.

public final String printCurrentLoad() {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new FastPrintWriter(sw, false, 128);
    pw.print("Load: ");
    pw.print(mLoad1);
    pw.print(" / ");
    pw.print(mLoad5);
    pw.print(" / ");
    pw.println(mLoad15);
    pw.flush();
    return sw.toString();
}
Also used : StringWriter(java.io.StringWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

Example 20 with FastPrintWriter

use of com.android.internal.util.FastPrintWriter in project android_frameworks_base by ResurrectionRemix.

the class ProcessCpuTracker method printCurrentState.

public final String printCurrentState(long now) {
    final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    buildWorkingProcs();
    StringWriter sw = new StringWriter();
    PrintWriter pw = new FastPrintWriter(sw, false, 1024);
    pw.print("CPU usage from ");
    if (now > mLastSampleTime) {
        pw.print(now - mLastSampleTime);
        pw.print("ms to ");
        pw.print(now - mCurrentSampleTime);
        pw.print("ms ago");
    } else {
        pw.print(mLastSampleTime - now);
        pw.print("ms to ");
        pw.print(mCurrentSampleTime - now);
        pw.print("ms later");
    }
    pw.print(" (");
    pw.print(sdf.format(new Date(mLastSampleWallTime)));
    pw.print(" to ");
    pw.print(sdf.format(new Date(mCurrentSampleWallTime)));
    pw.print(")");
    long sampleTime = mCurrentSampleTime - mLastSampleTime;
    long sampleRealTime = mCurrentSampleRealTime - mLastSampleRealTime;
    long percAwake = sampleRealTime > 0 ? ((sampleTime * 100) / sampleRealTime) : 0;
    if (percAwake != 100) {
        pw.print(" with ");
        pw.print(percAwake);
        pw.print("% awake");
    }
    pw.println(":");
    final int totalTime = mRelUserTime + mRelSystemTime + mRelIoWaitTime + mRelIrqTime + mRelSoftIrqTime + mRelIdleTime;
    if (DEBUG)
        Slog.i(TAG, "totalTime " + totalTime + " over sample time " + (mCurrentSampleTime - mLastSampleTime));
    int N = mWorkingProcs.size();
    for (int i = 0; i < N; i++) {
        Stats st = mWorkingProcs.get(i);
        printProcessCPU(pw, st.added ? " +" : (st.removed ? " -" : "  "), st.pid, st.name, (int) st.rel_uptime, st.rel_utime, st.rel_stime, 0, 0, 0, st.rel_minfaults, st.rel_majfaults);
        if (!st.removed && st.workingThreads != null) {
            int M = st.workingThreads.size();
            for (int j = 0; j < M; j++) {
                Stats tst = st.workingThreads.get(j);
                printProcessCPU(pw, tst.added ? "   +" : (tst.removed ? "   -" : "    "), tst.pid, tst.name, (int) st.rel_uptime, tst.rel_utime, tst.rel_stime, 0, 0, 0, 0, 0);
            }
        }
    }
    printProcessCPU(pw, "", -1, "TOTAL", totalTime, mRelUserTime, mRelSystemTime, mRelIoWaitTime, mRelIrqTime, mRelSoftIrqTime, 0, 0);
    pw.flush();
    return sw.toString();
}
Also used : StringWriter(java.io.StringWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

Aggregations

FastPrintWriter (com.android.internal.util.FastPrintWriter)128 PrintWriter (java.io.PrintWriter)122 FileOutputStream (java.io.FileOutputStream)61 StringWriter (java.io.StringWriter)34 LogWriter (android.util.LogWriter)24 StrictMode (android.os.StrictMode)17 IOException (java.io.IOException)16 FileNotFoundException (java.io.FileNotFoundException)12 Date (java.util.Date)10 HashMap (java.util.HashMap)8 Map (java.util.Map)8 Uri (android.net.Uri)7 Message (android.os.Message)7 ArrayMap (android.util.ArrayMap)7 PrintWriterPrinter (android.util.PrintWriterPrinter)7 SimpleDateFormat (java.text.SimpleDateFormat)7 NotFoundException (android.content.res.Resources.NotFoundException)5 Point (android.graphics.Point)5 LogPrinter (android.util.LogPrinter)5 Printer (android.util.Printer)5