2016-02-24 06:30:13 +03:00
|
|
|
#include "profiler/profiler.h"
|
2016-06-19 23:01:49 +03:00
|
|
|
#include "profiler/reader.h"
|
2016-02-24 06:30:13 +03:00
|
|
|
#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-06-19 23:46:42 +03:00
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
|
2016-06-20 23:33:14 +03:00
|
|
|
void printTree(const BlocksTree& tree, int level = 0, int parent_dur=0, int root_dur=0)
|
2016-06-19 23:46:42 +03:00
|
|
|
{
|
2016-06-20 23:33:14 +03:00
|
|
|
|
2016-06-19 23:46:42 +03:00
|
|
|
if (tree.node){
|
2016-06-20 23:33:14 +03:00
|
|
|
float percent = parent_dur ? float(tree.node->block()->duration()) / float(parent_dur)*100.0f : 100.0f;
|
|
|
|
float rpercent = root_dur ? float(tree.node->block()->duration()) / float(root_dur)*100.0f : 100.0f;
|
|
|
|
std::cout << std::string(level, '\t') << tree.node->getBlockName()
|
|
|
|
<< std::string(5 - level, '\t')
|
|
|
|
<< std::string(level, ' ') << percent << " | " << rpercent << " %"
|
|
|
|
<< std::endl;
|
|
|
|
if (root_dur == 0){
|
|
|
|
root_dur = tree.node->block()->duration();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
root_dur = 0;
|
|
|
|
}
|
|
|
|
|
2016-06-19 23:46:42 +03:00
|
|
|
|
|
|
|
for (const auto& i : tree.children){
|
2016-06-20 23:33:14 +03:00
|
|
|
|
|
|
|
printTree(i, level + 1, tree.node? tree.node->block()->duration() : 0, root_dur);
|
2016-06-19 23:46:42 +03:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
thread_blocks_tree_t threaded_trees;
|
2016-06-17 18:09:40 +03:00
|
|
|
|
|
|
|
auto start = std::chrono::system_clock::now();
|
2016-02-24 06:30:13 +03:00
|
|
|
|
2016-06-19 23:46:42 +03:00
|
|
|
int blocks_counter = fillTreesFromFile("test.prof", threaded_trees);
|
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-06-19 23:46:42 +03:00
|
|
|
for (const auto & i : threaded_trees){
|
2016-06-20 23:33:14 +03:00
|
|
|
std::cout << std::string(20, '=') << " thread "<< i.first << " "<< std::string(20, '=') << std::endl;
|
|
|
|
printTree(i.second,-1);
|
2016-06-19 23:46:42 +03:00
|
|
|
}
|
2016-02-24 06:30:13 +03:00
|
|
|
return 0;
|
|
|
|
}
|