Merge "Reduce the memory usage of the ProtoLogToFile" into tm-qpr-dev
This commit is contained in:
@@ -72,11 +72,13 @@ public class BaseProtoLogImpl {
|
||||
private static final String TAG = "ProtoLog";
|
||||
private static final long MAGIC_NUMBER_VALUE = ((long) MAGIC_NUMBER_H << 32) | MAGIC_NUMBER_L;
|
||||
static final String PROTOLOG_VERSION = "1.0.0";
|
||||
private static final int DEFAULT_PER_CHUNK_SIZE = 0;
|
||||
|
||||
private final File mLogFile;
|
||||
private final String mViewerConfigFilename;
|
||||
private final TraceBuffer mBuffer;
|
||||
protected final ProtoLogViewerConfigReader mViewerConfig;
|
||||
private final int mPerChunkSize;
|
||||
|
||||
private boolean mProtoLogEnabled;
|
||||
private boolean mProtoLogEnabledLockFree;
|
||||
@@ -156,7 +158,7 @@ public class BaseProtoLogImpl {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
ProtoOutputStream os = new ProtoOutputStream();
|
||||
ProtoOutputStream os = new ProtoOutputStream(mPerChunkSize);
|
||||
long token = os.start(LOG);
|
||||
os.write(MESSAGE_HASH, messageHash);
|
||||
os.write(ELAPSED_REALTIME_NANOS, SystemClock.elapsedRealtimeNanos());
|
||||
@@ -215,10 +217,16 @@ public class BaseProtoLogImpl {
|
||||
|
||||
public BaseProtoLogImpl(File file, String viewerConfigFilename, int bufferCapacity,
|
||||
ProtoLogViewerConfigReader viewerConfig) {
|
||||
this(file, viewerConfigFilename, bufferCapacity, viewerConfig, DEFAULT_PER_CHUNK_SIZE);
|
||||
}
|
||||
|
||||
public BaseProtoLogImpl(File file, String viewerConfigFilename, int bufferCapacity,
|
||||
ProtoLogViewerConfigReader viewerConfig, int perChunkSize) {
|
||||
mLogFile = file;
|
||||
mBuffer = new TraceBuffer(bufferCapacity);
|
||||
mViewerConfigFilename = viewerConfigFilename;
|
||||
mViewerConfig = viewerConfig;
|
||||
mPerChunkSize = perChunkSize;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -364,7 +372,7 @@ public class BaseProtoLogImpl {
|
||||
try {
|
||||
long offset =
|
||||
(System.currentTimeMillis() - (SystemClock.elapsedRealtimeNanos() / 1000000));
|
||||
ProtoOutputStream proto = new ProtoOutputStream();
|
||||
ProtoOutputStream proto = new ProtoOutputStream(mPerChunkSize);
|
||||
proto.write(MAGIC_NUMBER, MAGIC_NUMBER_VALUE);
|
||||
proto.write(VERSION, PROTOLOG_VERSION);
|
||||
proto.write(REAL_TIME_TO_ELAPSED_TIME_OFFSET_MILLIS, offset);
|
||||
|
||||
@@ -30,6 +30,7 @@ public class ProtoLogImpl extends BaseProtoLogImpl {
|
||||
private static final int BUFFER_CAPACITY = 1024 * 1024;
|
||||
private static final String LOG_FILENAME = "/data/misc/wmtrace/wm_log.winscope";
|
||||
private static final String VIEWER_CONFIG_FILENAME = "/system/etc/protolog.conf.json.gz";
|
||||
private static final int PER_CHUNK_SIZE = 1024;
|
||||
|
||||
private static ProtoLogImpl sServiceInstance = null;
|
||||
|
||||
@@ -94,7 +95,10 @@ public class ProtoLogImpl extends BaseProtoLogImpl {
|
||||
public static synchronized ProtoLogImpl getSingleInstance() {
|
||||
if (sServiceInstance == null) {
|
||||
sServiceInstance = new ProtoLogImpl(
|
||||
new File(LOG_FILENAME), BUFFER_CAPACITY, new ProtoLogViewerConfigReader());
|
||||
new File(LOG_FILENAME)
|
||||
, BUFFER_CAPACITY
|
||||
, new ProtoLogViewerConfigReader()
|
||||
, PER_CHUNK_SIZE);
|
||||
}
|
||||
return sServiceInstance;
|
||||
}
|
||||
@@ -105,8 +109,8 @@ public class ProtoLogImpl extends BaseProtoLogImpl {
|
||||
}
|
||||
|
||||
public ProtoLogImpl(File logFile, int bufferCapacity,
|
||||
ProtoLogViewerConfigReader viewConfigReader) {
|
||||
super(logFile, VIEWER_CONFIG_FILENAME, bufferCapacity, viewConfigReader);
|
||||
}
|
||||
ProtoLogViewerConfigReader viewConfigReader, int perChunkSize) {
|
||||
super(logFile, VIEWER_CONFIG_FILENAME, bufferCapacity, viewConfigReader, perChunkSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ public class ProtoLogImplTest {
|
||||
mFile = testContext.getFileStreamPath("tracing_test.dat");
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
mFile.delete();
|
||||
mProtoLog = new ProtoLogImpl(mFile, 1024 * 1024, mReader);
|
||||
mProtoLog = new ProtoLogImpl(mFile, 1024 * 1024, mReader, 1024);
|
||||
}
|
||||
|
||||
@After
|
||||
|
||||
Reference in New Issue
Block a user