Fields Summary |
---|
public static final String | METRIC_KEY_ITERATIONSIn a results Bundle, this key references a List of iteration Bundles. |
public static final String | METRIC_KEY_LABELIn an iteration Bundle, this key describes the iteration. |
public static final String | METRIC_KEY_CPU_TIMEIn a results Bundle, this key reports the cpu time of the code block
under measurement. |
public static final String | METRIC_KEY_EXECUTION_TIMEIn a results Bundle, this key reports the execution time of the code
block under measurement. |
public static final String | METRIC_KEY_PRE_RECEIVED_TRANSACTIONSIn a snapshot Bundle, this key reports the number of received
transactions from the binder driver before collection started. |
public static final String | METRIC_KEY_PRE_SENT_TRANSACTIONSIn a snapshot Bundle, this key reports the number of transactions sent by
the running program before collection started. |
public static final String | METRIC_KEY_RECEIVED_TRANSACTIONSIn a snapshot Bundle, this key reports the number of received
transactions from the binder driver. |
public static final String | METRIC_KEY_SENT_TRANSACTIONSIn a snapshot Bundle, this key reports the number of transactions sent by
the running program. |
public static final String | METRIC_KEY_GC_INVOCATION_COUNTIn a snapshot Bundle, this key reports the number of garbage collection
invocations. |
public static final String | METRIC_KEY_JAVA_ALLOCATEDIn a snapshot Bundle, this key reports the amount of allocated memory
used by the running program. |
public static final String | METRIC_KEY_JAVA_FREEIn a snapshot Bundle, this key reports the amount of free memory
available to the running program. |
public static final String | METRIC_KEY_JAVA_PRIVATE_DIRTYIn a snapshot Bundle, this key reports the number of private dirty pages
used by dalvik. |
public static final String | METRIC_KEY_JAVA_PSSIn a snapshot Bundle, this key reports the proportional set size for
dalvik. |
public static final String | METRIC_KEY_JAVA_SHARED_DIRTYIn a snapshot Bundle, this key reports the number of shared dirty pages
used by dalvik. |
public static final String | METRIC_KEY_JAVA_SIZEIn a snapshot Bundle, this key reports the total amount of memory
available to the running program. |
public static final String | METRIC_KEY_NATIVE_ALLOCATEDIn a snapshot Bundle, this key reports the amount of allocated memory in
the native heap. |
public static final String | METRIC_KEY_NATIVE_FREEIn a snapshot Bundle, this key reports the amount of free memory in the
native heap. |
public static final String | METRIC_KEY_NATIVE_PRIVATE_DIRTYIn a snapshot Bundle, this key reports the number of private dirty pages
used by the native heap. |
public static final String | METRIC_KEY_NATIVE_PSSIn a snapshot Bundle, this key reports the proportional set size for the
native heap. |
public static final String | METRIC_KEY_NATIVE_SHARED_DIRTYIn a snapshot Bundle, this key reports the number of shared dirty pages
used by the native heap. |
public static final String | METRIC_KEY_NATIVE_SIZEIn a snapshot Bundle, this key reports the size of the native heap. |
public static final String | METRIC_KEY_GLOBAL_ALLOC_COUNTIn a snapshot Bundle, this key reports the number of objects allocated
globally. |
public static final String | METRIC_KEY_GLOBAL_ALLOC_SIZEIn a snapshot Bundle, this key reports the size of all objects allocated
globally. |
public static final String | METRIC_KEY_GLOBAL_FREED_COUNTIn a snapshot Bundle, this key reports the number of objects freed
globally. |
public static final String | METRIC_KEY_GLOBAL_FREED_SIZEIn a snapshot Bundle, this key reports the size of all objects freed
globally. |
public static final String | METRIC_KEY_OTHER_PRIVATE_DIRTYIn a snapshot Bundle, this key reports the number of private dirty pages
used by everything else. |
public static final String | METRIC_KEY_OTHER_PSSIn a snapshot Bundle, this key reports the proportional set size for
everything else. |
public static final String | METRIC_KEY_OTHER_SHARED_DIRTYIn a snapshot Bundle, this key reports the number of shared dirty pages
used by everything else. |
private PerformanceResultsWriter | mPerfWriter |
private Bundle | mPerfSnapshot |
private Bundle | mPerfMeasurement |
private long | mSnapshotCpuTime |
private long | mSnapshotExecTime |
private long | mCpuTime |
private long | mExecTime |
Methods Summary |
---|
public Bundle | addIteration(java.lang.String label)Add a measured segment, and start measuring the next segment. Returns
collected data in a Bundle object.
mCpuTime = Process.getElapsedCpuTime() - mCpuTime;
mExecTime = SystemClock.uptimeMillis() - mExecTime;
Bundle iteration = new Bundle();
iteration.putString(METRIC_KEY_LABEL, label);
iteration.putLong(METRIC_KEY_EXECUTION_TIME, mExecTime);
iteration.putLong(METRIC_KEY_CPU_TIME, mCpuTime);
mPerfMeasurement.getParcelableArrayList(METRIC_KEY_ITERATIONS).add(iteration);
mExecTime = SystemClock.uptimeMillis();
mCpuTime = Process.getElapsedCpuTime();
return iteration;
|
public void | addMeasurement(java.lang.String label, float value)Add a float type measurement to the collector.
if (mPerfWriter != null)
mPerfWriter.writeMeasurement(label, value);
|
public void | addMeasurement(java.lang.String label, java.lang.String value)Add a string field to the collector.
if (mPerfWriter != null)
mPerfWriter.writeMeasurement(label, value);
|
public void | addMeasurement(java.lang.String label, long value)Add an integer type measurement to the collector.
if (mPerfWriter != null)
mPerfWriter.writeMeasurement(label, value);
|
public void | beginSnapshot(java.lang.String label)Begin collection of memory usage information.
if (mPerfWriter != null)
mPerfWriter.writeBeginSnapshot(label);
startPerformanceSnapshot();
|
private void | endPerformanceSnapshot()
// Stop the timing. This must be done first before any other counting is
// stopped.
mSnapshotCpuTime = Process.getElapsedCpuTime() - mSnapshotCpuTime;
mSnapshotExecTime = SystemClock.uptimeMillis() - mSnapshotExecTime;
stopAllocCounting();
long nativeMax = Debug.getNativeHeapSize() / 1024;
long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024;
long nativeFree = Debug.getNativeHeapFreeSize() / 1024;
Debug.MemoryInfo memInfo = new Debug.MemoryInfo();
Debug.getMemoryInfo(memInfo);
Runtime runtime = Runtime.getRuntime();
long dalvikMax = runtime.totalMemory() / 1024;
long dalvikFree = runtime.freeMemory() / 1024;
long dalvikAllocated = dalvikMax - dalvikFree;
// Add final binder counts
Bundle binderCounts = getBinderCounts();
for (String key : binderCounts.keySet()) {
mPerfSnapshot.putLong(key, binderCounts.getLong(key));
}
// Add alloc counts
Bundle allocCounts = getAllocCounts();
for (String key : allocCounts.keySet()) {
mPerfSnapshot.putLong(key, allocCounts.getLong(key));
}
mPerfSnapshot.putLong(METRIC_KEY_EXECUTION_TIME, mSnapshotExecTime);
mPerfSnapshot.putLong(METRIC_KEY_CPU_TIME, mSnapshotCpuTime);
mPerfSnapshot.putLong(METRIC_KEY_NATIVE_SIZE, nativeMax);
mPerfSnapshot.putLong(METRIC_KEY_NATIVE_ALLOCATED, nativeAllocated);
mPerfSnapshot.putLong(METRIC_KEY_NATIVE_FREE, nativeFree);
mPerfSnapshot.putLong(METRIC_KEY_NATIVE_PSS, memInfo.nativePss);
mPerfSnapshot.putLong(METRIC_KEY_NATIVE_PRIVATE_DIRTY, memInfo.nativePrivateDirty);
mPerfSnapshot.putLong(METRIC_KEY_NATIVE_SHARED_DIRTY, memInfo.nativeSharedDirty);
mPerfSnapshot.putLong(METRIC_KEY_JAVA_SIZE, dalvikMax);
mPerfSnapshot.putLong(METRIC_KEY_JAVA_ALLOCATED, dalvikAllocated);
mPerfSnapshot.putLong(METRIC_KEY_JAVA_FREE, dalvikFree);
mPerfSnapshot.putLong(METRIC_KEY_JAVA_PSS, memInfo.dalvikPss);
mPerfSnapshot.putLong(METRIC_KEY_JAVA_PRIVATE_DIRTY, memInfo.dalvikPrivateDirty);
mPerfSnapshot.putLong(METRIC_KEY_JAVA_SHARED_DIRTY, memInfo.dalvikSharedDirty);
mPerfSnapshot.putLong(METRIC_KEY_OTHER_PSS, memInfo.otherPss);
mPerfSnapshot.putLong(METRIC_KEY_OTHER_PRIVATE_DIRTY, memInfo.otherPrivateDirty);
mPerfSnapshot.putLong(METRIC_KEY_OTHER_SHARED_DIRTY, memInfo.otherSharedDirty);
|
public Bundle | endSnapshot()End collection of memory usage information. Returns collected data in a
Bundle object.
endPerformanceSnapshot();
if (mPerfWriter != null)
mPerfWriter.writeEndSnapshot(mPerfSnapshot);
return mPerfSnapshot;
|
private static Bundle | getAllocCounts()
Bundle results = new Bundle();
results.putLong(METRIC_KEY_GLOBAL_ALLOC_COUNT, Debug.getGlobalAllocCount());
results.putLong(METRIC_KEY_GLOBAL_ALLOC_SIZE, Debug.getGlobalAllocSize());
results.putLong(METRIC_KEY_GLOBAL_FREED_COUNT, Debug.getGlobalFreedCount());
results.putLong(METRIC_KEY_GLOBAL_FREED_SIZE, Debug.getGlobalFreedSize());
results.putLong(METRIC_KEY_GC_INVOCATION_COUNT, Debug.getGlobalGcInvocationCount());
return results;
|
private static Bundle | getBinderCounts()
Bundle results = new Bundle();
results.putLong(METRIC_KEY_SENT_TRANSACTIONS, Debug.getBinderSentTransactions());
results.putLong(METRIC_KEY_RECEIVED_TRANSACTIONS, Debug.getBinderReceivedTransactions());
return results;
|
public void | setPerformanceResultsWriter(android.os.PerformanceCollector$PerformanceResultsWriter writer)
mPerfWriter = writer;
|
private static void | startAllocCounting()
// Before we start trigger a GC and reset the debug counts. Run the
// finalizers and another GC before starting and stopping the alloc
// counts. This will free up any objects that were just sitting around
// waiting for their finalizers to be run.
Runtime.getRuntime().gc();
Runtime.getRuntime().runFinalization();
Runtime.getRuntime().gc();
Debug.resetAllCounts();
// start the counts
Debug.startAllocCounting();
|
private void | startPerformanceSnapshot()
// Create new snapshot
mPerfSnapshot = new Bundle();
// Add initial binder counts
Bundle binderCounts = getBinderCounts();
for (String key : binderCounts.keySet()) {
mPerfSnapshot.putLong("pre_" + key, binderCounts.getLong(key));
}
// Force a GC and zero out the performance counters. Do this
// before reading initial CPU/wall-clock times so we don't include
// the cost of this setup in our final metrics.
startAllocCounting();
// Record CPU time up to this point, and start timing. Note: this
// must happen at the end of this method, otherwise the timing will
// include noise.
mSnapshotExecTime = SystemClock.uptimeMillis();
mSnapshotCpuTime = Process.getElapsedCpuTime();
|
public void | startTiming(java.lang.String label)Start measurement of user and cpu time.
if (mPerfWriter != null)
mPerfWriter.writeStartTiming(label);
mPerfMeasurement = new Bundle();
mPerfMeasurement.putParcelableArrayList(
METRIC_KEY_ITERATIONS, new ArrayList<Parcelable>());
mExecTime = SystemClock.uptimeMillis();
mCpuTime = Process.getElapsedCpuTime();
|
private static void | stopAllocCounting()
Runtime.getRuntime().gc();
Runtime.getRuntime().runFinalization();
Runtime.getRuntime().gc();
Debug.stopAllocCounting();
|
public Bundle | stopTiming(java.lang.String label)Stop measurement of user and cpu time.
addIteration(label);
if (mPerfWriter != null)
mPerfWriter.writeStopTiming(mPerfMeasurement);
return mPerfMeasurement;
|