mirror of
https://github.com/thead-yocto-mirror/skia
synced 2026-10-03 01:23:37 +02:00
60 lines
1.1 KiB
C++
60 lines
1.1 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.
|
|
//
|
|
|
|
// PosixTimer.cpp: Implementation of a high precision timer class on POSIX
|
|
|
|
#include "util/posix/PosixTimer.h"
|
|
#include <iostream>
|
|
|
|
PosixTimer::PosixTimer() : mRunning(false) {}
|
|
|
|
namespace
|
|
{
|
|
uint64_t getCurrentTimeNs()
|
|
{
|
|
struct timespec currentTime;
|
|
clock_gettime(CLOCK_MONOTONIC, ¤tTime);
|
|
return currentTime.tv_sec * 1'000'000'000llu + currentTime.tv_nsec;
|
|
}
|
|
} // anonymous namespace
|
|
|
|
void PosixTimer::start()
|
|
{
|
|
mStartTimeNs = getCurrentTimeNs();
|
|
mRunning = true;
|
|
}
|
|
|
|
void PosixTimer::stop()
|
|
{
|
|
mStopTimeNs = getCurrentTimeNs();
|
|
mRunning = false;
|
|
}
|
|
|
|
double PosixTimer::getElapsedTime() const
|
|
{
|
|
uint64_t endTimeNs;
|
|
if (mRunning)
|
|
{
|
|
endTimeNs = getCurrentTimeNs();
|
|
}
|
|
else
|
|
{
|
|
endTimeNs = mStopTimeNs;
|
|
}
|
|
|
|
return (endTimeNs - mStartTimeNs) * 1e-9;
|
|
}
|
|
|
|
double PosixTimer::getAbsoluteTime()
|
|
{
|
|
return getCurrentTimeNs() * 1e-9;
|
|
}
|
|
|
|
Timer *CreateTimer()
|
|
{
|
|
return new PosixTimer();
|
|
}
|