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

More info in reader

This commit is contained in:
Sergey Yagovtsev 2016-06-20 23:33:14 +03:00
parent be11666ea3
commit 4d1d66a405
2 changed files with 80 additions and 6 deletions

View File

@ -13,14 +13,28 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
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){ 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){ 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 << "Blocks count: " << blocks_counter << std::endl;
std::cout << "dT = " << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() << " usec" << std::endl; std::cout << "dT = " << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() << " usec" << std::endl;
for (const auto & i : threaded_trees){ 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; return 0;
} }

View File

@ -80,12 +80,69 @@ void renderThread(){
frame(); 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() int main()
{ {
auto start = std::chrono::system_clock::now(); auto start = std::chrono::system_clock::now();
PROFILER_ENABLE; PROFILER_ENABLE;
std::thread render = std::thread(renderThread); one();
/*std::thread render = std::thread(renderThread);
std::thread modelling = std::thread(modellingThread); std::thread modelling = std::thread(modellingThread);
std::vector<std::thread> threads; std::vector<std::thread> threads;
@ -98,6 +155,8 @@ int main()
for(auto& t : threads){ for(auto& t : threads){
t.join(); t.join();
} }
*/
auto end = std::chrono::system_clock::now(); auto end = std::chrono::system_clock::now();
auto elapsed = auto elapsed =
std::chrono::duration_cast<std::chrono::microseconds>(end - start); std::chrono::duration_cast<std::chrono::microseconds>(end - start);