Bug 1287712 - TimeDurationAccumulator includes running timer in reports - r=cpearce

If the timer is currently running, add started time segment until now to
Total(), and add 1 to Count().
This ensures correct values are returned without having to Pause().

MozReview-Commit-ID: JSBvL93GtkE

--HG--
extra : rebase_source : 86923c39e54c778151812a55e2ad9e4e010047fd
This commit is contained in:
Gerald Squelart 2016-07-19 17:46:38 +10:00
Родитель b0c57eaceb
Коммит 5d19600ca6
1 изменённых файлов: 22 добавлений и 9 удалений

Просмотреть файл

@ -1575,19 +1575,21 @@ protected:
public: public:
// Helper class to measure times for MSE telemetry stats // Helper class to measure times for MSE telemetry stats
class TimeDurationAccumulator { class TimeDurationAccumulator
{
public: public:
TimeDurationAccumulator() TimeDurationAccumulator()
: mCount(0) : mCount(0)
{}
void Start()
{ {
}
void Start() {
if (IsStarted()) { if (IsStarted()) {
return; return;
} }
mStartTime = TimeStamp::Now(); mStartTime = TimeStamp::Now();
} }
void Pause() { void Pause()
{
if (!IsStarted()) { if (!IsStarted()) {
return; return;
} }
@ -1595,14 +1597,25 @@ public:
mCount++; mCount++;
mStartTime = TimeStamp(); mStartTime = TimeStamp();
} }
bool IsStarted() const { bool IsStarted() const
{
return !mStartTime.IsNull(); return !mStartTime.IsNull();
} }
double Total() const { double Total() const
return mSum.ToSeconds(); {
if (!IsStarted()) {
return mSum.ToSeconds();
}
// Add current running time until now, but keep it running.
return (mSum + (TimeStamp::Now() - mStartTime)).ToSeconds();
} }
uint32_t Count() const { uint32_t Count() const
return mCount; {
if (!IsStarted()) {
return mCount;
}
// Count current run in this report, without increasing the stored count.
return mCount + 1;
} }
private: private:
TimeStamp mStartTime; TimeStamp mStartTime;