2014-05-01 09:39:11 -04:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
2014-04-30 13:46:41 -04:00
|
|
|
#include "IncludeWindows.h"
|
|
|
|
#endif
|
2014-05-01 09:39:11 -04:00
|
|
|
#if defined(__linux__) || defined(__APPLE__)
|
2014-04-30 13:46:41 -04:00
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "UMicroseconds.h"
|
|
|
|
|
|
|
|
namespace wvNS {
|
|
|
|
UMicroseconds& UMicroseconds::ReadTime()
|
|
|
|
{
|
2014-05-01 09:39:11 -04:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
2014-04-30 13:46:41 -04:00
|
|
|
LARGE_INTEGER Frequency, Count ;
|
2014-04-29 16:05:54 -04:00
|
|
|
|
2014-04-30 13:46:41 -04:00
|
|
|
QueryPerformanceFrequency(&Frequency) ;
|
|
|
|
QueryPerformanceCounter(&Count);
|
|
|
|
theTime = uint64_t((Count.QuadPart * 1000000.0 / Frequency.QuadPart));
|
|
|
|
#endif
|
2014-04-29 16:05:54 -04:00
|
|
|
|
2014-05-01 09:39:11 -04:00
|
|
|
#if defined(__linux__) || defined(__APPLE__)
|
2014-04-30 13:46:41 -04:00
|
|
|
// Mac code replaced by posix calls, to reduce Carbon dependency.
|
|
|
|
timeval buf;
|
2014-04-29 16:05:54 -04:00
|
|
|
|
2014-04-30 13:46:41 -04:00
|
|
|
gettimeofday(&buf,NULL);
|
2014-04-29 16:05:54 -04:00
|
|
|
|
2014-04-30 13:46:41 -04:00
|
|
|
// micro sec
|
|
|
|
theTime = uint64_t(buf.tv_sec) * 1000*1000 + buf.tv_usec;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
Removed in favor of the posix implementation.
|
2014-05-01 09:39:11 -04:00
|
|
|
#ifdef __APPLE__
|
2014-04-30 13:46:41 -04:00
|
|
|
uint32_t UMicroseconds::hi() {return reinterpret_cast<UnsignedWide*>(&theTime)->hi;}
|
|
|
|
uint32_t UMicroseconds::lo() {return reinterpret_cast<UnsignedWide*>(&theTime)->lo;}
|
|
|
|
#endif
|
2014-04-29 16:30:56 -04:00
|
|
|
*/
|
2014-04-30 13:46:41 -04:00
|
|
|
void UMicrosecondsAccumulator::Start()
|
|
|
|
{
|
|
|
|
m_start_time.ReadTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UMicrosecondsAccumulator::Stop()
|
|
|
|
{
|
|
|
|
UMicroseconds stop_time;
|
|
|
|
|
|
|
|
m_accumulator += stop_time.GetNativeTime() - m_start_time.GetNativeTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UMicrosecondsAccumulator::Clear()
|
|
|
|
{
|
|
|
|
m_start_time = 0;
|
|
|
|
m_accumulator = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
UMicroseconds UMicrosecondsAccumulator::GetAccumulatedTime() const
|
|
|
|
{
|
|
|
|
return m_accumulator;
|
|
|
|
}
|
|
|
|
|
|
|
|
UMicrosecondsAccumulator& UMicrosecondsAccumulator::operator+=(const UMicrosecondsAccumulator& inaccum_to_add)
|
|
|
|
{
|
|
|
|
m_accumulator += inaccum_to_add.GetAccumulatedTime();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace wvNS {
|