0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-27 08:41:02 +08:00

152 lines
4.0 KiB
C++
Raw Normal View History

#include <easy/profiler.h>
#include <easy/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>
#include <sstream>
2016-06-21 22:08:11 +03:00
class TreePrinter
{
2016-09-06 22:23:55 +03:00
struct Info{
std::string name;
std::string info;
};
std::vector<Info> m_rows;
2016-06-21 22:08:11 +03:00
public:
2016-09-06 22:23:55 +03:00
TreePrinter(){
2016-06-21 22:08:11 +03:00
2016-09-06 22:23:55 +03:00
}
void addNewRow(int level)
{
2016-06-21 22:08:11 +03:00
2016-09-06 22:23:55 +03:00
}
2016-06-21 22:08:11 +03:00
2016-09-06 22:23:55 +03:00
void printTree()
{
for (auto& row : m_rows){
std::cout << row.name << " " << row.info << std::endl;
}
}
2016-06-21 22:08:11 +03:00
};
void printTree(TreePrinter& printer, const profiler::BlocksTree& tree, int level = 0, profiler::timestamp_t parent_dur = 0, profiler::timestamp_t root_dur = 0)
2016-06-19 23:46:42 +03:00
{
2016-09-06 22:23:55 +03:00
//
//if (tree.node){
// auto duration = tree.node->block()->duration();
// float duration_ms = duration / 1e6f;
// float percent = parent_dur ? float(duration) / float(parent_dur)*100.0f : 100.0f;
// float rpercent = root_dur ? float(duration) / float(root_dur)*100.0f : 100.0f;
// std::cout << std::string(level, '\t') << tree.node->getName()
// << std::string(5 - level, '\t')
// /*<< std::string(level, ' ')*/ << percent << "%| "
// << rpercent << "%| "
// << duration_ms << " ms"
// << std::endl;
// if (root_dur == 0){
// root_dur = tree.node->block()->duration();
// }
//}
//else{
// root_dur = 0;
//}
//
//for (const auto& i : tree.children){
// printTree(printer, 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(int argc, char* argv[])
2016-02-24 06:30:13 +03:00
{
profiler::thread_blocks_tree_t threaded_trees;
2016-06-17 18:09:40 +03:00
::std::string filename;// = "test.prof";
if (argc > 1 && argv[1])
{
filename = argv[1];
}
else
{
std::cout << "Specify prof file: ";
std::getline(std::cin, filename);
//return 255;
}
::std::string dump_filename;
if (argc > 2 && argv[2])
{
dump_filename = argv[2];
}
else
{
std::cout << "Specify output prof file: ";
std::getline(std::cin, dump_filename);
}
if (dump_filename.size() > 2)
{
EASY_PROFILER_ENABLE;
std::cout << "Will dump reader prof file to " << dump_filename << std::endl;
}
else
{
dump_filename.clear();
}
auto start = std::chrono::system_clock::now();
2016-02-24 06:30:13 +03:00
profiler::SerializedData serialized_blocks, serialized_descriptors;
profiler::descriptors_list_t descriptors;
profiler::blocks_t blocks;
profiler::bookmarks_t bookmarks;
profiler::BeginEndTime beginEndTime;
std::stringstream errorMessage;
uint32_t descriptorsNumberInFile = 0;
uint32_t version = 0;
profiler::processid_t pid = 0;
auto blocks_counter = fillTreesFromFile(filename.c_str(), beginEndTime, serialized_blocks, serialized_descriptors,
descriptors, blocks, threaded_trees, bookmarks, descriptorsNumberInFile,
version, pid, true, errorMessage);
if (blocks_counter == 0)
std::cout << "Can not read blocks from file " << filename.c_str() << "\nReason: " << errorMessage.str();
2016-06-17 18:09:40 +03:00
auto end = std::chrono::system_clock::now();
2016-06-17 18:09:40 +03:00
std::cout << "Blocks count: " << blocks_counter << std::endl;
std::cout << "dT = " << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() << " usec" << std::endl;
//for (const auto & i : threaded_trees){
2016-09-06 22:23:55 +03:00
// TreePrinter p;
// std::cout << std::string(20, '=') << " thread "<< i.first << " "<< std::string(20, '=') << std::endl;
// printTree(p, i.second.tree,-1);
//}
if (!dump_filename.empty())
{
auto bcount = profiler::dumpBlocksToFile(dump_filename.c_str());
std::cout << "Blocks count for reader: " << bcount << std::endl;
}
//char c;
//::std::cin >> c;
return 0;
2016-02-24 06:30:13 +03:00
}