1/*
2 * Copyright (C) 2011 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 FRAMEWORKS_EX_VARIABLESPEED_JNI_PROFILE_TIMER_H_
18#define FRAMEWORKS_EX_VARIABLESPEED_JNI_PROFILE_TIMER_H_
19
20#include <hlogging.h>
21#include <time.h>
22
23#include <string>
24
25// Simple profiler for debugging method call duration.
26class Timer {
27 public:
28  Timer() : startTime_(clock()) {
29  }
30
31  virtual ~Timer() {
32    PrintElapsed("destructor");
33  }
34
35  void PrintElapsed(const char* message) {
36    clock_t endTime(clock());
37    LOGD("Timer(%s): %d ms", message,
38        static_cast<int>((endTime - startTime_) * 1000 / CLOCKS_PER_SEC));
39  }
40
41  size_t GetElapsed() {
42    clock_t endTime(clock());
43    return (endTime - startTime_) * 1000 / CLOCKS_PER_SEC;
44  }
45
46 private:
47  clock_t startTime_;
48
49  DISALLOW_COPY_AND_ASSIGN(Timer);
50};
51
52#endif  // FRAMEWORKS_EX_VARIABLESPEED_JNI_PROFILE_TIMER_H_
53