iLand
Public Member Functions | Static Public Member Functions | List of all members
DebugTimer Class Reference

Timer class that writes timings to the Debug-Output-Channel. More...

#include <debugtimer.h>

Public Member Functions

 DebugTimer ()
 
 DebugTimer (const QString &caption, bool silent=false)
 
void setSilent ()
 
void setHideShort (bool hide_short_messages)
 
 ~DebugTimer ()
 
void showElapsed ()
 
double elapsed ()
 
void start ()
 
void interval (const QString &text)
 

Static Public Member Functions

static void clearAllTimers ()
 
static void printAllTimers ()
 
static QString timeStr (double value_ms, bool exact=true)
 
static void setResponsiveMode (bool mode)
 
static bool responsiveMode ()
 

Detailed Description

Timer class that writes timings to the Debug-Output-Channel.

The class writes the elapsed time to qDebug() when either destructed, or when explicitely showElapsed() is called. elapsed() queries the elapsed time in milliseconds since construction or start() is called. Using interval() one can write a message with the time elapsed up the calling time, and the clock is reset afterwards. The name of the timer is set during construction. This message is printed when showElapsed() is called or durig destruction. Additionally, elapsed times of timers sharing the same caption are aggregated. Use clearAllTimers() to reset and printAllTimers() print the sums to the debug console. "Silent" DebugOutputs (setSilent() don't print timings for each iteration, but are still counted in the sums. If setAsWarning() is issued, the debug messages are print as warning, thus also visible when debug messages are disabled.

void foo() {
DebugTimer t("foo took [ms]:");
<some lengthy operation>
} // will e.g. print "foo took [ms]: 123" to debug console
void bar() {
DebugTimer::clearAllTimers(); // set all timers to 0
for (i=0;i<1000;i++)
foo();
DebugTimer::printAllTimers(); // print the sum of the timings.
}
Timer class that writes timings to the Debug-Output-Channel.
Definition: debugtimer.h:50
static void clearAllTimers()
Definition: debugtimer.cpp:89
static void printAllTimers()
Definition: debugtimer.cpp:97

For Windows, the "TickTack"-backend is used.

Constructor & Destructor Documentation

◆ DebugTimer() [1/2]

DebugTimer::DebugTimer ( )
inline

◆ DebugTimer() [2/2]

DebugTimer::DebugTimer ( const QString &  caption,
bool  silent = false 
)

◆ ~DebugTimer()

DebugTimer::~DebugTimer ( )

Member Function Documentation

◆ clearAllTimers()

void DebugTimer::clearAllTimers ( )
static

◆ elapsed()

double DebugTimer::elapsed ( )

◆ interval()

void DebugTimer::interval ( const QString &  text)

◆ printAllTimers()

void DebugTimer::printAllTimers ( )
static

◆ responsiveMode()

static bool DebugTimer::responsiveMode ( )
inlinestatic

◆ setHideShort()

void DebugTimer::setHideShort ( bool  hide_short_messages)
inline

◆ setResponsiveMode()

static void DebugTimer::setResponsiveMode ( bool  mode)
inlinestatic

◆ setSilent()

void DebugTimer::setSilent ( )
inline

◆ showElapsed()

void DebugTimer::showElapsed ( )

◆ start()

void DebugTimer::start ( )

◆ timeStr()

QString DebugTimer::timeStr ( double  value_ms,
bool  exact = true 
)
static

The documentation for this class was generated from the following files: