0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-27 08:41:02 +08:00

Move serialized block in header

This commit is contained in:
Sergey Yagovtsev 2016-02-24 06:31:05 +03:00
parent c6c09dbe32
commit 0d986a6464
5 changed files with 51 additions and 15 deletions

View File

@ -29,3 +29,4 @@ endif(UNIX)
add_subdirectory(src) add_subdirectory(src)
add_subdirectory(sample) add_subdirectory(sample)
add_subdirectory(reader)

View File

@ -102,6 +102,8 @@ namespace profiler
thread_id_t thread_id; thread_id_t thread_id;
BaseBlockData(color_t _color, block_type_t _type); BaseBlockData(color_t _color, block_type_t _type);
timestamp_t duration() const { return (end - begin); }
}; };
#pragma pack(pop) #pragma pack(pop)
@ -109,6 +111,7 @@ namespace profiler
{ {
const char *name; const char *name;
void tick(timestamp_t& stamp); void tick(timestamp_t& stamp);
public: public:
Block(const char* _name, color_t _color = 0, block_type_t _type = BLOCK_TYPE_MARK); Block(const char* _name, color_t _color = 0, block_type_t _type = BLOCK_TYPE_MARK);
@ -125,8 +128,26 @@ namespace profiler
inline void finish(){ tick(end); } inline void finish(){ tick(end); }
~Block(); ~Block();
}; };
class PROFILER_API SerilizedBlock
{
uint16_t m_size;
char* m_data;
public:
SerilizedBlock(profiler::Block* block);
SerilizedBlock(uint16_t _size, const char* _data);
SerilizedBlock(SerilizedBlock&& that);
~SerilizedBlock();
const char* const data() const { return m_data; }
uint16_t size() const { return m_size; }
const BaseBlockData * block();
const char* getBlockName();
};
} }
#endif #endif

View File

@ -42,5 +42,8 @@ Block::~Block()
endBlock(); endBlock();
} }
else{//for mark end equal begin
end = begin;
}
} }

View File

@ -34,7 +34,14 @@ SerilizedBlock::SerilizedBlock(Block* block):
m_data = new char[m_size]; m_data = new char[m_size];
memcpy(&m_data[0], block, sizeof(BaseBlockData)); memcpy(&m_data[0], block, sizeof(BaseBlockData));
strncpy(&m_data[sizeof(BaseBlockData)], block->getName(), name_len); strncpy(&m_data[sizeof(BaseBlockData)], block->getName(), name_len);
}
SerilizedBlock::SerilizedBlock(uint16_t _size, const char* _data) :
m_size(_size),
m_data(nullptr)
{
m_data = new char[m_size];
memcpy(&m_data[0], _data, m_size);
} }
SerilizedBlock::~SerilizedBlock() SerilizedBlock::~SerilizedBlock()
@ -45,6 +52,23 @@ SerilizedBlock::~SerilizedBlock()
} }
} }
SerilizedBlock::SerilizedBlock(SerilizedBlock&& that)
{
m_size = that.m_size;
m_data = that.m_data;
that.m_size = 0;
that.m_data = nullptr;
}
const BaseBlockData * SerilizedBlock::block()
{
return (BaseBlockData*)m_data;
}
const char* SerilizedBlock::getBlockName()
{
return (const char*)&m_data[sizeof(profiler::BaseBlockData)];
}
ProfileManager::ProfileManager() ProfileManager::ProfileManager()
{ {

View File

@ -27,19 +27,6 @@ along with this program.If not, see <http://www.gnu.org/licenses/>.
#include <map> #include <map>
#include <list> #include <list>
class SerilizedBlock
{
uint16_t m_size;
char* m_data;
public:
SerilizedBlock(profiler::Block* block);
~SerilizedBlock();
const char* const data() { return m_data; }
uint16_t size() const { return m_size; }
};
class ProfileManager class ProfileManager
{ {
ProfileManager(); ProfileManager();
@ -60,7 +47,7 @@ class ProfileManager
void _internalInsertBlock(profiler::Block* _block); void _internalInsertBlock(profiler::Block* _block);
typedef std::list<SerilizedBlock*> serialized_list_t; typedef std::list<profiler::SerilizedBlock*> serialized_list_t;
serialized_list_t m_blocks; serialized_list_t m_blocks;
public: public:
static ProfileManager& instance(); static ProfileManager& instance();