blob: c91cd5cd70fc445b030e9e7b672ea41691fdf5dd [file] [log] [blame]
The Android Open Source Projectcbb10112009-03-03 19:31:44 -08001/*
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
Mathias Agopian22dbf392017-02-28 15:06:51 -080019#include <utils/StopWatch.h>
The Android Open Source Projectcbb10112009-03-03 19:31:44 -080020
Andrew Hsieh24e57d52012-02-27 18:50:55 -080021#include <inttypes.h>
22
Steven Moreland066e6252023-10-07 00:29:44 +000023#include <log/log.h>
The Android Open Source Projectcbb10112009-03-03 19:31:44 -080024
The Android Open Source Projectcbb10112009-03-03 19:31:44 -080025namespace android {
26
Chih-Hung Hsieh122352d2017-10-02 15:20:07 -070027StopWatch::StopWatch(const char* name, int clock) : mName(name), mClock(clock) {
Jeff Brown66db6892010-04-22 18:58:52 -070028 reset();
The Android Open Source Projectcbb10112009-03-03 19:31:44 -080029}
30
Elliott Hughesafa6e9f2021-05-11 12:29:27 -070031StopWatch::~StopWatch() {
32 ALOGD("StopWatch %s (us): %" PRId64 " ", name(), ns2us(elapsedTime()));
The Android Open Source Projectcbb10112009-03-03 19:31:44 -080033}
34
Elliott Hughesafa6e9f2021-05-11 12:29:27 -070035const char* StopWatch::name() const {
The Android Open Source Projectcbb10112009-03-03 19:31:44 -080036 return mName;
37}
38
Elliott Hughesafa6e9f2021-05-11 12:29:27 -070039nsecs_t StopWatch::elapsedTime() const {
The Android Open Source Projectcbb10112009-03-03 19:31:44 -080040 return systemTime(mClock) - mStartTime;
41}
42
Elliott Hughesafa6e9f2021-05-11 12:29:27 -070043void StopWatch::reset() {
Jeff Brown66db6892010-04-22 18:58:52 -070044 mStartTime = systemTime(mClock);
45}
46
Elliott Hughesafa6e9f2021-05-11 12:29:27 -070047} // namespace android