import com.android.internal.app.IUsageStats;
import com.android.internal.os.PkgUsageStats;
import com.android.internal.os.TransferPipe;
+import com.android.internal.util.FastPrintWriter;
import com.android.internal.util.MemInfoReader;
import android.content.ComponentName;
*/
public static void dumpPackageStateStatic(FileDescriptor fd, String packageName) {
FileOutputStream fout = new FileOutputStream(fd);
- PrintWriter pw = new PrintWriter(fout);
- dumpService(pw, fd, Context.ACTIVITY_SERVICE, new String[] { "package", packageName});
+ PrintWriter pw = new FastPrintWriter(fout);
+ dumpService(pw, fd, Context.ACTIVITY_SERVICE, new String[] { "package", packageName });
pw.println();
- dumpService(pw, fd, "package", new String[] { packageName});
+ dumpService(pw, fd, "procstats", new String[] { packageName });
pw.println();
- dumpService(pw, fd, BatteryStats.SERVICE_NAME, new String[] { packageName});
+ dumpService(pw, fd, "package", new String[] { packageName });
+ pw.println();
+ dumpService(pw, fd, BatteryStats.SERVICE_NAME, new String[] { packageName });
pw.flush();
}
import com.android.internal.os.BinderInternal;
import com.android.internal.os.RuntimeInit;
import com.android.internal.os.SamplingProfilerIntegration;
+import com.android.internal.util.FastPrintWriter;
import com.android.internal.util.Objects;
import com.android.org.conscrypt.OpenSSLSocketImpl;
public Debug.MemoryInfo dumpMemInfo(FileDescriptor fd, boolean checkin,
boolean dumpInfo, boolean dumpDalvik, String[] args) {
FileOutputStream fout = new FileOutputStream(fd);
- PrintWriter pw = new PrintWriter(fout);
+ PrintWriter pw = new FastPrintWriter(fout);
try {
return dumpMemInfo(pw, checkin, dumpInfo, dumpDalvik);
} finally {
@Override
public void dumpDbInfo(FileDescriptor fd, String[] args) {
- PrintWriter pw = new PrintWriter(new FileOutputStream(fd));
+ PrintWriter pw = new FastPrintWriter(new FileOutputStream(fd));
PrintWriterPrinter printer = new PrintWriterPrinter(pw);
SQLiteDebug.dump(printer, args);
pw.flush();
try {
Service s = mServices.get(info.token);
if (s != null) {
- PrintWriter pw = new PrintWriter(new FileOutputStream(info.fd.getFileDescriptor()));
+ PrintWriter pw = new FastPrintWriter(new FileOutputStream(
+ info.fd.getFileDescriptor()));
s.dump(info.fd.getFileDescriptor(), pw, info.args);
pw.flush();
}
try {
ActivityClientRecord r = mActivities.get(info.token);
if (r != null && r.activity != null) {
- PrintWriter pw = new PrintWriter(new FileOutputStream(info.fd.getFileDescriptor()));
+ PrintWriter pw = new FastPrintWriter(new FileOutputStream(
+ info.fd.getFileDescriptor()));
r.activity.dump(info.prefix, info.fd.getFileDescriptor(), pw, info.args);
pw.flush();
}
try {
ProviderClientRecord r = mLocalProviders.get(info.token);
if (r != null && r.mLocalProvider != null) {
- PrintWriter pw = new PrintWriter(new FileOutputStream(info.fd.getFileDescriptor()));
+ PrintWriter pw = new FastPrintWriter(new FileOutputStream(
+ info.fd.getFileDescriptor()));
r.mLocalProvider.dump(info.fd.getFileDescriptor(), pw, info.args);
pw.flush();
}
import android.os.SystemProperties;
import android.provider.Settings;
import android.util.Printer;
+import com.android.internal.util.FastPrintWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
*/
public CrashInfo(Throwable tr) {
StringWriter sw = new StringWriter();
- tr.printStackTrace(new PrintWriter(sw));
+ PrintWriter pw = new FastPrintWriter(sw, false, 256);
+ tr.printStackTrace(pw);
+ pw.flush();
stackTrace = sw.toString();
exceptionMessage = tr.getMessage();
import android.text.TextUtils;
import android.util.Log;
import android.util.LogWriter;
+import com.android.internal.util.FastPrintWriter;
import java.io.FileDescriptor;
import java.io.PrintWriter;
if (FragmentManagerImpl.DEBUG) {
Log.v(TAG, "Commit: " + this);
LogWriter logw = new LogWriter(Log.VERBOSE, TAG);
- PrintWriter pw = new PrintWriter(logw);
+ PrintWriter pw = new FastPrintWriter(logw, false, 1024);
dump(" ", null, pw, null);
+ pw.flush();
}
mCommitted = true;
if (mAddToBackStack) {
if (FragmentManagerImpl.DEBUG) {
Log.v(TAG, "popFromBackStack: " + this);
LogWriter logw = new LogWriter(Log.VERBOSE, TAG);
- PrintWriter pw = new PrintWriter(logw);
+ PrintWriter pw = new FastPrintWriter(logw, false, 1024);
dump(" ", null, pw, null);
+ pw.flush();
}
bumpBackStackNesting(-1);
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
+import com.android.internal.util.FastPrintWriter;
import java.io.FileDescriptor;
import java.io.PrintWriter;
private void throwException(RuntimeException ex) {
Log.e(TAG, ex.getMessage());
LogWriter logw = new LogWriter(Log.ERROR, TAG);
- PrintWriter pw = new PrintWriter(logw);
+ PrintWriter pw = new FastPrintWriter(logw, false, 1024);
if (mActivity != null) {
Log.e(TAG, "Activity state:");
try {
mActivity.dump(" ", null, pw, new String[] { });
} catch (Exception e) {
+ pw.flush();
Log.e(TAG, "Failed dumping state", e);
}
} else {
try {
dump(" ", null, pw, new String[] { });
} catch (Exception e) {
+ pw.flush();
Log.e(TAG, "Failed dumping state", e);
}
}
+ pw.flush();
throw ex;
}
Log.v(TAG, "restoreAllState: back stack #" + i
+ " (index " + bse.mIndex + "): " + bse);
LogWriter logw = new LogWriter(Log.VERBOSE, TAG);
- PrintWriter pw = new PrintWriter(logw);
+ PrintWriter pw = new FastPrintWriter(logw, false, 1024);
bse.dump(" ", pw, false);
+ pw.flush();
}
mBackStack.add(bse);
if (bse.mIndex >= 0) {
package android.os;
+import com.android.internal.util.FastPrintWriter;
import com.android.internal.util.TypedProperties;
import android.util.Log;
PrintWriter outStream = null;
try {
FileOutputStream fos = new FileOutputStream(SYSFS_QEMU_TRACE_STATE);
- outStream = new PrintWriter(new OutputStreamWriter(fos));
+ outStream = new FastPrintWriter(fos);
outStream.println("1");
} catch (Exception e) {
} finally {
PrintWriter outStream = null;
try {
FileOutputStream fos = new FileOutputStream(SYSFS_QEMU_TRACE_STATE);
- outStream = new PrintWriter(new OutputStreamWriter(fos));
+ outStream = new FastPrintWriter(fos);
outStream.println("0");
} catch (Exception e) {
// We could print an error message here but we probably want
import com.android.internal.os.RuntimeInit;
+import com.android.internal.util.FastPrintWriter;
import dalvik.system.BlockGuard;
import dalvik.system.CloseGuard;
import dalvik.system.VMDebug;
/* package */ static void readAndHandleBinderCallViolations(Parcel p) {
// Our own stack trace to append
StringWriter sw = new StringWriter();
- new LogStackTrace().printStackTrace(new PrintWriter(sw));
+ PrintWriter pw = new FastPrintWriter(sw, false, 256);
+ new LogStackTrace().printStackTrace(pw);
+ pw.flush();
String ourStack = sw.toString();
int policyMask = getThreadPolicyMask();
package android.util;
import com.android.internal.os.RuntimeInit;
+import com.android.internal.util.FastPrintWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
}
StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
+ PrintWriter pw = new FastPrintWriter(sw, false, 256);
tr.printStackTrace(pw);
+ pw.flush();
return sw.toString();
}
import android.util.ArraySet;
import android.util.Log;
import android.view.inputmethod.InputMethodManager;
+import com.android.internal.util.FastPrintWriter;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
public void dumpGfxInfo(FileDescriptor fd) {
FileOutputStream fout = new FileOutputStream(fd);
- PrintWriter pw = new PrintWriter(fout);
+ PrintWriter pw = new FastPrintWriter(fout);
try {
synchronized (mLock) {
final int count = mViews.size();
package com.android.internal.logging;
import android.util.Log;
+import com.android.internal.util.FastPrintWriter;
import dalvik.system.DalvikLogging;
import dalvik.system.DalvikLogHandler;
Throwable thrown = r.getThrown();
if (thrown != null) {
StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
+ PrintWriter pw = new FastPrintWriter(sw, false, 256);
sw.write(r.getMessage());
sw.write("\n");
thrown.printStackTrace(pw);
import com.android.internal.annotations.GuardedBy;
import com.android.internal.net.NetworkStatsFactory;
+import com.android.internal.util.FastPrintWriter;
import com.android.internal.util.JournaledFile;
import com.google.android.collect.Sets;
Slog.w(TAG, "New history ends before old history!");
} else if (!out.same(mHistoryReadTmp)) {
long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
- PrintWriter pw = new PrintWriter(new LogWriter(android.util.Log.WARN, TAG));
+ PrintWriter pw = new FastPrintWriter(new LogWriter(android.util.Log.WARN, TAG));
pw.println("Histories differ!");
pw.println("Old history:");
(new HistoryPrinter()).printNextItem(pw, out, now);
pw.println("New history:");
(new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, now);
+ pw.flush();
}
}
return true;
import android.os.StrictMode;
import android.os.SystemClock;
import android.util.Slog;
+import com.android.internal.util.FastPrintWriter;
import java.io.File;
import java.io.FileInputStream;
final public String printCurrentLoad() {
StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
+ 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();
}
buildWorkingProcs();
StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
+ PrintWriter pw = new FastPrintWriter(sw, false, 1024);
pw.print("CPU usage from ");
if (now > mLastSampleTime) {
printProcessCPU(pw, "", -1, "TOTAL", totalTime, mRelUserTime, mRelSystemTime,
mRelIoWaitTime, mRelIrqTime, mRelSoftIrqTime, 0, 0);
-
+
+ pw.flush();
return sw.toString();
}
if (handler.runWithScissors(new Runnable() {
@Override
public void run() {
- PrintWriter lpw = new PrintWriter(sw);
+ PrintWriter lpw = new FastPrintWriter(sw);
dump.dump(lpw);
lpw.close();
}
import java.nio.charset.CodingErrorAction;
public class FastPrintWriter extends PrintWriter {
- private static final int BUFFER_LEN = 8192;
-
private static Writer sDummyWriter = new Writer() {
@Override
public void close() throws IOException {
}
};
- private final char[] mText = new char[BUFFER_LEN];
+ private final int mBufferLen;
+ private final char[] mText;
private int mPos;
final private OutputStream mOutputStream;
- final private Writer mWriter;
final private boolean mAutoFlush;
final private String mSeparator;
+
+ final private Writer mWriter;
+
private CharsetEncoder mCharset;
- final private ByteBuffer mBytes = ByteBuffer.allocate(BUFFER_LEN);
+ final private ByteBuffer mBytes;
+
private boolean mIoError;
/**
* if {@code out} is {@code null}.
*/
public FastPrintWriter(OutputStream out) {
- super(sDummyWriter);
- mOutputStream = out;
- mWriter = null;
- mAutoFlush = false;
- mSeparator = System.lineSeparator();
- initDefaultEncoder();
+ this(out, false, 8192);
}
/**
* if {@code out} is {@code null}.
*/
public FastPrintWriter(OutputStream out, boolean autoFlush) {
+ this(out, autoFlush, 8192);
+ }
+
+ /**
+ * Constructs a new {@code PrintWriter} with {@code out} as its target
+ * stream and a custom buffer size. The parameter {@code autoFlush} determines
+ * if the print writer automatically flushes its contents to the target stream
+ * when a newline is encountered.
+ *
+ * @param out
+ * the target output stream.
+ * @param autoFlush
+ * indicates whether contents are flushed upon encountering a
+ * newline sequence.
+ * @param bufferLen
+ * specifies the size of the FastPrintWriter's internal buffer; the
+ * default is 8192.
+ * @throws NullPointerException
+ * if {@code out} is {@code null}.
+ */
+ public FastPrintWriter(OutputStream out, boolean autoFlush, int bufferLen) {
super(sDummyWriter, autoFlush);
+ if (out == null) {
+ throw new NullPointerException("out is null");
+ }
+ mBufferLen = bufferLen;
+ mText = new char[bufferLen];
+ mBytes = ByteBuffer.allocate(mBufferLen);
mOutputStream = out;
mWriter = null;
mAutoFlush = autoFlush;
* writer. By default, the new print writer does not automatically flush its
* contents to the target writer when a newline is encountered.
*
+ * <p>NOTE: Unlike PrintWriter, this version will still do buffering inside of
+ * FastPrintWriter before sending data to the Writer. This means you must call
+ * flush() before retrieving any data from the Writer.</p>
+ *
* @param wr
* the target writer.
* @throws NullPointerException
* if {@code wr} is {@code null}.
*/
public FastPrintWriter(Writer wr) {
- super(sDummyWriter);
- mOutputStream = null;
- mWriter = wr;
- mAutoFlush = false;
- mSeparator = System.lineSeparator();
- initDefaultEncoder();
+ this(wr, false, 8192);
}
/**
* if {@code out} is {@code null}.
*/
public FastPrintWriter(Writer wr, boolean autoFlush) {
+ this(wr, autoFlush, 8192);
+ }
+
+ /**
+ * Constructs a new {@code PrintWriter} with {@code out} as its target
+ * writer and a custom buffer size. The parameter {@code autoFlush} determines
+ * if the print writer automatically flushes its contents to the target writer
+ * when a newline is encountered.
+ *
+ * @param wr
+ * the target writer.
+ * @param autoFlush
+ * indicates whether to flush contents upon encountering a
+ * newline sequence.
+ * @param bufferLen
+ * specifies the size of the FastPrintWriter's internal buffer; the
+ * default is 8192.
+ * @throws NullPointerException
+ * if {@code wr} is {@code null}.
+ */
+ public FastPrintWriter(Writer wr, boolean autoFlush, int bufferLen) {
super(sDummyWriter, autoFlush);
+ if (wr == null) {
+ throw new NullPointerException("wr is null");
+ }
+ mBufferLen = bufferLen;
+ mText = new char[bufferLen];
+ mBytes = null;
mOutputStream = null;
mWriter = wr;
mAutoFlush = autoFlush;
private void appendLocked(char c) throws IOException {
int pos = mPos;
- if (pos >= (BUFFER_LEN-1)) {
+ if (pos >= (mBufferLen-1)) {
flushLocked();
pos = mPos;
}
}
private void appendLocked(String str, int i, final int length) throws IOException {
+ final int BUFFER_LEN = mBufferLen;
if (length > BUFFER_LEN) {
final int end = i + length;
while (i < end) {
}
private void appendLocked(char[] buf, int i, final int length) throws IOException {
+ final int BUFFER_LEN = mBufferLen;
if (length > BUFFER_LEN) {
final int end = i + length;
while (i < end) {
import com.android.internal.location.ILocationProvider;
import com.android.internal.location.ProviderProperties;
import com.android.internal.location.ProviderRequest;
+import com.android.internal.util.FastPrintWriter;
/**
* Base class for location providers implemented as unbundled services.
}
@Override
public void dump(FileDescriptor fd, String[] args) {
- PrintWriter pw = new PrintWriter(new FileOutputStream(fd));
+ PrintWriter pw = new FastPrintWriter(new FileOutputStream(fd));
onDump(fd, pw, args);
pw.flush();
}
package com.android.server;
+import android.os.BatteryStats;
import com.android.internal.app.IBatteryStats;
import com.android.server.am.BatteryStatsService;
private static final int DUMP_MAX_LENGTH = 24 * 1024;
private static final String[] DUMPSYS_ARGS = new String[] { "--checkin", "--unplugged" };
- private static final String BATTERY_STATS_SERVICE_NAME = "batteryinfo";
private static final String DUMPSYS_DATA_PATH = "/data/system/";
}
private void logBatteryStatsLocked() {
- IBinder batteryInfoService = ServiceManager.getService(BATTERY_STATS_SERVICE_NAME);
+ IBinder batteryInfoService = ServiceManager.getService(BatteryStats.SERVICE_NAME);
if (batteryInfoService == null) return;
DropBoxManager db = (DropBoxManager) mContext.getSystemService(Context.DROPBOX_SERVICE);
FileOutputStream dumpStream = null;
try {
// dump the service to a file
- dumpFile = new File(DUMPSYS_DATA_PATH + BATTERY_STATS_SERVICE_NAME + ".dump");
+ dumpFile = new File(DUMPSYS_DATA_PATH + BatteryStats.SERVICE_NAME + ".dump");
dumpStream = new FileOutputStream(dumpFile);
batteryInfoService.dump(dumpStream.getFD(), DUMPSYS_ARGS);
FileUtils.sync(dumpStream);
import com.android.internal.os.BatteryStatsImpl;
import com.android.internal.os.ProcessStats;
import com.android.internal.os.TransferPipe;
+import com.android.internal.util.FastPrintWriter;
import com.android.internal.util.FastXmlSerializer;
import com.android.server.AppOpsService;
import com.android.server.AttributeCache;
StringBuilder dropBuilder = new StringBuilder(1024);
StringBuilder logBuilder = new StringBuilder(1024);
StringWriter oomSw = new StringWriter();
- PrintWriter oomPw = new PrintWriter(oomSw);
+ PrintWriter oomPw = new FastPrintWriter(oomSw, false, 256);
StringWriter catSw = new StringWriter();
- PrintWriter catPw = new PrintWriter(catSw);
+ PrintWriter catPw = new FastPrintWriter(catSw, false, 256);
String[] emptyArgs = new String[] { };
StringBuilder tag = new StringBuilder(128);
StringBuilder stack = new StringBuilder(128);
dropBuilder.append(stack);
dropBuilder.append('\n');
dropBuilder.append('\n');
+ oomPw.flush();
String oomString = oomSw.toString();
dropBuilder.append(oomString);
dropBuilder.append('\n');
catPw.println();
dumpActivitiesLocked(null, catPw, emptyArgs, 0, false, false, null);
}
+ catPw.flush();
dropBuilder.append(catSw.toString());
addErrorToDropBox("lowmem", null, "system_server", null,
null, tag.toString(), dropBuilder.toString(), null, null);
import com.android.internal.app.ResolverActivity;
import com.android.internal.content.NativeLibraryHelper;
import com.android.internal.content.PackageHelper;
+import com.android.internal.util.FastPrintWriter;
import com.android.internal.util.FastXmlSerializer;
import com.android.internal.util.XmlUtils;
import com.android.server.DeviceStorageMonitorService;
try {
File fname = getSettingsProblemFile();
FileOutputStream out = new FileOutputStream(fname, true);
- PrintWriter pw = new PrintWriter(out);
+ PrintWriter pw = new FastPrintWriter(out);
SimpleDateFormat formatter = new SimpleDateFormat();
String dateString = formatter.format(new Date(System.currentTimeMillis()));
pw.println(dateString + ": " + msg);
import com.android.internal.app.IBatteryStats;
import com.android.internal.policy.PolicyManager;
import com.android.internal.policy.impl.PhoneWindowManager;
+import com.android.internal.util.FastPrintWriter;
import com.android.internal.view.IInputContext;
import com.android.internal.view.IInputMethodClient;
import com.android.internal.view.IInputMethodManager;
if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG, "******************** ENABLING SCREEN!");
if (false) {
StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
+ PrintWriter pw = new FastPrintWriter(sw, false, 1024);
this.dump(null, pw, null);
+ pw.flush();
Slog.i(TAG, sw.toString());
}
try {
WindowState ws = mRebuildTmp[i];
if (ws.mRebuilding) {
StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
+ PrintWriter pw = new FastPrintWriter(sw, false, 1024);
ws.dump(pw, "", true);
pw.flush();
Slog.w(TAG, "This window was lost: " + ws);
*/
public void saveANRStateLocked(AppWindowToken appWindowToken, WindowState windowState) {
StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
+ PrintWriter pw = new FastPrintWriter(sw, false, 1024);
pw.println(" ANR time: " + DateFormat.getInstance().format(new Date()));
if (appWindowToken != null) {
pw.println(" Application at fault: " + appWindowToken.stringName);