[Pkg-owncloud-commits] [owncloud-client] 234/333: Add a stopwatch utility class with lap times.
Sandro Knauß
hefee-guest at moszumanska.debian.org
Thu Apr 17 23:16:58 UTC 2014
This is an automated email from the git hooks/post-receive script.
hefee-guest pushed a commit to branch master
in repository owncloud-client.
commit 7b84defd5625100532d5b55d9d35f0b8f99d4071
Author: Klaas Freitag <freitag at owncloud.com>
Date: Wed Mar 26 18:00:02 2014 +0100
Add a stopwatch utility class with lap times.
Allows to meassure the duration of something that started at a
point of time, with some small convenience methods.
---
src/mirall/utility.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/mirall/utility.h | 18 +++++++++++++++++
2 files changed, 72 insertions(+)
diff --git a/src/mirall/utility.cpp b/src/mirall/utility.cpp
index bafb424..6da0f7a 100644
--- a/src/mirall/utility.cpp
+++ b/src/mirall/utility.cpp
@@ -490,4 +490,58 @@ bool Utility::isLinux()
#endif
}
+# define STOPWATCH_END_TAG QLatin1String("_STOPWATCH_END")
+
+void Utility::StopWatch::start()
+{
+ _startTime = QDateTime::currentDateTime();
+ _timer.start();
+}
+
+void Utility::StopWatch::stop()
+{
+ addLapTime(QLatin1String(STOPWATCH_END_TAG));
+ _timer.invalidate();
+}
+
+quint64 Utility::StopWatch::addLapTime( const QString& lapName )
+{
+ if( !_timer.isValid() ) {
+ start();
+ }
+ quint64 re = _timer.elapsed();
+ QPair<QString, quint64> p(lapName, re);
+ _lapTimes.append(p);
+ return re;
+}
+
+QDateTime Utility::StopWatch::startTime()
+{
+ return _startTime;
+}
+
+QDateTime Utility::StopWatch::timeOfLap( const QString& lapName )
+{
+ quint64 t = durationOfLap(lapName);
+ if( t ) {
+ QDateTime re(_startTime);
+ return re.addMSecs(t);
+ }
+
+ return QDateTime();
+}
+
+quint64 Utility::StopWatch::durationOfLap( const QString& lapName )
+{
+ QPair<QString, quint64> lapPair;
+
+ foreach( lapPair, _lapTimes ) {
+ if( lapPair.first == lapName ) {
+ return lapPair.second;
+ }
+ }
+ return 0;
+}
+
+
} // namespace Mirall
diff --git a/src/mirall/utility.h b/src/mirall/utility.h
index 41760cd..904d2b8 100644
--- a/src/mirall/utility.h
+++ b/src/mirall/utility.h
@@ -18,6 +18,8 @@
#include <QString>
#include <QByteArray>
#include <QDateTime>
+#include <QPair>
+#include <QElapsedTimer>
class QWidget;
@@ -65,6 +67,22 @@ namespace Utility
bool isMac();
bool isUnix();
bool isLinux(); // use with care
+
+ class StopWatch {
+ private:
+ QList<QPair<QString, quint64> > _lapTimes;
+ QDateTime _startTime;
+ QElapsedTimer _timer;
+ public:
+ void start();
+ void stop();
+ quint64 addLapTime( const QString& lapName );
+
+ // out helpers, return the masured times.
+ QDateTime startTime();
+ QDateTime timeOfLap( const QString& lapName );
+ quint64 durationOfLap( const QString& lapName );
+ };
}
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git
More information about the Pkg-owncloud-commits
mailing list