GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
GmTimeMsg Class Reference

RAII object used to measure the elapsed time of an operation. More...

#include <gmLogTime.h>

Collaboration diagram for GmTimeMsg:

Public Member Functions

 GmTimeMsg (const GmLogCategory &logger, QString msg)
 
qint64 elapsed () const
 Returns the elapsed tim so far in ms.
 

Static Public Member Functions

static QString formatTime (double time, QString unit, bool useConstSizeUnit=false)
 Returns a string representation for the given time in the best possible unit.
 
static QString formatTime (double time, int unitIndex, bool useConstSizeUnit=false)
 Returns a string representation for the given time in the best possible unit, with the src unit definied by its index in _timeUnits.
 
static int unitIndex (QString unit)
 Returns the index of the unit in the format time table of known units, or -1 if not found.
 
static QString indexFmtUnit (int unitIndex)
 Returns the formatted unit (always with 3 characters) for the given unit index returned bu unitIndex()
 

Private Attributes

QElapsedTimer _timer
 Timer used to measure elapsed time.
 
const GmLogCategory_logger
 The logger used to emmit messages.
 
QString _msg
 Message title.
 

Static Private Attributes

static int _nestLevel = 0
 A global value storing the current nesting level (GmTimeMsg objects created in the scope of another one)
 
static const QStringList _timeUnits = { "ms", "s", "min", "h", "day" }
 The vector with the conversion "stair" for time conversion.
 
static const QStringList _fmtTimeUnits = { "ms ", "s ", "min", "h ", "day" }
 Equivalent to _timeUnits but with formatted strings.
 
static const QVector< double > _timeFactors = { 1000, 60, 60, 24, 1 }
 The vector with factors to convert time values between the considered time units.
 
static const int _secondIndex = 1
 The index for the second entry in _timeUnits.
 

Detailed Description

RAII object used to measure the elapsed time of an operation.

When the object is constructed, a timer is started. On destruction, the elapsed time is measured and a message is printed with gmTimeMsg().

Member Data Documentation

◆ _fmtTimeUnits

const QStringList GmTimeMsg::_fmtTimeUnits = { "ms ", "s ", "min", "h ", "day" }
staticprivate

Equivalent to _timeUnits but with formatted strings.

Equivalent to _timeUnits with formatted values (all with 3 characters)

◆ _nestLevel

int GmTimeMsg::_nestLevel = 0
staticprivate

A global value storing the current nesting level (GmTimeMsg objects created in the scope of another one)

Nesting level for GmTimeMsg object creations.

◆ _timeFactors

const QVector< double > GmTimeMsg::_timeFactors = { 1000, 60, 60, 24, 1 }
staticprivate

The vector with factors to convert time values between the considered time units.

Definition of the vector with factors to convert time values.

definition of the index for the second entry in _timeUnits

◆ _timeUnits

const QStringList GmTimeMsg::_timeUnits = { "ms", "s", "min", "h", "day" }
staticprivate

The vector with the conversion "stair" for time conversion.

Definition of the vector with the conversion "stair" for time conversion.


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