Custom profiler
-
Hi,
When compiling this for release, all TIC and TOCs are ignored and completely removed from the code by the compiler right??
#pragma once #ifdef _DEBUG #include <QElapsedTimer.h> #include <iostream> #define TIC Profiler::getInstance().startTimer(); #define TOC Profiler::getInstance().takeTime(); class Profiler { private: Profiler() { timer.start(); }; QElapsedTimer timer; public: ~Profiler() {}; static Profiler& getInstance() { static Profiler instance; return instance; } void startTimer() { timer.restart(); }; void takeTime() { std::cout << "time elapsed: " << timer.elapsed() << std::endl; }; }; #else #define TIC #define TOC #endif
-
Yes if _DEBUG is set for debug and not release.
-
Hi,
When compiling this for release, all TIC and TOCs are ignored and completely removed from the code by the compiler right??
#pragma once #ifdef _DEBUG #include <QElapsedTimer.h> #include <iostream> #define TIC Profiler::getInstance().startTimer(); #define TOC Profiler::getInstance().takeTime(); class Profiler { private: Profiler() { timer.start(); }; QElapsedTimer timer; public: ~Profiler() {}; static Profiler& getInstance() { static Profiler instance; return instance; } void startTimer() { timer.restart(); }; void takeTime() { std::cout << "time elapsed: " << timer.elapsed() << std::endl; }; }; #else #define TIC #define TOC #endif
@QT-static-prgm You could answer this question by yourself by just trying it out...
-
@jsulm no since for release there is no console ;) and even if there is a console it may still have the code merged into the project and that'd be unused code.
-
@jsulm no since for release there is no console ;) and even if there is a console it may still have the code merged into the project and that'd be unused code.
@QT-static-prgm What do you mean with "no console"? You can always print to console, even in release mode and even in a GUI application. Do you think if somebody in this forum says it is OK what you are doing there is no need to check to be sure?
You can check generated binary using nm tool to see whether Profiler class is in or not. -
nm tool??
-
nm tool??
Its a linux tool
http://www.thegeekstuff.com/2012/03/linux-nm-command/?utm_source=feedburnerListing symbols and other info
-
Hi,
When compiling this for release, all TIC and TOCs are ignored and completely removed from the code by the compiler right??
#pragma once #ifdef _DEBUG #include <QElapsedTimer.h> #include <iostream> #define TIC Profiler::getInstance().startTimer(); #define TOC Profiler::getInstance().takeTime(); class Profiler { private: Profiler() { timer.start(); }; QElapsedTimer timer; public: ~Profiler() {}; static Profiler& getInstance() { static Profiler instance; return instance; } void startTimer() { timer.restart(); }; void takeTime() { std::cout << "time elapsed: " << timer.elapsed() << std::endl; }; }; #else #define TIC #define TOC #endif
- You should use
NDEBUG
. - Or better yet just define your own debug macro for your project
- Or better use one of the standard tools for profiling like
callgrind
- And why try to profile a debug build to begin with? This doesn't make much sense.
- You should use