• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef PERFMONITOR_H_
18 #define PERFMONITOR_H_
19 
20 #include <jni.h>
21 #include <errno.h>
22 #include <time.h>
23 #include "JNIHelper.h"
24 
25 namespace ndk_helper
26 {
27 
28 const int32_t NUM_SAMPLES = 100;
29 
30 /******************************************************************
31  * Helper class for a performance monitoring and get current tick time
32  */
33 class PerfMonitor
34 {
35 private:
36     float current_FPS_;
37     time_t tv_last_sec_;
38 
39     double last_tick_;
40     int32_t tickindex_;
41     double ticksum_;
42     double ticklist_[NUM_SAMPLES];
43 
44     double UpdateTick( double current_tick );
45 public:
46     PerfMonitor();
47     virtual ~PerfMonitor();
48 
49     bool Update( float &fFPS );
50 
GetCurrentTime()51     static double GetCurrentTime()
52     {
53         struct timeval time;
54         gettimeofday( &time, NULL );
55         double ret = time.tv_sec + time.tv_usec * 1.0 / 1000000.0;
56         return ret;
57     }
58 };
59 
60 }   //namespace ndkHelper
61 #endif /* PERFMONITOR_H_ */
62