From 99fa9ffc5ddb8cf8e0e743ea172568d8b1257dde Mon Sep 17 00:00:00 2001 From: Sergey Yagovtsev Date: Tue, 21 Jun 2016 22:08:11 +0300 Subject: [PATCH] Add info about duration in ms --- reader/main.cpp | 50 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/reader/main.cpp b/reader/main.cpp index 4b4ec41..50bd88a 100644 --- a/reader/main.cpp +++ b/reader/main.cpp @@ -13,15 +13,46 @@ #include #include -void printTree(const BlocksTree& tree, int level = 0, int parent_dur=0, int root_dur=0) + +class TreePrinter +{ + struct Info{ + std::string name; + std::string info; + }; + std::vector m_rows; + +public: + TreePrinter(){ + + } + void addNewRow(int level) + { + + } + + void printTree() + { + for (auto& row : m_rows){ + std::cout << row.name << " " << row.info << std::endl; + } + } +}; + + +void printTree(TreePrinter& printer, const BlocksTree& tree, int level = 0, int parent_dur = 0, profiler::timestamp_t root_dur = 0) { if (tree.node){ - 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; + 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->getBlockName() << std::string(5 - level, '\t') - << std::string(level, ' ') << percent << " | " << rpercent << " %" + /*<< std::string(level, ' ')*/ << percent << "%| " + << rpercent << "%| " + << duration_ms << " ms" << std::endl; if (root_dur == 0){ root_dur = tree.node->block()->duration(); @@ -34,18 +65,12 @@ void printTree(const BlocksTree& tree, int level = 0, int parent_dur=0, int root for (const auto& i : tree.children){ - printTree(i, level + 1, tree.node? tree.node->block()->duration() : 0, root_dur); + printTree(printer, i, level + 1, tree.node ? tree.node->block()->duration() : 0, root_dur); } } int main() { - std::ifstream inFile("test.prof", std::fstream::binary); - - if (!inFile.is_open()){ - return -1; - } - thread_blocks_tree_t threaded_trees; auto start = std::chrono::system_clock::now(); @@ -57,8 +82,9 @@ int main() std::cout << "Blocks count: " << blocks_counter << std::endl; std::cout << "dT = " << std::chrono::duration_cast(end - start).count() << " usec" << std::endl; for (const auto & i : threaded_trees){ + TreePrinter p; std::cout << std::string(20, '=') << " thread "<< i.first << " "<< std::string(20, '=') << std::endl; - printTree(i.second,-1); + printTree(p, i.second,-1); } return 0; }