iLand
debugtimer.h
Go to the documentation of this file.
1/********************************************************************************************
2** iLand - an individual based forest landscape and disturbance model
3** http://iland-model.org
4** Copyright (C) 2009- Werner Rammer, Rupert Seidl
5**
6** This program is free software: you can redistribute it and/or modify
7** it under the terms of the GNU General Public License as published by
8** the Free Software Foundation, either version 3 of the License, or
9** (at your option) any later version.
10**
11** This program is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14** GNU General Public License for more details.
15**
16** You should have received a copy of the GNU General Public License
17** along with this program. If not, see <http://www.gnu.org/licenses/>.
18********************************************************************************************/
19#ifndef DEBUGTIMER_H
20#define DEBUGTIMER_H
21#include "ticktack.h"
22#include <QAtomicInt>
23
50{
51public:
52 DebugTimer() { m_hideShort=false; m_silent=false; start(); ++m_count; }
53 DebugTimer(const QString &caption, bool silent=false);
54 void setSilent() { m_silent=true; }
55 void setHideShort(bool hide_short_messages) { m_hideShort = hide_short_messages; }
57 void showElapsed();
58 double elapsed(); // elapsed time in milliseconds
59 void start();
60 void interval(const QString &text);
61 static void clearAllTimers();
62 static void printAllTimers();
63 static QString timeStr(double value_ms, bool exact=true);
64 static void setResponsiveMode(bool mode) { m_responsive_mode = mode; }
65 static bool responsiveMode() { return m_responsive_mode; }
66private:
67 static QHash<QString, double> mTimingList;
68 static bool m_responsive_mode;
69 static qint64 ms_since_epoch; // milliseconds since epoch for the first call
70 TickTack t;
71 bool m_hideShort; // if true, hide messages for short operations (except an explicit call to showElapsed())
72 bool m_shown;
73 bool m_silent;
74 QString m_caption;
75 QAtomicInt m_count; // counts how many DebugTimer are currently alive
76};
77
78#endif // DEBUGTIMER_H
Timer class that writes timings to the Debug-Output-Channel.
Definition: debugtimer.h:50
double elapsed()
Definition: debugtimer.cpp:153
static void clearAllTimers()
Definition: debugtimer.cpp:89
void setSilent()
Definition: debugtimer.h:54
void interval(const QString &text)
Definition: debugtimer.cpp:139
DebugTimer()
Definition: debugtimer.h:52
static void printAllTimers()
Definition: debugtimer.cpp:97
void setHideShort(bool hide_short_messages)
Definition: debugtimer.h:55
static QString timeStr(double value_ms, bool exact=true)
Definition: debugtimer.cpp:112
~DebugTimer()
Definition: debugtimer.cpp:47
void start()
Definition: debugtimer.cpp:158
void showElapsed()
Definition: debugtimer.cpp:146
static void setResponsiveMode(bool mode)
Definition: debugtimer.h:64
static bool responsiveMode()
Definition: debugtimer.h:65
Definition: ticktack.h:26