Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static const bool use_debug_timer = true;
- static quint32 last_id = 0;
- static qint64 warning_maximum = 1000;
- struct DebugTimer {
- DebugTimer(const QString& func_name, bool use_debug_timer, quint32& last_id) {
- if (use_debug_timer) {
- id = last_id + 1;
- last_id = id;
- this->func_name = func_name;
- used = true;
- timer.start();
- }
- }
- void end(qint64 warning_minimum) {
- if (used) {
- qint64 elapsed = timer.elapsed();
- if (elapsed > warning_minimum) {
- qDebug() << func_name << " [" << id << "] took " << timer.elapsed() << " msecs!";
- }
- }
- }
- QElapsedTimer timer;
- quint32 id;
- QString func_name;
- bool used = false;
- };
- void f() {
- DebugTimer debug_timer(__func__, use_debug_timer, last_id);
- do_stuff();
- debug_timer.end(warning_maximum);
- }
- qint32 b() {
- DebugTimer debug_timer(__func__, use_debug_timer, last_id);
- if (sth1 && sth2 && sth3) {
- debug_timer.end(warning_maximum);
- return 1;
- }
- else if (sth1 && (sth2 || sth3)) {
- debug_timer.end(warning_maximum);
- return 2;
- }
- debug_timer.end(warning_maximum);
- return 3;
- }
Advertisement
Add Comment
Please, Sign In to add comment