2016-02-16 23:21:12 +03:00
|
|
|
#include "profiler/profiler.h"
|
2016-06-20 23:21:54 +03:00
|
|
|
#include "profile_manager.h"
|
2016-02-16 23:21:12 +03:00
|
|
|
#include <ctime>
|
|
|
|
#include <chrono>
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
using namespace profiler;
|
|
|
|
|
2016-09-01 22:22:58 +03:00
|
|
|
#ifdef _WIN32
|
2016-08-02 21:18:04 +03:00
|
|
|
struct ProfPerformanceFrequency {
|
|
|
|
LARGE_INTEGER frequency;
|
|
|
|
ProfPerformanceFrequency() { QueryPerformanceFrequency(&frequency); }
|
|
|
|
} const WINDOWS_CPU_INFO;
|
|
|
|
#endif
|
|
|
|
|
2016-07-31 19:20:58 +03:00
|
|
|
inline timestamp_t getCurrentTime()
|
|
|
|
{
|
2016-09-01 22:22:58 +03:00
|
|
|
#ifdef _WIN32
|
2016-07-31 19:20:58 +03:00
|
|
|
//see https://msdn.microsoft.com/library/windows/desktop/dn553408(v=vs.85).aspx
|
|
|
|
LARGE_INTEGER elapsedMicroseconds;
|
|
|
|
if (!QueryPerformanceCounter(&elapsedMicroseconds))
|
|
|
|
return 0;
|
2016-08-01 22:16:31 +03:00
|
|
|
elapsedMicroseconds.QuadPart *= 1000000000LL;
|
2016-08-02 21:18:04 +03:00
|
|
|
elapsedMicroseconds.QuadPart /= WINDOWS_CPU_INFO.frequency.QuadPart;
|
2016-07-31 19:20:58 +03:00
|
|
|
return (timestamp_t)elapsedMicroseconds.QuadPart;
|
|
|
|
#else
|
2016-07-31 20:01:02 +03:00
|
|
|
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> time_point;
|
|
|
|
time_point = std::chrono::time_point_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now());
|
2016-07-31 19:20:58 +03:00
|
|
|
return time_point.time_since_epoch().count();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-08-28 02:41:02 +03:00
|
|
|
BaseBlockData::BaseBlockData(timestamp_t _begin_time, block_id_t _descriptor_id)
|
|
|
|
: m_begin(_begin_time)
|
|
|
|
, m_end(0)
|
|
|
|
, m_id(_descriptor_id)
|
2016-02-16 23:21:12 +03:00
|
|
|
{
|
2016-08-28 02:41:02 +03:00
|
|
|
|
2016-02-16 23:21:12 +03:00
|
|
|
}
|
|
|
|
|
2016-08-28 23:40:23 +03:00
|
|
|
Block::Block(block_type_t _block_type, block_id_t _descriptor_id, const char* _name)
|
2016-08-28 02:41:02 +03:00
|
|
|
: BaseBlockData(getCurrentTime(), _descriptor_id)
|
|
|
|
, m_name(_name)
|
|
|
|
{
|
|
|
|
if (_block_type != BLOCK_TYPE_BLOCK)
|
|
|
|
{
|
|
|
|
m_end = m_begin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Block::finish()
|
2016-02-16 23:21:12 +03:00
|
|
|
{
|
2016-08-28 02:41:02 +03:00
|
|
|
m_end = getCurrentTime();
|
|
|
|
}
|
2016-02-20 05:24:12 +03:00
|
|
|
|
2016-08-28 02:41:02 +03:00
|
|
|
Block::~Block()
|
|
|
|
{
|
|
|
|
if (!isFinished())
|
|
|
|
::profiler::endBlock();
|
2016-02-16 23:25:12 +03:00
|
|
|
}
|