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-06-17 18:09:40 +03:00
|
|
|
#include <iterator>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <ctime>
|
|
|
|
#include <chrono>
|
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;
|
2016-06-19 22:28:17 +03:00
|
|
|
std::vector<BlocksTree > children;
|
2016-06-19 22:37:17 +03:00
|
|
|
|
2016-06-17 16:31:09 +03:00
|
|
|
BlocksTree(){
|
|
|
|
node = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-06-19 22:28:17 +03:00
|
|
|
BlocksTree(BlocksTree&& that)
|
|
|
|
{
|
|
|
|
makeMove(std::forward<BlocksTree&&>(that));
|
|
|
|
}
|
2016-06-17 16:31:09 +03:00
|
|
|
|
2016-06-19 22:28:17 +03:00
|
|
|
BlocksTree& operator=(BlocksTree&& that)
|
|
|
|
{
|
|
|
|
makeMove(std::forward<BlocksTree&&>(that));
|
|
|
|
return *this;
|
2016-06-17 16:31:09 +03:00
|
|
|
}
|
2016-06-19 22:28:17 +03:00
|
|
|
|
2016-06-17 16:31:09 +03:00
|
|
|
~BlocksTree(){
|
|
|
|
if (node){
|
|
|
|
delete node;
|
|
|
|
}
|
|
|
|
node = nullptr;
|
2016-06-17 18:09:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator < (const BlocksTree& other) const
|
|
|
|
{
|
|
|
|
if (!node || !other.node){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return node->block()->getBegin() < other.node->block()->getBegin();
|
2016-06-17 16:31:09 +03:00
|
|
|
}
|
2016-06-19 22:28:17 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
void makeMove(BlocksTree&& that)
|
|
|
|
{
|
|
|
|
node = that.node;
|
|
|
|
children = std::move(that.children);
|
|
|
|
|
|
|
|
that.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
|
|
|
typedef std::map<size_t, BlocksTree> thread_blocks_tree_t;
|
|
|
|
|
|
|
|
thread_blocks_tree_t threaded_trees;
|
2016-06-17 18:09:40 +03:00
|
|
|
|
|
|
|
int blocks_counter = 0;
|
2016-06-19 22:28:17 +03:00
|
|
|
|
2016-06-17 18:09:40 +03:00
|
|
|
auto start = std::chrono::system_clock::now();
|
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 18:09:40 +03:00
|
|
|
BlocksTree& root = threaded_trees[baseData->getThreadId()];
|
|
|
|
|
2016-06-17 16:31:09 +03:00
|
|
|
BlocksTree tree;
|
|
|
|
tree.node = new profiler::SerilizedBlock(sz, data);
|
2016-06-17 18:09:40 +03:00
|
|
|
blocks_counter++;
|
|
|
|
|
|
|
|
if (root.children.empty()){
|
|
|
|
root.children.push_back(std::move(tree));
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
BlocksTree& back = root.children.back();
|
|
|
|
auto t1 = back.node->block()->getEnd();
|
|
|
|
auto mt0 = tree.node->block()->getBegin();
|
2016-06-19 22:28:17 +03:00
|
|
|
if (mt0 < t1)//parent - starts earlier than last ends
|
2016-06-17 18:09:40 +03:00
|
|
|
{
|
|
|
|
auto lower = std::lower_bound(root.children.begin(), root.children.end(), tree);
|
2016-06-17 16:31:09 +03:00
|
|
|
|
2016-06-17 18:09:40 +03:00
|
|
|
std::move(lower, root.children.end(), std::back_inserter(tree.children));
|
|
|
|
|
|
|
|
root.children.erase(lower, root.children.end());
|
2016-02-24 06:30:13 +03:00
|
|
|
|
2016-06-17 18:09:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
root.children.push_back(std::move(tree));
|
2016-06-17 16:31:09 +03:00
|
|
|
}
|
2016-06-17 18:09:40 +03:00
|
|
|
|
2016-06-17 16:31:09 +03:00
|
|
|
|
|
|
|
delete[] data;
|
|
|
|
|
|
|
|
}
|
2016-06-17 18:09:40 +03:00
|
|
|
auto end = std::chrono::system_clock::now();
|
|
|
|
|
|
|
|
std::cout << "Blocks count: " << blocks_counter << std::endl;
|
2016-06-17 18:49:09 +03:00
|
|
|
std::cout << "dT = " << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() << " usec" << std::endl;
|
2016-02-24 06:30:13 +03:00
|
|
|
return 0;
|
|
|
|
}
|