mirror of
https://github.com/utmapp/angle.git
synced 2026-12-01 22:13:25 -10:00
Changes to CLOCK_MONOTONIC as CLOCK_PROCESS_CPUTIME counts only user time and not kernel time. BUG=angleproject:892 Change-Id: I3d5aee26ee2bacd7449fdd7795ad8c2b289d7324 Reviewed-on: https://chromium-review.googlesource.com/272652 Reviewed-by: Jamie Madill <[email protected]> Reviewed-by: Geoff Lang <[email protected]> Tested-by: Corentin Wallez <[email protected]>
50 lines
1.0 KiB
C++
50 lines
1.0 KiB
C++
//
|
|
// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
//
|
|
|
|
// LinuxTimer.cpp: Implementation of a high precision timer class on Linux
|
|
|
|
#include "linux/LinuxTimer.h"
|
|
#include <iostream>
|
|
|
|
LinuxTimer::LinuxTimer()
|
|
: mRunning(false)
|
|
{
|
|
}
|
|
|
|
void LinuxTimer::start()
|
|
{
|
|
clock_gettime(CLOCK_MONOTONIC, &mStartTime);
|
|
mRunning = true;
|
|
}
|
|
|
|
void LinuxTimer::stop()
|
|
{
|
|
clock_gettime(CLOCK_MONOTONIC, &mStopTime);
|
|
mRunning = false;
|
|
}
|
|
|
|
double LinuxTimer::getElapsedTime() const
|
|
{
|
|
struct timespec endTime;
|
|
if (mRunning)
|
|
{
|
|
clock_gettime(CLOCK_MONOTONIC, &endTime);
|
|
}
|
|
else
|
|
{
|
|
endTime = mStopTime;
|
|
}
|
|
|
|
double startSeconds = mStartTime.tv_sec + (1.0 / 1000000000) * mStartTime.tv_nsec;
|
|
double endSeconds = endTime.tv_sec + (1.0 / 1000000000) * endTime.tv_nsec;
|
|
return endSeconds - startSeconds;
|
|
}
|
|
|
|
Timer *CreateTimer()
|
|
{
|
|
return new LinuxTimer();
|
|
}
|