• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
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 
Timer()13 Timer::Timer() : mRunning(false), mStartTime(0), mStopTime(0) {}
14 
start()15 void Timer::start()
16 {
17     mStartTime    = angle::GetCurrentSystemTime();
18     mStartCpuTime = angle::GetCurrentProcessCpuTime();
19     mRunning      = true;
20 }
21 
stop()22 void Timer::stop()
23 {
24     mStopTime    = angle::GetCurrentSystemTime();
25     mStopCpuTime = angle::GetCurrentProcessCpuTime();
26     mRunning     = false;
27 }
28 
getElapsedWallClockTime() const29 double Timer::getElapsedWallClockTime() const
30 {
31     double endTime;
32     if (mRunning)
33     {
34         endTime = angle::GetCurrentSystemTime();
35     }
36     else
37     {
38         endTime = mStopTime;
39     }
40 
41     return endTime - mStartTime;
42 }
43 
getElapsedCpuTime() const44 double 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 }
58