2016-02-24 06:30:13 +03:00
|
|
|
#include "profiler/profiler.h"
|
|
|
|
#include <fstream>
|
|
|
|
#include <list>
|
|
|
|
#include <iostream>
|
2016-06-17 16:31:09 +03:00
|
|
|
#include <map>
|
|
|
|
#include <stack>
|
|
|
|
#include <vector>
|
2016-02-24 06:30:13 +03:00
|
|
|
|
2016-06-17 16:31:09 +03:00
|
|
|
struct BlocksTree
|
2016-02-24 06:30:13 +03:00
|
|
|
{
|
2016-06-17 16:31:09 +03:00
|
|
|
profiler::SerilizedBlock* node;
|
|
|
|
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;
|
|
|
|
}
|
2016-02-24 06:30:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
std::ifstream inFile("test.prof", std::fstream::binary);
|
|
|
|
|
|
|
|
if (!inFile.is_open()){
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-06-17 16:31:09 +03:00
|
|
|
//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;
|
2016-02-24 06:30:13 +03:00
|
|
|
while (!inFile.eof()){
|
|
|
|
uint16_t sz = 0;
|
|
|
|
inFile.read((char*)&sz, sizeof(sz));
|
|
|
|
if (sz == 0)
|
|
|
|
{
|
|
|
|
inFile.read((char*)&sz, sizeof(sz));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
char* data = new char[sz];
|
|
|
|
inFile.read((char*)&data[0], sz);
|
2016-06-17 16:31:09 +03:00
|
|
|
profiler::BaseBlockData* baseData = (profiler::BaseBlockData*)data;
|
2016-02-24 06:30:13 +03:00
|
|
|
|
2016-06-17 16:31:09 +03:00
|
|
|
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()];
|
2016-02-24 06:30:13 +03:00
|
|
|
|
2016-06-17 16:31:09 +03:00
|
|
|
if (currentRoot.node == nullptr){
|
|
|
|
threaded_trees[baseData->getThreadId()] = tree;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete[] data;
|
|
|
|
|
|
|
|
//blocksList.emplace_back(sz, data);
|
|
|
|
}
|
|
|
|
|
2016-02-24 06:30:13 +03:00
|
|
|
return 0;
|
|
|
|
}
|