From 4d1d66a405144fedda6b294b596682a2d8150ea6 Mon Sep 17 00:00:00 2001 From: Sergey Yagovtsev Date: Mon, 20 Jun 2016 23:33:14 +0300 Subject: [PATCH] More info in reader --- reader/main.cpp | 25 ++++++++++++++++---- sample/main.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 80 insertions(+), 6 deletions(-) diff --git a/reader/main.cpp b/reader/main.cpp index 001a9fc..4b4ec41 100644 --- a/reader/main.cpp +++ b/reader/main.cpp @@ -13,14 +13,28 @@ #include #include -void printTree(const BlocksTree& tree, int level = 0) +void printTree(const BlocksTree& tree, int level = 0, int parent_dur=0, int root_dur=0) { + if (tree.node){ - std::cout << std::string(level, '\t') << " "<< tree.node->getBlockName() << std::endl; - } + 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; + } + for (const auto& i : tree.children){ - printTree(i,level+1); + + printTree(i, level + 1, tree.node? tree.node->block()->duration() : 0, root_dur); } } @@ -43,7 +57,8 @@ 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){ - // printTree(i.second,-1); + std::cout << std::string(20, '=') << " thread "<< i.first << " "<< std::string(20, '=') << std::endl; + printTree(i.second,-1); } return 0; } diff --git a/sample/main.cpp b/sample/main.cpp index c07cbf9..a7d52ba 100644 --- a/sample/main.cpp +++ b/sample/main.cpp @@ -80,12 +80,69 @@ void renderThread(){ frame(); } } + +void four() +{ + PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Red); + std::this_thread::sleep_for(std::chrono::milliseconds(20)); +} + +void five() +{ + PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Red); + std::this_thread::sleep_for(std::chrono::milliseconds(20)); +} +void six() +{ + PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Red); + std::this_thread::sleep_for(std::chrono::milliseconds(20)); +} + +void three() +{ + PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Red); + four(); + five(); + six(); +} + +void seven() +{ + PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Red); + std::this_thread::sleep_for(std::chrono::milliseconds(20)); +} + +void two() +{ + PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Red); + std::this_thread::sleep_for(std::chrono::milliseconds(20)); +} + +void one() +{ + PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Red); + two(); + three(); + seven(); +} + +/* +one + two + three + four + five + six + seven + +*/ int main() { auto start = std::chrono::system_clock::now(); PROFILER_ENABLE; - std::thread render = std::thread(renderThread); + one(); + /*std::thread render = std::thread(renderThread); std::thread modelling = std::thread(modellingThread); std::vector threads; @@ -98,6 +155,8 @@ int main() for(auto& t : threads){ t.join(); } + */ + auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start);