From 0d986a64646b561acbd7d3d1798ff01eafe06313 Mon Sep 17 00:00:00 2001 From: Sergey Yagovtsev Date: Wed, 24 Feb 2016 06:31:05 +0300 Subject: [PATCH] Move serialized block in header --- CMakeLists.txt | 1 + include/profiler/profiler.h | 23 ++++++++++++++++++++++- src/block.cpp | 3 +++ src/profile_manager.cpp | 24 ++++++++++++++++++++++++ src/profile_manager.h | 15 +-------------- 5 files changed, 51 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a9ae60c..81fb83b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,3 +29,4 @@ endif(UNIX) add_subdirectory(src) add_subdirectory(sample) +add_subdirectory(reader) \ No newline at end of file diff --git a/include/profiler/profiler.h b/include/profiler/profiler.h index 2926132..f29ece5 100644 --- a/include/profiler/profiler.h +++ b/include/profiler/profiler.h @@ -102,6 +102,8 @@ namespace profiler thread_id_t thread_id; BaseBlockData(color_t _color, block_type_t _type); + + timestamp_t duration() const { return (end - begin); } }; #pragma pack(pop) @@ -109,6 +111,7 @@ namespace profiler { const char *name; void tick(timestamp_t& stamp); + public: 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); } ~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 diff --git a/src/block.cpp b/src/block.cpp index 41cd5eb..e1114c6 100644 --- a/src/block.cpp +++ b/src/block.cpp @@ -42,5 +42,8 @@ Block::~Block() endBlock(); } + else{//for mark end equal begin + end = begin; + } } diff --git a/src/profile_manager.cpp b/src/profile_manager.cpp index 7df46b2..22031ef 100644 --- a/src/profile_manager.cpp +++ b/src/profile_manager.cpp @@ -34,7 +34,14 @@ SerilizedBlock::SerilizedBlock(Block* block): m_data = new char[m_size]; memcpy(&m_data[0], block, sizeof(BaseBlockData)); 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() @@ -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() { diff --git a/src/profile_manager.h b/src/profile_manager.h index f109e50..4b726d2 100644 --- a/src/profile_manager.h +++ b/src/profile_manager.h @@ -27,19 +27,6 @@ along with this program.If not, see . #include #include -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 { ProfileManager(); @@ -60,7 +47,7 @@ class ProfileManager void _internalInsertBlock(profiler::Block* _block); - typedef std::list serialized_list_t; + typedef std::list serialized_list_t; serialized_list_t m_blocks; public: static ProfileManager& instance();