package com.alexvasilkov.gestures.internal;

import android.os.SystemClock;
import android.util.Log;

class Fps {

    private static final String TAG = "GestureFps";

    private static final long WARNING_TIME = 17L; // About 60 fps
    private static final long ERROR_TIME = 33L; // About 30 fps

    private long frameStart;
    private long animationStart;
    private int framesCount;

    void start() {
        if (GestureDebug.isDebugFps()) {
            animationStart = frameStart = SystemClock.uptimeMillis();
            framesCount = 0;
        }
    }

    void stop() {
        if (GestureDebug.isDebugFps() && framesCount > 0) {
            long time = SystemClock.uptimeMillis() - animationStart;
            Log.d(TAG, "Average FPS: " + (1000 * framesCount / time));
        }
    }

    void step() {
        if (GestureDebug.isDebugFps()) {
            long frameTime = SystemClock.uptimeMillis() - frameStart;
            if (frameTime > ERROR_TIME) {
                Log.e(TAG, "Frame time: " + frameTime);
            } else if (frameTime > WARNING_TIME) {
                Log.w(TAG, "Frame time: " + frameTime);
            }

            framesCount++;
            frameStart = SystemClock.uptimeMillis();
        }
    }

}

@@ -210,28 +210,52 @@
 E = 
-17
+20
 L; // 
-About 60 fps
+Dropping less than 60 fps in average
 %0A   
@@ -298,28 +298,52 @@
 E = 
-33
+40
 L; // 
-About 30 fps
+Dropping less than 30 fps in average
 %0A%0A  
@@ -702,20 +702,19 @@
     
-long
+int
  time = 
 Syst
@@ -705,24 +705,31 @@
  int time = 
+(int) (
 SystemClock.
@@ -755,24 +755,25 @@
 imationStart
+)
 ;%0A          
@@ -807,13 +807,24 @@
 %22 + 
+Math.round
 (1000
+f
  * f

Clean up fps logs