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-02-20 05:24:12 +03:00
|
|
|
BaseBlockData::BaseBlockData(color_t _color, block_type_t _type) :
|
|
|
|
type(_type),
|
2016-02-17 23:43:37 +03:00
|
|
|
color(_color),
|
|
|
|
begin(0),
|
2016-02-20 05:24:12 +03:00
|
|
|
end(0),
|
|
|
|
thread_id(0)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Block::Block(const char* _name, color_t _color, block_type_t _type) :
|
|
|
|
BaseBlockData(_color,_type),
|
2016-02-17 23:43:37 +03:00
|
|
|
name(_name)
|
2016-02-16 23:21:12 +03:00
|
|
|
{
|
|
|
|
tick(begin);
|
2016-03-03 14:55:38 +03:00
|
|
|
if (this->type == BLOCK_TYPE_EVENT)
|
2016-02-20 18:17:00 +03:00
|
|
|
{
|
|
|
|
end = begin;
|
|
|
|
}
|
2016-06-20 23:21:54 +03:00
|
|
|
thread_id = getCurrentThreadId();
|
2016-02-16 23:21:12 +03:00
|
|
|
}
|
|
|
|
|
2016-07-31 19:20:58 +03:00
|
|
|
inline timestamp_t getCurrentTime()
|
|
|
|
{
|
|
|
|
#ifdef WIN32
|
|
|
|
//see https://msdn.microsoft.com/library/windows/desktop/dn553408(v=vs.85).aspx
|
|
|
|
static LARGE_INTEGER frequency;
|
|
|
|
static bool first=true;
|
|
|
|
if (first)
|
|
|
|
QueryPerformanceFrequency(&frequency);
|
|
|
|
first = false;
|
|
|
|
LARGE_INTEGER elapsedMicroseconds;
|
|
|
|
if (!QueryPerformanceCounter(&elapsedMicroseconds))
|
|
|
|
return 0;
|
|
|
|
elapsedMicroseconds.QuadPart *= 1000000;
|
|
|
|
elapsedMicroseconds.QuadPart /= frequency.QuadPart;
|
|
|
|
return (timestamp_t)elapsedMicroseconds.QuadPart;
|
|
|
|
#else
|
|
|
|
std::chrono::time_point<std::chrono::system_clock, std::chrono::microseconds> time_point;
|
|
|
|
time_point = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now());
|
|
|
|
return time_point.time_since_epoch().count();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-03-03 14:55:38 +03:00
|
|
|
void BaseBlockData::tick(timestamp_t& stamp)
|
2016-02-16 23:21:12 +03:00
|
|
|
{
|
2016-07-31 19:20:58 +03:00
|
|
|
stamp = getCurrentTime();
|
2016-02-16 23:21:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Block::~Block()
|
|
|
|
{
|
2016-02-20 05:24:12 +03:00
|
|
|
if (this->type == BLOCK_TYPE_BLOCK)
|
|
|
|
{
|
|
|
|
if (this->isCleared())//this block was cleared by END_BLOCK macros
|
|
|
|
return;
|
|
|
|
if (!this->isFinished())
|
|
|
|
this->finish();
|
|
|
|
|
|
|
|
endBlock();
|
|
|
|
}
|
2016-02-16 23:25:12 +03:00
|
|
|
}
|