mirror of
https://github.com/yse/easy_profiler.git
synced 2024-12-28 01:04:41 +08:00
New target with disabled profiler
This commit is contained in:
parent
e525df5254
commit
0e26850408
@ -8,13 +8,18 @@ set(SOURCES
|
|||||||
${CPP_FILES}
|
${CPP_FILES}
|
||||||
)
|
)
|
||||||
|
|
||||||
add_definitions(
|
|
||||||
#-DFULL_DISABLE_PROFILER
|
|
||||||
)
|
|
||||||
add_executable(${PROJECT_NAME} ${SOURCES})
|
add_executable(${PROJECT_NAME} ${SOURCES})
|
||||||
|
|
||||||
|
set(DISABLED_PROFILER_NAME
|
||||||
|
"${PROJECT_NAME}_disabled_profiler"
|
||||||
|
)
|
||||||
|
add_executable(${DISABLED_PROFILER_NAME} ${SOURCES})
|
||||||
|
|
||||||
if(UNIX)
|
if(UNIX)
|
||||||
set(SPEC_LIB pthread)
|
set(SPEC_LIB pthread)
|
||||||
endif(UNIX)
|
endif(UNIX)
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME} easy_profiler ${SPEC_LIB})
|
target_link_libraries(${PROJECT_NAME} easy_profiler ${SPEC_LIB})
|
||||||
|
target_link_libraries(${DISABLED_PROFILER_NAME} easy_profiler ${SPEC_LIB})
|
||||||
|
|
||||||
|
target_compile_definitions(${DISABLED_PROFILER_NAME} PRIVATE FULL_DISABLE_PROFILER)
|
||||||
|
@ -4,6 +4,12 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <condition_variable>
|
||||||
|
#include "profiler/reader.h"
|
||||||
|
|
||||||
|
std::condition_variable cv;
|
||||||
|
std::mutex cv_m;
|
||||||
|
int g_i = 0;
|
||||||
|
|
||||||
void loadingResources(){
|
void loadingResources(){
|
||||||
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Lightcyan);
|
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Lightcyan);
|
||||||
@ -62,6 +68,8 @@ void frame(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loadingResourcesThread(){
|
void loadingResourcesThread(){
|
||||||
|
std::unique_lock<std::mutex> lk(cv_m);
|
||||||
|
cv.wait(lk, []{return g_i == 1; });
|
||||||
for(int i = 0; i < 10; i++){
|
for(int i = 0; i < 10; i++){
|
||||||
loadingResources();
|
loadingResources();
|
||||||
PROFILER_ADD_EVENT_GROUPED("Resources Loading!",profiler::colors::Cyan);
|
PROFILER_ADD_EVENT_GROUPED("Resources Loading!",profiler::colors::Cyan);
|
||||||
@ -70,13 +78,17 @@ void loadingResourcesThread(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void modellingThread(){
|
void modellingThread(){
|
||||||
for (int i = 0; i < 160000; i++){
|
std::unique_lock<std::mutex> lk(cv_m);
|
||||||
|
cv.wait(lk, []{return g_i == 1; });
|
||||||
|
for (int i = 0; i < 1600; i++){
|
||||||
modellingStep();
|
modellingStep();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void renderThread(){
|
void renderThread(){
|
||||||
for (int i = 0; i < 100000; i++){
|
std::unique_lock<std::mutex> lk(cv_m);
|
||||||
|
cv.wait(lk, []{return g_i == 1; });
|
||||||
|
for (int i = 0; i < 1000; i++){
|
||||||
frame();
|
frame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,7 +96,7 @@ void renderThread(){
|
|||||||
void four()
|
void four()
|
||||||
{
|
{
|
||||||
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Red);
|
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Red);
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
std::this_thread::sleep_for(std::chrono::milliseconds(37));
|
||||||
}
|
}
|
||||||
|
|
||||||
void five()
|
void five()
|
||||||
@ -95,7 +107,7 @@ void five()
|
|||||||
void six()
|
void six()
|
||||||
{
|
{
|
||||||
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Red);
|
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Red);
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
std::this_thread::sleep_for(std::chrono::milliseconds(42));
|
||||||
}
|
}
|
||||||
|
|
||||||
void three()
|
void three()
|
||||||
@ -109,13 +121,13 @@ void three()
|
|||||||
void seven()
|
void seven()
|
||||||
{
|
{
|
||||||
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Red);
|
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Red);
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
std::this_thread::sleep_for(std::chrono::milliseconds(147));
|
||||||
}
|
}
|
||||||
|
|
||||||
void two()
|
void two()
|
||||||
{
|
{
|
||||||
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Red);
|
PROFILER_BEGIN_FUNCTION_BLOCK_GROUPED(profiler::colors::Red);
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
std::this_thread::sleep_for(std::chrono::milliseconds(26));
|
||||||
}
|
}
|
||||||
|
|
||||||
void one()
|
void one()
|
||||||
@ -141,27 +153,42 @@ int main()
|
|||||||
auto start = std::chrono::system_clock::now();
|
auto start = std::chrono::system_clock::now();
|
||||||
PROFILER_ENABLE;
|
PROFILER_ENABLE;
|
||||||
|
|
||||||
one();
|
//one();
|
||||||
/*std::thread render = std::thread(renderThread);
|
//one();
|
||||||
|
/**/
|
||||||
|
std::vector<std::thread> threads;
|
||||||
|
|
||||||
|
std::thread render = std::thread(renderThread);
|
||||||
std::thread modelling = std::thread(modellingThread);
|
std::thread modelling = std::thread(modellingThread);
|
||||||
|
|
||||||
std::vector<std::thread> threads;
|
|
||||||
for(int i=0; i < 3; i++){
|
for(int i=0; i < 3; i++){
|
||||||
threads.emplace_back(std::thread(loadingResourcesThread));
|
threads.emplace_back(std::thread(loadingResourcesThread));
|
||||||
|
threads.emplace_back(std::thread(renderThread));
|
||||||
|
threads.emplace_back(std::thread(modellingThread));
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lk(cv_m);
|
||||||
|
g_i = 1;
|
||||||
|
}
|
||||||
|
cv.notify_all();
|
||||||
|
|
||||||
render.join();
|
render.join();
|
||||||
modelling.join();
|
modelling.join();
|
||||||
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);
|
||||||
|
|
||||||
std::cout << elapsed.count() << " usec" << std::endl;
|
std::cout << elapsed.count() << " usec" << std::endl;
|
||||||
//block count ~810
|
|
||||||
|
thread_blocks_tree_t threaded_trees;
|
||||||
|
int blocks_counter = fillTreesFromFile("test.prof", threaded_trees);
|
||||||
|
std::cout << "Blocks count: " << blocks_counter << std::endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user