0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-28 01:04:41 +08:00
easy_profiler/src/block.cpp

50 lines
1014 B
C++
Raw Normal View History

2016-02-16 23:21:12 +03:00
#include "profiler/profiler.h"
#include <ctime>
#include <chrono>
#include <thread>
using namespace profiler;
BaseBlockData::BaseBlockData(color_t _color, block_type_t _type) :
type(_type),
2016-02-17 23:43:37 +03:00
color(_color),
begin(0),
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);
if (this->type == BLOCK_TYPE_EVENT)
{
end = 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 BaseBlockData::tick(timestamp_t& stamp)
2016-02-16 23:21:12 +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());
stamp = time_point.time_since_epoch().count();
}
Block::~Block()
{
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
}