RoveComm C++ 3.0.0
Welcome to the RoveComm C++ repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of RoveComm C++. The RoveComm C++ project is the RoveComm interface for high level systems and should not be used for microcontrollers.
Loading...
Searching...
No Matches
IPS Class Reference

This util class provides an easy way to keep track of iterations per second for any body of code. More...

#include <IPS.hpp>

Public Member Functions

 IPS ()
 Construct a new IPS object.
 ~IPS ()
 Construct a new IPS object.
IPS & operator= (const IPS &OtherIPS)
 Operator equals for IPS class.
void Tick ()
 This method is used to update the iterations per second counter and recalculate all of the IPS metrics.
double GetExactIPS () const
 Accessor for the Current I P S private member. This method will return the immediate IPS since the last Tick() call. If called in a loop, this number will likely jump around greatly. If you want a 'smoother' IPS number then call the GetAverageIPS() method.
double GetAverageIPS () const
 Calculates the average iterations per second.
double GetHighestIPS () const
 Accessor for the Highest I P S private member.
double GetLowestIPS () const
 Accessor for the Lowest I P S private member.
double Get1PercentLow () const
 Accessor for the 1PercentLow I P S private member.
void Reset ()
 Resets all metrics and frame time history.

Private Member Functions

void UpdateMetrics ()
 This method is used to calculate the IPS stats. Highest, lowest, and 1 percent low IPS.

Private Attributes

double m_dCurrentIPS
double m_dHighestIPS
double m_dLowestIPS
double m_d1PercentLow
std::deque< double > m_dqIPSHistory
std::chrono::high_resolution_clock::time_point m_tLastUpdateTime
const long unsigned int m_nMaxMetricsHistorySize = 100

Detailed Description

This util class provides an easy way to keep track of iterations per second for any body of code.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-08-17

Constructor & Destructor Documentation

◆ IPS()

IPS::IPS ( )
inline

Construct a new IPS object.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-08-17
91 {
92 // Initialize member variables and objects.
93 m_dCurrentIPS = 0.0;
94 m_dHighestIPS = 0.0;
95 m_dLowestIPS = 9999999;
96 m_d1PercentLow = 0.0;
97 }
double m_d1PercentLow
Definition IPS.hpp:39
double m_dLowestIPS
Definition IPS.hpp:38
double m_dCurrentIPS
Definition IPS.hpp:36
double m_dHighestIPS
Definition IPS.hpp:37
Here is the caller graph for this function:

◆ ~IPS()

IPS::~IPS ( )
inline

Construct a new IPS object.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-08-17
107 {
108 // Nothing to destroy.
109 }

Member Function Documentation

◆ Get1PercentLow()

double IPS::Get1PercentLow ( ) const
inline

Accessor for the 1PercentLow I P S private member.

Returns
double - The recorded 1% low within the given metrics window size.
Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-08-17
241 {
242 // Return the 1% low for IPS.
243 return m_d1PercentLow;
244 }

◆ GetAverageIPS()

double IPS::GetAverageIPS ( ) const
inline

Calculates the average iterations per second.

Returns
double - The average iterations per second according to the metrics window.
Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-08-17
184 {
185 // Check if there is any history.
186 if (m_dqIPSHistory.empty())
187 {
188 // Return zero IPS average.
189 return 0.0;
190 }
191
192 // Loop through IPS history and calculate average.
193 double dSum = 0.0;
194 for (const double dVal : m_dqIPSHistory)
195 {
196 // Add FPS to total sum.
197 dSum += dVal;
198 }
199
200 // Return calculated average.
201 return dSum / m_dqIPSHistory.size();
202 }
std::deque< double > m_dqIPSHistory
Definition IPS.hpp:40

◆ GetExactIPS()

double IPS::GetExactIPS ( ) const
inline

Accessor for the Current I P S private member. This method will return the immediate IPS since the last Tick() call. If called in a loop, this number will likely jump around greatly. If you want a 'smoother' IPS number then call the GetAverageIPS() method.

Returns
double - The calculated IPS value since the last iteration.
Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-08-17
169 {
170 // Return current iterations per second.
171 return m_dCurrentIPS;
172 }

◆ GetHighestIPS()

double IPS::GetHighestIPS ( ) const
inline

Accessor for the Highest I P S private member.

Returns
double - The highest recorded IPS over this objects lifespan.
Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-08-17
213 {
214 // Return the highest iterations per second.
215 return m_dHighestIPS;
216 }

◆ GetLowestIPS()

double IPS::GetLowestIPS ( ) const
inline

Accessor for the Lowest I P S private member.

Returns
double - The lowest recorded IPS over this objects lifespan.
Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-08-17
227 {
228 // Return the lowest iterations per second.
229 return m_dLowestIPS;
230 }

◆ operator=()

IPS & IPS::operator= ( const IPS & OtherIPS)
inline

Operator equals for IPS class.

Parameters
OtherIPS- The IPS object to copy values from.
Returns
IPS& - A reference to this object.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-10-10
121 {
122 // Copy values from other IPS object.
123 m_dCurrentIPS = OtherIPS.m_dCurrentIPS;
124 m_dHighestIPS = OtherIPS.m_dHighestIPS;
125 m_dLowestIPS = OtherIPS.m_dLowestIPS;
128
129 // Return this object.
130 return *this;
131 }
Here is the call graph for this function:

◆ Reset()

void IPS::Reset ( )
inline

Resets all metrics and frame time history.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-09-07
254 {
255 // Reset member variable.
256 m_dCurrentIPS = 0.0;
257 m_dHighestIPS = 0.0;
258 m_dLowestIPS = 9999999;
259 m_d1PercentLow = 0.0;
260 // Reset deque.
261 m_dqIPSHistory.clear();
262 }

◆ Tick()

void IPS::Tick ( )
inline

This method is used to update the iterations per second counter and recalculate all of the IPS metrics.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-08-17
142 {
143 // Get the current and elapsed time.
144 auto tCurrentTime = std::chrono::high_resolution_clock::now();
145 auto tElapsedTimeSinceLastTick = std::chrono::duration_cast<std::chrono::microseconds>(tCurrentTime - m_tLastUpdateTime).count();
146
147 // Calculate current IPS. 1 second == 1000000 microseconds.
148 m_dCurrentIPS = 1e6 / tElapsedTimeSinceLastTick;
149
150 // Calculate IPS overall stats.
151 this->UpdateMetrics();
152
153 // Set current time to old.
154 m_tLastUpdateTime = tCurrentTime;
155 }
std::chrono::high_resolution_clock::time_point m_tLastUpdateTime
Definition IPS.hpp:41
void UpdateMetrics()
This method is used to calculate the IPS stats. Highest, lowest, and 1 percent low IPS.
Definition IPS.hpp:54
Here is the call graph for this function:

◆ UpdateMetrics()

void IPS::UpdateMetrics ( )
inlineprivate

This method is used to calculate the IPS stats. Highest, lowest, and 1 percent low IPS.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-08-17
55 {
56 // Check highest IPS.
58 {
59 // Update new highest.
61 }
62 // Check lowest IPS.
64 {
65 // Update new lowest.
67 }
68
69 // Add current IPS to history.
70 m_dqIPSHistory.emplace_back(m_dCurrentIPS);
71 // Sort the IPS history vector, this allows us to find the 1% low more easily.
72 // Throw out oldest element in deque if size is over given number.
74 {
75 m_dqIPSHistory.pop_front();
76 }
77 // Get the index correlating to the IPS number that was lower than 99% of the rest of the IPS history.
78 m_d1PercentLow = *std::min_element(m_dqIPSHistory.begin(), m_dqIPSHistory.end());
79 }
const long unsigned int m_nMaxMetricsHistorySize
Definition IPS.hpp:44
Here is the caller graph for this function:

Member Data Documentation

◆ m_d1PercentLow

double IPS::m_d1PercentLow
private

◆ m_dCurrentIPS

double IPS::m_dCurrentIPS
private

◆ m_dHighestIPS

double IPS::m_dHighestIPS
private

◆ m_dLowestIPS

double IPS::m_dLowestIPS
private

◆ m_dqIPSHistory

std::deque<double> IPS::m_dqIPSHistory
private

◆ m_nMaxMetricsHistorySize

const long unsigned int IPS::m_nMaxMetricsHistorySize = 100
private

◆ m_tLastUpdateTime

std::chrono::high_resolution_clock::time_point IPS::m_tLastUpdateTime
private

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