Skip to content
Snippets Groups Projects
Commit 3cd006d4 authored by Stepan Salenikovich's avatar Stepan Salenikovich Committed by Guillaume Roguez
Browse files

usage_statistics: speed up compilation


Move the function implementations to the .cpp file; otherwise each
small change to the implementation causes very long lrc compilation
time.

Change-Id: I97aa4e36d72392600700220d5461c0dc0c5d4828
Reviewed-by: default avatarGuillaume Roguez <guillaume.roguez@savoirfairelinux.com>
parent 1bf29f26
Branches
No related tags found
No related merge requests found
...@@ -334,6 +334,7 @@ SET( libringclient_LIB_SRCS ...@@ -334,6 +334,7 @@ SET( libringclient_LIB_SRCS
src/private/threadworker.cpp src/private/threadworker.cpp
src/mime.cpp src/mime.cpp
src/smartinfohub.cpp src/smartinfohub.cpp
src/usage_statistics.cpp
#Extension #Extension
src/extensions/presencecollectionextension.cpp src/extensions/presencecollectionextension.cpp
......
/****************************************************************************
* Copyright (C) 2017 by Savoir-faire Linux *
* Author : Guillaume Roguez <guillaume.roguez@savoirfairelinux.com> *
* Author : Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>*
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "usage_statistics.h"
//Qt
#include <QDebug>
//Accessors
unsigned
UsageStatistics::totalCount() const {
return m_TotalSeconds;
}
unsigned
UsageStatistics::totalSeconds() const {
return m_TotalSeconds;
}
unsigned
UsageStatistics::lastWeekCount() const {
return m_LastWeekCount;
}
unsigned
UsageStatistics::lastTrimCount() const {
return m_LastTrimCount;
}
time_t
UsageStatistics::lastUsed() const {
return m_LastUsed;
}
bool
UsageStatistics::haveCalled() const {
return m_HaveCalled;
}
//Mutators
void
UsageStatistics::setHaveCalled() {
m_HaveCalled = true;
}
/// \brief Update usage using a time range.
///
/// All values are updated using given <tt>[start, stop]</tt> time range.
/// \a start and \a stop are given in seconds.
///
/// \param start starting time of usage
/// \param stop ending time of usage, must be greater than \a start
void
UsageStatistics::update(const time_t& start, const time_t& stop) {
++m_TotalCount;
setLastUsed(start);
m_TotalSeconds += stop - start;
time_t now;
::time(&now);
if (now - 3600*24*7 < stop)
++m_LastWeekCount;
if (now - 3600*24*7*15 < stop)
++m_LastTrimCount;
}
/// \brief Use this method to update lastUsed time by a new time only if sooner.
///
/// \return \a true if the update has been effective.
bool
UsageStatistics::setLastUsed(time_t new_time) {
if (new_time > m_LastUsed) {
m_LastUsed = new_time;
return true;
}
return false;
}
UsageStatistics& UsageStatistics::operator+=(const UsageStatistics& rhs) {
m_TotalCount += rhs.m_TotalCount;
m_LastWeekCount += rhs.m_LastWeekCount;
m_LastTrimCount += rhs.m_LastTrimCount;
m_HaveCalled += rhs.m_TotalCount; // '+=' mean '|=' here
setLastUsed(rhs.m_LastUsed);
return *this;
}
...@@ -28,35 +28,21 @@ class UsageStatistics ...@@ -28,35 +28,21 @@ class UsageStatistics
public: public:
//Accessors //Accessors
unsigned totalCount() const { unsigned totalCount() const;
return m_TotalSeconds;
}
unsigned totalSeconds() const { unsigned totalSeconds() const;
return m_TotalSeconds;
}
unsigned lastWeekCount() const { unsigned lastWeekCount() const;
return m_LastWeekCount;
}
unsigned lastTrimCount() const { unsigned lastTrimCount() const;
return m_LastTrimCount;
}
time_t lastUsed() const { time_t lastUsed() const;
return m_LastUsed;
}
bool haveCalled() const { bool haveCalled() const;
return m_HaveCalled;
}
//Mutators //Mutators
void setHaveCalled() { void setHaveCalled();
m_HaveCalled = true;
}
/// \brief Update usage using a time range. /// \brief Update usage using a time range.
/// ///
...@@ -65,40 +51,17 @@ public: ...@@ -65,40 +51,17 @@ public:
/// ///
/// \param start starting time of usage /// \param start starting time of usage
/// \param stop ending time of usage, must be greater than \a start /// \param stop ending time of usage, must be greater than \a start
void update(const time_t& start, const time_t& stop) { void update(const time_t& start, const time_t& stop);
++m_TotalCount;
setLastUsed(start);
m_TotalSeconds += stop - start;
time_t now;
::time(&now);
if (now - 3600*24*7 < stop)
++m_LastWeekCount;
if (now - 3600*24*7*15 < stop)
++m_LastTrimCount;
}
/// \brief Use this method to update lastUsed time by a new time only if sooner. /// \brief Use this method to update lastUsed time by a new time only if sooner.
/// ///
/// \return \a true if the update has been effective. /// \return \a true if the update has been effective.
bool setLastUsed(time_t time) { bool setLastUsed(time_t new_time);
if (m_LastUsed < time) {
m_LastUsed = time;
return true;
}
return false;
}
/// \brief Inplace incrementation of current values by values from another UsageStatistics instance. /// \brief Inplace incrementation of current values by values from another UsageStatistics instance.
/// ///
/// \note \a lastUsed time is not incremented but updated using setLastUsed(). /// \note \a lastUsed time is not incremented but updated using setLastUsed().
UsageStatistics& operator+=(const UsageStatistics& rhs) { UsageStatistics& operator+=(const UsageStatistics& rhs);
m_TotalCount += rhs.m_TotalCount;
m_LastWeekCount += rhs.m_LastWeekCount;
m_LastTrimCount += rhs.m_LastTrimCount;
m_HaveCalled += rhs.m_TotalCount; // '+=' mean '|=' here
setLastUsed(rhs.m_LastUsed);
return *this;
}
private: private:
unsigned m_TotalCount {0}; ///< cummulated usage in number of time unsigned m_TotalCount {0}; ///< cummulated usage in number of time
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment