public class PerformanceCollector extends Object
PerformanceCollector.PerformanceResultsWriter
.
beginSnapshot(String)
and endSnapshot()
functions collect
memory usage information and measure runtime between calls to begin and end.
These functions logically wrap around an entire test, and should be called
with name of test as the label, e.g. EmailPerformanceTest.
startTiming(String)
and stopTiming(String)
functions
measure runtime between calls to start and stop. These functions logically
wrap around a single test case or a small block of code, and should be called
with the name of test case as the label, e.g. testSimpleSendMailSequence.
addIteration(String)
inserts intermediate measurement point which
can be labeled with a String, e.g. Launch email app, compose, send, etc.
Snapshot and timing functions do not interfere with each other, and thus can be called in any order. The intended structure is to wrap begin/endSnapshot around calls to start/stopTiming, for example:
beginSnapshot("EmailPerformanceTest");
startTiming("testSimpleSendSequence");
addIteration("Launch email app");
addIteration("Compose");
stopTiming("Send");
startTiming("testComplexSendSequence");
stopTiming("");
startTiming("testAddLabel");
stopTiming("");
endSnapshot();
Structure of results output is up to implementor of
PerformanceCollector.PerformanceResultsWriter
.
Pending approval for public API.
Modifier and Type | Class and Description |
---|---|
static interface |
PerformanceCollector.PerformanceResultsWriter
Interface for reporting performance data.
|
Modifier and Type | Field and Description |
---|---|
static String |
METRIC_KEY_CPU_TIME
In a results Bundle, this key reports the cpu time of the code block
under measurement.
|
static String |
METRIC_KEY_EXECUTION_TIME
In a results Bundle, this key reports the execution time of the code
block under measurement.
|
static String |
METRIC_KEY_GC_INVOCATION_COUNT
In a snapshot Bundle, this key reports the number of garbage collection
invocations.
|
static String |
METRIC_KEY_GLOBAL_ALLOC_COUNT
In a snapshot Bundle, this key reports the number of objects allocated
globally.
|
static String |
METRIC_KEY_GLOBAL_ALLOC_SIZE
In a snapshot Bundle, this key reports the size of all objects allocated
globally.
|
static String |
METRIC_KEY_GLOBAL_FREED_COUNT
In a snapshot Bundle, this key reports the number of objects freed
globally.
|
static String |
METRIC_KEY_GLOBAL_FREED_SIZE
In a snapshot Bundle, this key reports the size of all objects freed
globally.
|
static String |
METRIC_KEY_ITERATIONS
In a results Bundle, this key references a List of iteration Bundles.
|
static String |
METRIC_KEY_JAVA_ALLOCATED
In a snapshot Bundle, this key reports the amount of allocated memory
used by the running program.
|
static String |
METRIC_KEY_JAVA_FREE
In a snapshot Bundle, this key reports the amount of free memory
available to the running program.
|
static String |
METRIC_KEY_JAVA_PRIVATE_DIRTY
In a snapshot Bundle, this key reports the number of private dirty pages
used by dalvik.
|
static String |
METRIC_KEY_JAVA_PSS
In a snapshot Bundle, this key reports the proportional set size for
dalvik.
|
static String |
METRIC_KEY_JAVA_SHARED_DIRTY
In a snapshot Bundle, this key reports the number of shared dirty pages
used by dalvik.
|
static String |
METRIC_KEY_JAVA_SIZE
In a snapshot Bundle, this key reports the total amount of memory
available to the running program.
|
static String |
METRIC_KEY_LABEL
In an iteration Bundle, this key describes the iteration.
|
static String |
METRIC_KEY_NATIVE_ALLOCATED
In a snapshot Bundle, this key reports the amount of allocated memory in
the native heap.
|
static String |
METRIC_KEY_NATIVE_FREE
In a snapshot Bundle, this key reports the amount of free memory in the
native heap.
|
static String |
METRIC_KEY_NATIVE_PRIVATE_DIRTY
In a snapshot Bundle, this key reports the number of private dirty pages
used by the native heap.
|
static String |
METRIC_KEY_NATIVE_PSS
In a snapshot Bundle, this key reports the proportional set size for the
native heap.
|
static String |
METRIC_KEY_NATIVE_SHARED_DIRTY
In a snapshot Bundle, this key reports the number of shared dirty pages
used by the native heap.
|
static String |
METRIC_KEY_NATIVE_SIZE
In a snapshot Bundle, this key reports the size of the native heap.
|
static String |
METRIC_KEY_OTHER_PRIVATE_DIRTY
In a snapshot Bundle, this key reports the number of private dirty pages
used by everything else.
|
static String |
METRIC_KEY_OTHER_PSS
In a snapshot Bundle, this key reports the proportional set size for
everything else.
|
static String |
METRIC_KEY_OTHER_SHARED_DIRTY
In a snapshot Bundle, this key reports the number of shared dirty pages
used by everything else.
|
static String |
METRIC_KEY_PRE_RECEIVED_TRANSACTIONS
In a snapshot Bundle, this key reports the number of received
transactions from the binder driver before collection started.
|
static String |
METRIC_KEY_PRE_SENT_TRANSACTIONS
In a snapshot Bundle, this key reports the number of transactions sent by
the running program before collection started.
|
static String |
METRIC_KEY_RECEIVED_TRANSACTIONS
In a snapshot Bundle, this key reports the number of received
transactions from the binder driver.
|
static String |
METRIC_KEY_SENT_TRANSACTIONS
In a snapshot Bundle, this key reports the number of transactions sent by
the running program.
|
Constructor and Description |
---|
PerformanceCollector() |
PerformanceCollector(PerformanceCollector.PerformanceResultsWriter writer) |
Modifier and Type | Method and Description |
---|---|
Bundle |
addIteration(String label)
Add a measured segment, and start measuring the next segment.
|
void |
addMeasurement(String label,
float value)
Add a float type measurement to the collector.
|
void |
addMeasurement(String label,
long value)
Add an integer type measurement to the collector.
|
void |
addMeasurement(String label,
String value)
Add a string field to the collector.
|
void |
beginSnapshot(String label)
Begin collection of memory usage information.
|
Bundle |
endSnapshot()
End collection of memory usage information.
|
void |
setPerformanceResultsWriter(PerformanceCollector.PerformanceResultsWriter writer) |
void |
startTiming(String label)
Start measurement of user and cpu time.
|
Bundle |
stopTiming(String label)
Stop measurement of user and cpu time.
|
public static final String METRIC_KEY_ITERATIONS
public static final String METRIC_KEY_LABEL
public static final String METRIC_KEY_CPU_TIME
public static final String METRIC_KEY_EXECUTION_TIME
public static final String METRIC_KEY_PRE_RECEIVED_TRANSACTIONS
public static final String METRIC_KEY_PRE_SENT_TRANSACTIONS
public static final String METRIC_KEY_RECEIVED_TRANSACTIONS
public static final String METRIC_KEY_SENT_TRANSACTIONS
public static final String METRIC_KEY_GC_INVOCATION_COUNT
public static final String METRIC_KEY_JAVA_ALLOCATED
public static final String METRIC_KEY_JAVA_FREE
public static final String METRIC_KEY_JAVA_PRIVATE_DIRTY
public static final String METRIC_KEY_JAVA_PSS
public static final String METRIC_KEY_JAVA_SHARED_DIRTY
public static final String METRIC_KEY_JAVA_SIZE
public static final String METRIC_KEY_NATIVE_ALLOCATED
public static final String METRIC_KEY_NATIVE_FREE
public static final String METRIC_KEY_NATIVE_PRIVATE_DIRTY
public static final String METRIC_KEY_NATIVE_PSS
public static final String METRIC_KEY_NATIVE_SHARED_DIRTY
public static final String METRIC_KEY_NATIVE_SIZE
public static final String METRIC_KEY_GLOBAL_ALLOC_COUNT
public static final String METRIC_KEY_GLOBAL_ALLOC_SIZE
public static final String METRIC_KEY_GLOBAL_FREED_COUNT
public static final String METRIC_KEY_GLOBAL_FREED_SIZE
public static final String METRIC_KEY_OTHER_PRIVATE_DIRTY
public static final String METRIC_KEY_OTHER_PSS
public static final String METRIC_KEY_OTHER_SHARED_DIRTY
public PerformanceCollector()
public PerformanceCollector(PerformanceCollector.PerformanceResultsWriter writer)
public void setPerformanceResultsWriter(PerformanceCollector.PerformanceResultsWriter writer)
public void beginSnapshot(String label)
label
- description of code block between beginSnapshot and
endSnapshot, used to label outputpublic Bundle endSnapshot()
cpu_time
execution_time
pre_received_transactions
pre_sent_transactions
received_transactions
sent_transactions
gc_invocation_count
java_allocated
java_free
java_private_dirty
java_pss
java_shared_dirty
java_size
native_allocated
native_free
native_private_dirty
native_pss
native_shared_dirty
native_size
global_alloc_count
global_alloc_size
global_freed_count
global_freed_size
other_private_dirty
other_pss
other_shared_dirty
public void startTiming(String label)
label
- description of code block between startTiming and
stopTiming, used to label outputpublic Bundle addIteration(String label)
label
- description of code block between startTiming and
addIteration, and between two calls to addIteration, used
to label outputpublic Bundle stopTiming(String label)
label
- description of code block between addIteration or
startTiming and stopTiming, used to label outputiterations
.public void addMeasurement(String label, long value)
label
- short description of the metric that was measuredvalue
- long value of the measurementpublic void addMeasurement(String label, float value)
label
- short description of the metric that was measuredvalue
- float value of the measurement