[go: up one dir, main page]

blob: 5bd51f24872adbea9bd54ce3c9029c789707ef5c [file] [log] [blame]
Shahbaz Youssefif0dd0872019-08-23 19:45:341//
2// Copyright 2019 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6// Timer.cpp: Implementation of a high precision timer class.
7//
8
9#include "util/Timer.h"
10
11#include "common/system_utils.h"
12
13Timer::Timer() : mRunning(false), mStartTime(0), mStopTime(0) {}
14
15void Timer::start()
16{
Lingfeng Yange9f9fa12021-11-10 02:13:1517 mStartTime = angle::GetCurrentSystemTime();
18 mStartCpuTime = angle::GetCurrentProcessCpuTime();
19 mRunning = true;
Shahbaz Youssefif0dd0872019-08-23 19:45:3420}
21
22void Timer::stop()
23{
Lingfeng Yange9f9fa12021-11-10 02:13:1524 mStopTime = angle::GetCurrentSystemTime();
25 mStopCpuTime = angle::GetCurrentProcessCpuTime();
26 mRunning = false;
Shahbaz Youssefif0dd0872019-08-23 19:45:3427}
28
Lingfeng Yange9f9fa12021-11-10 02:13:1529double Timer::getElapsedWallClockTime() const
Shahbaz Youssefif0dd0872019-08-23 19:45:3430{
31 double endTime;
32 if (mRunning)
33 {
Jamie Madill666fcf32021-10-08 16:19:1534 endTime = angle::GetCurrentSystemTime();
Shahbaz Youssefif0dd0872019-08-23 19:45:3435 }
36 else
37 {
38 endTime = mStopTime;
39 }
40
41 return endTime - mStartTime;
42}
Lingfeng Yange9f9fa12021-11-10 02:13:1543
44double Timer::getElapsedCpuTime() const
45{
46 double endTime;
47 if (mRunning)
48 {
49 endTime = angle::GetCurrentProcessCpuTime();
50 }
51 else
52 {
53 endTime = mStopCpuTime;
54 }
55
56 return endTime - mStartCpuTime;
57}