• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2005 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 #define LOG_TAG "StopWatch"
18 
19 #include <utils/StopWatch.h>
20 
21 /* for PRId64 */
22 #ifndef __STDC_FORMAT_MACROS
23 #define __STDC_FORMAT_MACROS 1
24 #endif
25 #include <inttypes.h>
26 
27 #include <utils/Log.h>
28 
29 namespace android {
30 
StopWatch(const char * name,int clock)31 StopWatch::StopWatch(const char* name, int clock) : mName(name), mClock(clock) {
32     reset();
33 }
34 
~StopWatch()35 StopWatch::~StopWatch() {
36     ALOGD("StopWatch %s (us): %" PRId64 " ", name(), ns2us(elapsedTime()));
37 }
38 
name() const39 const char* StopWatch::name() const {
40     return mName;
41 }
42 
elapsedTime() const43 nsecs_t StopWatch::elapsedTime() const {
44     return systemTime(mClock) - mStartTime;
45 }
46 
reset()47 void StopWatch::reset() {
48     mStartTime = systemTime(mClock);
49 }
50 
51 }  // namespace android
52