Created
August 17, 2012 17:47
-
-
Save bjorn/3380952 to your computer and use it in GitHub Desktop.
Duration Logger (Qt)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef DURATIONLOGGER_H | |
#define DURATIONLOGGER_H | |
#include <QTime> | |
/** | |
* A helper class that logs the duration of a specific scope. | |
*/ | |
class DurationLogger | |
{ | |
public: | |
DurationLogger(const char *thing) : thing(thing) { time.start(); } | |
~DurationLogger() { qDebug() << thing << time.elapsed(); } | |
private: | |
QTime time; | |
const char *thing; | |
}; | |
/** | |
* Use this macro in functions to conveniently time their duration. | |
*/ | |
#define LOG_DURATION DurationLogger _durationLogger(Q_FUNC_INFO) | |
#endif // DURATIONLOGGER_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment