FileDocCategorySizeDatePackage
StopWatchMap.javaAPI DocAndroid 5.1 API2815Thu Mar 12 22:22:30 GMT 2015android.filterfw.core

StopWatch

public class StopWatch extends Object
hide

Fields Summary
private int
STOP_WATCH_LOGGING_PERIOD
private String
TAG
private String
mName
private long
mStartTime
private long
mTotalTime
private int
mNumCalls
Constructors Summary
public StopWatch(String name)


       
        mName = name;
        mStartTime = -1;
        mTotalTime = 0;
        mNumCalls = 0;
    
Methods Summary
public voidstart()

        if (mStartTime != -1) {
             throw new RuntimeException(
                 "Calling start with StopWatch already running");
        }
        mStartTime = SystemClock.elapsedRealtime();
    
public voidstop()

        if (mStartTime == -1) {
             throw new RuntimeException(
                 "Calling stop with StopWatch already stopped");
        }
        long stopTime = SystemClock.elapsedRealtime();
        mTotalTime += stopTime - mStartTime;
        ++mNumCalls;
        mStartTime = -1;
        if (mNumCalls % STOP_WATCH_LOGGING_PERIOD == 0) {
            Log.i(TAG, "AVG ms/call " + mName + ": " +
                  String.format("%.1f", mTotalTime * 1.0f / mNumCalls));
            mTotalTime = 0;
            mNumCalls = 0;
        }