mirror of
https://github.com/yse/easy_profiler.git
synced 2025-01-14 00:27:55 +08:00
Create tree structure
This commit is contained in:
parent
5f96b6403c
commit
7713f91500
@ -286,6 +286,7 @@ namespace profiler
|
|||||||
SerilizedBlock(profiler::Block* block);
|
SerilizedBlock(profiler::Block* block);
|
||||||
SerilizedBlock(uint16_t _size, const char* _data);
|
SerilizedBlock(uint16_t _size, const char* _data);
|
||||||
SerilizedBlock(SerilizedBlock&& that);
|
SerilizedBlock(SerilizedBlock&& that);
|
||||||
|
SerilizedBlock(const SerilizedBlock& other);
|
||||||
~SerilizedBlock();
|
~SerilizedBlock();
|
||||||
|
|
||||||
const char* const data() const { return m_data; }
|
const char* const data() const { return m_data; }
|
||||||
|
@ -2,12 +2,35 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <map>
|
||||||
|
#include <stack>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
template<class T>
|
struct BlocksTree
|
||||||
struct tree
|
|
||||||
{
|
{
|
||||||
typedef tree<T> tree_t;
|
profiler::SerilizedBlock* node;
|
||||||
tree_t* parent;
|
std::vector<BlocksTree> 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()
|
int main()
|
||||||
@ -18,7 +41,15 @@ int main()
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<profiler::SerilizedBlock> blocksList;
|
//std::list<profiler::SerilizedBlock> blocksList;
|
||||||
|
typedef std::map<profiler::timestamp_t, profiler::SerilizedBlock> blocks_map_t;
|
||||||
|
typedef std::map<size_t, blocks_map_t> thread_map_t;
|
||||||
|
typedef std::map<size_t, BlocksTree> thread_blocks_tree_t;
|
||||||
|
thread_map_t blocksList;
|
||||||
|
|
||||||
|
|
||||||
|
BlocksTree root;
|
||||||
|
thread_blocks_tree_t threaded_trees;
|
||||||
while (!inFile.eof()){
|
while (!inFile.eof()){
|
||||||
uint16_t sz = 0;
|
uint16_t sz = 0;
|
||||||
inFile.read((char*)&sz, sizeof(sz));
|
inFile.read((char*)&sz, sizeof(sz));
|
||||||
@ -29,15 +60,28 @@ int main()
|
|||||||
}
|
}
|
||||||
char* data = new char[sz];
|
char* data = new char[sz];
|
||||||
inFile.read((char*)&data[0], sz);
|
inFile.read((char*)&data[0], sz);
|
||||||
blocksList.emplace_back(sz, data);
|
profiler::BaseBlockData* baseData = (profiler::BaseBlockData*)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;
|
|
||||||
|
|
||||||
}
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -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)
|
SerilizedBlock::SerilizedBlock(SerilizedBlock&& that)
|
||||||
{
|
{
|
||||||
m_size = that.m_size;
|
m_size = that.m_size;
|
||||||
@ -100,7 +107,7 @@ void ProfileManager::beginBlock(Block* _block)
|
|||||||
{
|
{
|
||||||
if (!m_isEnabled)
|
if (!m_isEnabled)
|
||||||
return;
|
return;
|
||||||
if (_block->getType() != BLOCK_TYPE_EVENT){
|
if (BLOCK_TYPE_BLOCK == _block->getType()){
|
||||||
guard_lock_t lock(m_spin);
|
guard_lock_t lock(m_spin);
|
||||||
m_openedBracketsMap[_block->getThreadId()].push(_block);
|
m_openedBracketsMap[_block->getThreadId()].push(_block);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user