-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
185 additions
and
50 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* Josip Medved <[email protected]> * www.medo64.com * MIT License */ | ||
|
||
#include <QDebug> | ||
#include "lifetimewatch.h" | ||
|
||
|
||
LifetimeWatch::LifetimeWatch(const QString& text) | ||
: LifetimeWatch(text, false) { | ||
} | ||
|
||
LifetimeWatch::LifetimeWatch(const QString& text, bool addGuid) { | ||
#ifdef QT_DEBUG | ||
_text = text; | ||
_stopwatch = new QElapsedTimer(); | ||
_stopwatch->start(); | ||
if (addGuid) { _uuid = QUuid::createUuid(); } | ||
qDebug().noquote().nospace() << "[LifeTimeWatch] " << text | ||
<< ( _uuid.isNull() ? "" : " " + _uuid.toString() ); | ||
#else | ||
Q_UNUSED(text) | ||
Q_UNUSED(addGuid) | ||
#endif | ||
} | ||
|
||
void LifetimeWatch::elapsed() { | ||
this->elapsed(""); | ||
} | ||
|
||
void LifetimeWatch::elapsed(const QString& extraText) { | ||
#ifdef QT_DEBUG | ||
_mutex.lock(); | ||
if (_stopwatch != nullptr) { | ||
qDebug().noquote().nospace() << "[LifeTimeWatch] " << _text | ||
<< " elapsed at " << _stopwatch->elapsed() << "ms" | ||
<< ( extraText.length() > 0 ? " (" + extraText + ")" : "" ) | ||
<< ( _uuid.isNull() ? "" : " " + _uuid.toString() ); | ||
} | ||
_mutex.unlock(); | ||
#else | ||
Q_UNUSED(extraText) | ||
#endif | ||
} | ||
|
||
void LifetimeWatch::done() { | ||
#ifdef QT_DEBUG | ||
_mutex.lock(); | ||
if (_stopwatch != nullptr) { | ||
qDebug().noquote().nospace() << "[LifeTimeWatch] " << _text | ||
<< " done in " << _stopwatch->elapsed() << "ms" | ||
<< ( _uuid.isNull() ? "" : " " + _uuid.toString() ); | ||
delete(_stopwatch); | ||
_stopwatch = nullptr; | ||
} | ||
_mutex.unlock(); | ||
#endif | ||
} | ||
|
||
LifetimeWatch::~LifetimeWatch() { | ||
this->done(); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* Josip Medved <[email protected]> * www.medo64.com * MIT License */ | ||
|
||
// 2021-12-09: Initial version | ||
|
||
#pragma once | ||
|
||
#include <QElapsedTimer> | ||
#include <QMutex> | ||
#include <QString> | ||
#include <QUuid> | ||
|
||
namespace Medo { class LifetimeWatch; } | ||
|
||
class LifetimeWatch { | ||
|
||
public: | ||
LifetimeWatch(const QString& text); | ||
LifetimeWatch(const QString& text, bool addGuid); | ||
~LifetimeWatch(); | ||
void done(); | ||
void elapsed(); | ||
void elapsed(const QString& extraText); | ||
|
||
private: | ||
QMutex _mutex; | ||
QUuid _uuid; | ||
QElapsedTimer* _stopwatch = nullptr; | ||
QString _text; | ||
|
||
}; |
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
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
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
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