2016-02-16 23:21:12 +03:00
|
|
|
#include "profiler/profiler.h"
|
|
|
|
|
|
|
|
#include <ctime>
|
|
|
|
#include <chrono>
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
using namespace profiler;
|
|
|
|
|
|
|
|
const int NAME_LENGTH = 64;
|
|
|
|
|
|
|
|
const unsigned char MARK_TYPE_LOCAL_EVENT = 1;
|
|
|
|
const unsigned char MARK_TYPE_GLOBAL_EVENT = 2;
|
|
|
|
const unsigned char MARK_TYPE_BEGIN = 3;
|
|
|
|
const unsigned char MARK_TYPE_END = 4;
|
|
|
|
|
|
|
|
Mark::Mark(const char* _name, color_t _color) :
|
2016-02-17 23:43:37 +03:00
|
|
|
type(0),
|
|
|
|
color(_color),
|
|
|
|
begin(0),
|
|
|
|
thread_id(0),
|
|
|
|
name(_name)
|
2016-02-16 23:21:12 +03:00
|
|
|
{
|
|
|
|
tick(begin);
|
2016-02-17 23:24:35 +03:00
|
|
|
thread_id = std::hash<std::thread::id>()(std::this_thread::get_id());
|
2016-02-16 23:21:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Mark::tick(timestamp_t& stamp)
|
|
|
|
{
|
|
|
|
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());
|
|
|
|
stamp = time_point.time_since_epoch().count();
|
|
|
|
}
|
|
|
|
|
|
|
|
Block::Block(const char* _name, color_t _color) :
|
2016-02-17 23:43:37 +03:00
|
|
|
Mark(_name, _color),
|
2016-02-18 19:27:17 +03:00
|
|
|
end(0)
|
2016-02-16 23:21:12 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Block::~Block()
|
|
|
|
{
|
2016-02-18 19:27:17 +03:00
|
|
|
if (this->isCleared())
|
|
|
|
return;
|
|
|
|
if (!this->isFinished())
|
|
|
|
this->finish();
|
|
|
|
|
|
|
|
endBlock();
|
2016-02-16 23:25:12 +03:00
|
|
|
}
|