main.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #include <easy/profiler.h>
  2. #include <easy/reader.h>
  3. #include <fstream>
  4. #include <list>
  5. #include <iostream>
  6. #include <map>
  7. #include <stack>
  8. #include <vector>
  9. #include <iterator>
  10. #include <algorithm>
  11. #include <ctime>
  12. #include <chrono>
  13. #include <iostream>
  14. #include <string>
  15. #include <sstream>
  16. class TreePrinter
  17. {
  18. struct Info{
  19. std::string name;
  20. std::string info;
  21. };
  22. std::vector<Info> m_rows;
  23. public:
  24. TreePrinter(){
  25. }
  26. void addNewRow(int level)
  27. {
  28. }
  29. void printTree()
  30. {
  31. for (auto& row : m_rows){
  32. std::cout << row.name << " " << row.info << std::endl;
  33. }
  34. }
  35. };
  36. void printTree(TreePrinter& printer, const ::profiler::BlocksTree& tree, int level = 0, profiler::timestamp_t parent_dur = 0, profiler::timestamp_t root_dur = 0)
  37. {
  38. //
  39. //if (tree.node){
  40. // auto duration = tree.node->block()->duration();
  41. // float duration_ms = duration / 1e6f;
  42. // float percent = parent_dur ? float(duration) / float(parent_dur)*100.0f : 100.0f;
  43. // float rpercent = root_dur ? float(duration) / float(root_dur)*100.0f : 100.0f;
  44. // std::cout << std::string(level, '\t') << tree.node->getName()
  45. // << std::string(5 - level, '\t')
  46. // /*<< std::string(level, ' ')*/ << percent << "%| "
  47. // << rpercent << "%| "
  48. // << duration_ms << " ms"
  49. // << std::endl;
  50. // if (root_dur == 0){
  51. // root_dur = tree.node->block()->duration();
  52. // }
  53. //}
  54. //else{
  55. // root_dur = 0;
  56. //}
  57. //
  58. //for (const auto& i : tree.children){
  59. // printTree(printer, i, level + 1, tree.node ? tree.node->block()->duration() : 0, root_dur);
  60. //}
  61. }
  62. int main(int argc, char* argv[])
  63. {
  64. ::profiler::thread_blocks_tree_t threaded_trees;
  65. ::std::string filename;// = "test.prof";
  66. if (argc > 1 && argv[1])
  67. {
  68. filename = argv[1];
  69. }
  70. else
  71. {
  72. std::cout << "Specify prof file: ";
  73. std::getline(std::cin, filename);
  74. //return 255;
  75. }
  76. ::std::string dump_filename;
  77. if (argc > 2 && argv[2])
  78. {
  79. dump_filename = argv[2];
  80. }
  81. else
  82. {
  83. std::cout << "Specify output prof file: ";
  84. std::getline(std::cin, dump_filename);
  85. }
  86. if (dump_filename.size() > 2)
  87. {
  88. EASY_PROFILER_ENABLE;
  89. std::cout << "Will dump reader prof file to " << dump_filename << std::endl;
  90. }
  91. else
  92. {
  93. dump_filename.clear();
  94. }
  95. auto start = std::chrono::system_clock::now();
  96. ::profiler::SerializedData serialized_blocks, serialized_descriptors;
  97. ::profiler::descriptors_list_t descriptors;
  98. ::profiler::blocks_t blocks;
  99. ::std::stringstream errorMessage;
  100. uint32_t descriptorsNumberInFile = 0;
  101. uint32_t version = 0;
  102. auto blocks_counter = fillTreesFromFile(filename.c_str(), serialized_blocks, serialized_descriptors, descriptors, blocks,
  103. threaded_trees, descriptorsNumberInFile, version, true, errorMessage);
  104. if (blocks_counter == 0)
  105. std::cout << "Can not read blocks from file " << filename.c_str() << "\nReason: " << errorMessage.str();
  106. auto end = std::chrono::system_clock::now();
  107. std::cout << "Blocks count: " << blocks_counter << std::endl;
  108. std::cout << "dT = " << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() << " usec" << std::endl;
  109. //for (const auto & i : threaded_trees){
  110. // TreePrinter p;
  111. // std::cout << std::string(20, '=') << " thread "<< i.first << " "<< std::string(20, '=') << std::endl;
  112. // printTree(p, i.second.tree,-1);
  113. //}
  114. if (!dump_filename.empty())
  115. {
  116. auto bcount = profiler::dumpBlocksToFile(dump_filename.c_str());
  117. std::cout << "Blocks count for reader: " << bcount << std::endl;
  118. }
  119. //char c;
  120. //::std::cin >> c;
  121. return 0;
  122. }