blob: 66aba36e3a275f4b6eca1edf4c02a18b286a6154 [file] [log] [blame]
Corentin Wallezfe2f3d62015-05-05 17:37:39 -04001//
2// Copyright (c) 2015 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
7// LinuxTimer.cpp: Implementation of a high precision timer class on Linux
8
9#include "linux/LinuxTimer.h"
10
11LinuxTimer::LinuxTimer()
12 : mRunning(false)
13{
14}
15
16void LinuxTimer::start()
17{
18 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &mStartTime);
19 mRunning = true;
20}
21
22void LinuxTimer::stop()
23{
24 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &mStopTime);
25 mRunning = false;
26}
27
28double LinuxTimer::getElapsedTime() const
29{
30 struct timespec endTime;
31 if (mRunning)
32 {
33 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &endTime);
34 }
35 else
36 {
37 endTime = mStopTime;
38 }
39
40 return endTime.tv_sec + (1.0 / 1000000000) * endTime.tv_nsec;
41}
42
43Timer *CreateTimer()
44{
45 return new LinuxTimer();
46}