public static void onEvent(int eventType){
  if (sInstance == null) {
    sInstance=new CameraPerformanceTracker();
  }
  long currentTime=System.currentTimeMillis();
switch (eventType) {
case ACTIVITY_START:
    sInstance.mAppStartTime=currentTime;
  break;
case ACTIVITY_PAUSE:
sInstance.mFirstPreviewFrameLatencyWarmStart=UNSET;
break;
case ACTIVITY_RESUME:
sInstance.mAppResumeTime=currentTime;
break;
case FIRST_PREVIEW_FRAME:
Log.d(TAG,"First preview frame received");
if (sInstance.mFirstPreviewFrameLatencyColdStart == UNSET) {
sInstance.mFirstPreviewFrameLatencyColdStart=currentTime - sInstance.mAppStartTime;
}
 else {
sInstance.mFirstPreviewFrameLatencyWarmStart=currentTime - sInstance.mAppResumeTime;
}
if (sInstance.mModeSwitchStartTime != UNSET) {
sInstance.mModeSwitchDuration=currentTime - sInstance.mModeSwitchStartTime;
sInstance.mModeSwitchStartTime=UNSET;
}
break;
case MODE_SWITCH_START:
sInstance.mModeSwitchStartTime=currentTime;
break;
default :
break;
}
if (DEBUG && eventType == FIRST_PREVIEW_FRAME) {
Log.d(TAG,"Mode switch duration: " + (sInstance.mModeSwitchDuration == UNSET ? "UNSET" : sInstance.mModeSwitchDuration));
Log.d(TAG,"Cold start latency: " + (sInstance.mFirstPreviewFrameLatencyColdStart == UNSET ? "UNSET" : sInstance.mFirstPreviewFrameLatencyColdStart));
Log.d(TAG,"Warm start latency: " + (sInstance.mFirstPreviewFrameLatencyWarmStart == UNSET ? "UNSET" : sInstance.mFirstPreviewFrameLatencyWarmStart));
}
}

public static void onEvent ( int eventType ) { if ( sInstance == null ) { sInstance = new CameraPerformanceTracker ( ) ; } long currentTime = System . currentTimeMillis ( ) ; switch ( eventType ) { case ACTIVITY_START : sInstance . mAppStartTime = currentTime ; break ; case ACTIVITY_PAUSE : sInstance . mFirstPreviewFrameLatencyWarmStart = UNSET ; break ; case ACTIVITY_RESUME : sInstance . mAppResumeTime = currentTime ; break ; case FIRST_PREVIEW_FRAME : Log . d ( TAG , "First preview frame received" ) ; if ( sInstance . mFirstPreviewFrameLatencyColdStart == UNSET ) { sInstance . mFirstPreviewFrameLatencyColdStart = currentTime - sInstance . mAppStartTime ; } else { sInstance . mFirstPreviewFrameLatencyWarmStart = currentTime - sInstance . mAppResumeTime ; } if ( sInstance . mModeSwitchStartTime != UNSET ) { sInstance . mModeSwitchDuration = currentTime - sInstance . mModeSwitchStartTime ; sInstance . mModeSwitchStartTime = UNSET ; } break ; case MODE_SWITCH_START : sInstance . mModeSwitchStartTime = currentTime ; break ; default : break ; } if ( DEBUG && eventType == FIRST_PREVIEW_FRAME ) { Log . d ( TAG , "Mode switch duration: " + ( sInstance . mModeSwitchDuration == UNSET ? "UNSET" : sInstance . mModeSwitchDuration ) ) ; Log . d ( TAG , "Cold start latency: " + ( sInstance . mFirstPreviewFrameLatencyColdStart == UNSET ? "UNSET" : sInstance . mFirstPreviewFrameLatencyColdStart ) ) ; Log . d ( TAG , "Warm start latency: " + ( sInstance . mFirstPreviewFrameLatencyWarmStart == UNSET ? "UNSET" : sInstance . mFirstPreviewFrameLatencyWarmStart ) ) ; } }
this gets called when an important state change happens . based on the type of the event / state change , either we will record the time of the event , or calculate the duration / latency .
