From 7713f91500fb42c445ee966b87cf50d08932c55e Mon Sep 17 00:00:00 2001 From: Sergey Yagovtsev Date: Fri, 17 Jun 2016 16:31:09 +0300 Subject: [PATCH] Create tree structure --- include/profiler/profiler.h | 1 + reader/main.cpp | 70 ++++++++++++++++++++++++++++++------- src/profile_manager.cpp | 9 ++++- 3 files changed, 66 insertions(+), 14 deletions(-) diff --git a/include/profiler/profiler.h b/include/profiler/profiler.h index db31e68..e47d49a 100644 --- a/include/profiler/profiler.h +++ b/include/profiler/profiler.h @@ -286,6 +286,7 @@ namespace profiler SerilizedBlock(profiler::Block* block); SerilizedBlock(uint16_t _size, const char* _data); SerilizedBlock(SerilizedBlock&& that); + SerilizedBlock(const SerilizedBlock& other); ~SerilizedBlock(); const char* const data() const { return m_data; } diff --git a/reader/main.cpp b/reader/main.cpp index b70482d..ccc564b 100644 --- a/reader/main.cpp +++ b/reader/main.cpp @@ -2,12 +2,35 @@ #include #include #include +#include +#include +#include -template -struct tree +struct BlocksTree { - typedef tree tree_t; - tree_t* parent; + profiler::SerilizedBlock* node; + std::vector children; + BlocksTree* parent; + BlocksTree(){ + node = nullptr; + parent = nullptr; + } + BlocksTree(BlocksTree&& that){ + + node = that.node; + parent = that.parent; + + children = std::move(that.children); + + that.node = nullptr; + that.parent = nullptr; + } + ~BlocksTree(){ + if (node){ + delete node; + } + node = nullptr; + } }; int main() @@ -18,7 +41,15 @@ int main() return -1; } - std::list blocksList; + //std::list blocksList; + typedef std::map blocks_map_t; + typedef std::map thread_map_t; + typedef std::map thread_blocks_tree_t; + thread_map_t blocksList; + + + BlocksTree root; + thread_blocks_tree_t threaded_trees; while (!inFile.eof()){ uint16_t sz = 0; inFile.read((char*)&sz, sizeof(sz)); @@ -29,15 +60,28 @@ int main() } char* data = new char[sz]; inFile.read((char*)&data[0], sz); - blocksList.emplace_back(sz, data); - } - for (auto& i : blocksList){ - static auto thread_id = i.block()->getThreadId(); - //if (i.block()->thread_id == thread_id) - std::cout << i.block()->duration() << "\n"; - //std::cout << i.getBlockName() << ":" << (i.block()->end - i.block()->begin)/1000 << " usec." << std::endl; + profiler::BaseBlockData* baseData = (profiler::BaseBlockData*)data; - } + blocksList[baseData->getThreadId()].emplace( + baseData->getBegin(), + profiler::SerilizedBlock(sz, data)); + + + BlocksTree tree; + tree.node = new profiler::SerilizedBlock(sz, data); + root.children.push_back(std::move(tree)); + + BlocksTree currentRoot = threaded_trees[baseData->getThreadId()]; + + if (currentRoot.node == nullptr){ + threaded_trees[baseData->getThreadId()] = tree; + } + + delete[] data; + + //blocksList.emplace_back(sz, data); + } + return 0; } diff --git a/src/profile_manager.cpp b/src/profile_manager.cpp index da0a14b..4dff626 100644 --- a/src/profile_manager.cpp +++ b/src/profile_manager.cpp @@ -53,6 +53,13 @@ SerilizedBlock::~SerilizedBlock() } } +SerilizedBlock::SerilizedBlock(const SerilizedBlock& other) +{ + m_size = other.m_size; + m_data = new char[m_size]; + memcpy(&m_data[0], other.m_data, m_size); +} + SerilizedBlock::SerilizedBlock(SerilizedBlock&& that) { m_size = that.m_size; @@ -100,7 +107,7 @@ void ProfileManager::beginBlock(Block* _block) { if (!m_isEnabled) return; - if (_block->getType() != BLOCK_TYPE_EVENT){ + if (BLOCK_TYPE_BLOCK == _block->getType()){ guard_lock_t lock(m_spin); m_openedBracketsMap[_block->getThreadId()].push(_block); }