Methods Summary |
---|
public void | addTimestamp(long timestamp)Add a timestamp to a timing measurement. These are queued up and matched to completed
workload measurements as they become available.
mTimestampQueue.add(timestamp);
|
public void | dumpPerformanceData(java.lang.String path)Dump collected data to file, and clear the stored data.
Format is a simple csv-like text file with a header,
followed by a 3-column list of values in nanoseconds:
timestamp gpu_duration cpu_duration
....
try (BufferedWriter dump = new BufferedWriter(new FileWriter(path))) {
dump.write("timestamp gpu_duration cpu_duration\n");
for (int i = 0; i < mCollectedGpuDurations.size(); i++) {
dump.write(String.format("%d %d %d\n",
mCollectedTimestamps.get(i),
mCollectedGpuDurations.get(i),
mCollectedCpuDurations.get(i)));
}
mCollectedTimestamps.clear();
mCollectedGpuDurations.clear();
mCollectedCpuDurations.clear();
} catch (IOException e) {
Log.e(TAG, "Error writing data dump to " + path + ":" + e);
}
|
protected void | finalize()
nativeDeleteContext(mNativeContext);
|
public int | getCompletedQueryCount()Returns the number of measurements so far that returned a valid duration
measurement.
return mCompletedQueryCount;
|
private long | getNextGlDuration()Get the next available GPU timing measurement.
Since the GPU works asynchronously, the results of a single start/stopGlTimer measurement
will only be available some time after the {@link #stopTimer} call is made. Poll this method
until the result becomes available. If multiple start/endTimer measurements are made in a
row, the results will be available in FIFO order.
long duration = nativeGetNextGlDuration(mNativeContext);
if (duration > 0) {
mCompletedQueryCount++;
}
return duration;
|
public static boolean | isGlTimingSupported()Returns true if the Gl timing methods will work, false otherwise.
Must be called within a valid GL context.
return nativeQuerySupport();
|
private static native long | nativeCreateContext(int maxQueryCount)Create a native performance measurement context.
|
private static native void | nativeDeleteContext(long contextHandle)Delete the native context.
Not safe to call more than once.
|
protected static native long | nativeGetNextGlDuration(long contextHandle)Get the next available GL duration measurement, in nanoseconds.
Must be called from the same thread as calls to {@link #nativeStartGlTimer} and
{@link #nativeEndGlTimer}.
|
private static native boolean | nativeQuerySupport()Query whether the relevant Gl extensions are available for Gl timing
|
protected static native void | nativeStartGlTimer(long contextHandle)Start a GL timing section.
All GL commands between this method and the next {@link #nativeEndGlTimer} will be
included in the timing.
Must be called from the same thread as calls to {@link #nativeEndGlTimer} and
{@link #nativeGetNextGlDuration}.
|
protected static native void | nativeStopGlTimer(long contextHandle)Finish a GL timing section.
Some time after this call returns, the time the GPU took to
execute all work submitted between the latest {@link #nativeStartGlTimer} and
this call, will become available from calling {@link #nativeGetNextGlDuration}.
Must be called from the same thread as calls to {@link #nativeStartGlTimer} and
{@link #nativeGetNextGlDuration}.
|
public void | startTimer()Start a GPU/CPU timing measurement.
Call before starting a rendering pass. Only one timing measurement can be active at once,
so {@link #stopTimer} must be called before the next call to this method.
nativeStartGlTimer(mNativeContext);
mStartTimeNs = SystemClock.elapsedRealtimeNanos();
|
public void | stopTimer()Finish a GPU/CPU timing measurement.
Call after finishing all the drawing for a rendering pass. Only one timing measurement can
be active at once, so {@link #startTimer} must be called before the next call to this
method.
// Complete CPU timing
long endTimeNs = SystemClock.elapsedRealtimeNanos();
mCpuDurationsQueue.add(endTimeNs - mStartTimeNs);
// Complete GL timing
nativeStopGlTimer(mNativeContext);
// Poll to see if GL timing results have arrived; if so
// store the results for a frame
long duration = getNextGlDuration();
if (duration > 0) {
mCollectedGpuDurations.add(duration);
mCollectedTimestamps.add(mTimestampQueue.isEmpty() ?
NO_DURATION_YET : mTimestampQueue.poll());
mCollectedCpuDurations.add(mCpuDurationsQueue.isEmpty() ?
NO_DURATION_YET : mCpuDurationsQueue.poll());
}
if (duration == FAILED_TIMING) {
// Discard timestamp and CPU measurement since GPU measurement failed
if (!mTimestampQueue.isEmpty()) {
mTimestampQueue.poll();
}
if (!mCpuDurationsQueue.isEmpty()) {
mCpuDurationsQueue.poll();
}
}
|