COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems

#include <elapsedtime.h>

Collaboration diagram for ElapsedTime:

Public Member Functions

 ElapsedTime ()
 ElapsedTime::ElapsedTime. More...
 
void printElapsedTime ()
 ElapsedTime::printElapsedTime. More...
 
void printElapsedTime (string text)
 ElapsedTime::printElapsedTime. More...
 
double getElapsedTimeMiliSeconds ()
 
double getElapsedTime ()
 
double getElapsedTimeSince (double startTimeMjd)
 
double getElapsedTime (double startMjd, double endMjd)
 compute the elapsed time between the two provided times More...
 
double lap ()
 Lap Time. More...
 
double split ()
 ElapsedTime::split, gets the current elapsed time since the start() More...
 
double check ()
 
void reset ()
 ElapsedTime::reset. More...
 
void start ()
 ElapsedTime::start. More...
 
double stop ()
 ElapsedTime::stop. More...
 
void tic ()
 ElapsedTime::tic, equivalent to matlab to start a stopwatch timer. More...
 
double toc ()
 ElapsedTime::toc, equivalent to matlab to stop a stopwatch timer. More...
 
double toc (string text)
 ElapsedTime::toc, equivalent to matlab to stop a stopwatch timer. More...
 
void info ()
 ElapsedTime::info, combines toc and print, this simplifies the calling of functions. More...
 

Public Attributes

bool print = true
 
double elapsedTime = 0.
 

Private Attributes

std::chrono::steady_clock::time_point timeStart
 
std::chrono::steady_clock::time_point timeStop
 
std::chrono::steady_clock::time_point timeNow
 
std::chrono::steady_clock::time_point timeCheck
 

Constructor & Destructor Documentation

ElapsedTime::ElapsedTime ( )

ElapsedTime::ElapsedTime.

83 {
84  // by default start the timer
85  start();
86 }
void start()
ElapsedTime::start.
Definition: elapsedtime.cpp:203

Member Function Documentation

void ElapsedTime::printElapsedTime ( )

ElapsedTime::printElapsedTime.

116 {
117  if (print){
118  //char buffer[50];
119  //sprintf(buffer,"Elapsed Time: %.6f s",elapsedTime);
120  //std::cout << buffer << std::endl;
121  std::cout << "Elapsed Time "<< elapsedTime << " s" << std::endl;
122  }
123 }
double elapsedTime
Definition: elapsedtime.h:98
bool print
Definition: elapsedtime.h:97
void ElapsedTime::printElapsedTime ( string  text)

ElapsedTime::printElapsedTime.

Parameters
text
130 {
131  if (print){
132  //toc();
133  //char buffer[50];
134  //sprintf(buffer,"Elapsed Time (%s): %.6f s",text.c_str(),elapsedTime);
135  //std::cout << buffer << std::endl;
136  std::cout << "Elapsed Time (" << text << "): "<< elapsedTime<< " s" << std::endl;
137  }
138 }
double elapsedTime
Definition: elapsedtime.h:98
bool print
Definition: elapsedtime.h:97
double ElapsedTime::getElapsedTimeMiliSeconds ( )
double ElapsedTime::getElapsedTime ( )
251  {
252  //Get the elapsedTime from start
253  return split();
254 }
double split()
ElapsedTime::split, gets the current elapsed time since the start()
Definition: elapsedtime.cpp:234
double ElapsedTime::getElapsedTimeSince ( double  startTimeMjd)
256  {
257  //Get the elapsedTime from start to now
258  return (currentmjd()-startMjd)*86400;
259 }
double currentmjd(double offset)
Current UTC in Modified Julian Days.
Definition: timelib.cpp:65
double ElapsedTime::getElapsedTime ( double  startMjd,
double  endMjd 
)

compute the elapsed time between the two provided times

Parameters
startMjdFirst time.
endMjdSecond time.
Returns
elapsed time in seconds
269 {
270  // compute the elapsed time between start and end
271  return (endMjd-startMjd)*86400;
272 }
double ElapsedTime::lap ( )

Lap Time.

This is the elapsed time since the last Lap Time. ElapsedTime::timeCheck is set in order to keep track of this event.

Returns
Time since last call to lap(), reset(), or start(), in seconds.
146 {
147 #ifdef CROSS_TYPE_arm
148  // clock_gettime(CLOCK_MONOTONIC, &timeNow);
149  // elapsedTime = (timeNow.tv_sec - timeCheck.tv_sec) + (timeNow.tv_nsec - timeCheck.tv_nsec) / 1e9;
150  gettimeofday(&timeNow, nullptr);
151  elapsedTime = (timeNow.tv_sec - timeCheck.tv_sec) + (timeNow.tv_usec - timeCheck.tv_usec) / 1e6;
152 #else
153  timeNow = std::chrono::steady_clock::now();
154  elapsedTime = std::chrono::duration<double>(timeNow - timeCheck).count();
155 #endif
156 
157  timeCheck = timeNow;
158  return elapsedTime;
159 
160 }
std::chrono::steady_clock::time_point timeCheck
Definition: elapsedtime.h:68
int count
Definition: rw_test.cpp:36
double elapsedTime
Definition: elapsedtime.h:98
std::chrono::steady_clock::time_point timeNow
Definition: elapsedtime.h:68
double ElapsedTime::split ( )

ElapsedTime::split, gets the current elapsed time since the start()

Returns
was previously stop()
235 {
236  //Get the final time
237 
238 #ifdef CROSS_TYPE_arm
239  // clock_gettime(CLOCK_MONOTONIC, &timeNow);
240  // elapsedTime = (timeNow.tv_sec - timeStart.tv_sec) + (timeNow.tv_nsec - timeStart.tv_nsec) / 1e9;
241  gettimeofday(&timeNow, nullptr);
242  elapsedTime = (timeNow.tv_sec - timeStart.tv_sec) + (timeNow.tv_usec - timeStart.tv_usec) / 1e6;
243 #else
244  timeNow = std::chrono::steady_clock::now();
245  elapsedTime = std::chrono::duration<double>(timeNow - timeStart).count();
246 #endif
247 
248  return elapsedTime;
249 }
int count
Definition: rw_test.cpp:36
double elapsedTime
Definition: elapsedtime.h:98
std::chrono::steady_clock::time_point timeStart
Definition: elapsedtime.h:68
std::chrono::steady_clock::time_point timeNow
Definition: elapsedtime.h:68
double ElapsedTime::check ( )
void ElapsedTime::reset ( )

ElapsedTime::reset.

278  {
279  start();
280 }
void start()
ElapsedTime::start.
Definition: elapsedtime.cpp:203
void ElapsedTime::start ( )

ElapsedTime::start.

204 {
205  //Get the start time
206 #ifdef CROSS_TYPE_arm
207  // clock_gettime(CLOCK_MONOTONIC, &timeStart);
208  gettimeofday(&timeStart, nullptr);
209 #else
210  // On windows using MinGw32 it does not get better than 1ms
211  // new c++11
212  timeStart = std::chrono::steady_clock::now();
213 #endif
215  elapsedTime = 0;
216 }
std::chrono::steady_clock::time_point timeCheck
Definition: elapsedtime.h:68
double elapsedTime
Definition: elapsedtime.h:98
std::chrono::steady_clock::time_point timeStart
Definition: elapsedtime.h:68
double ElapsedTime::stop ( )

ElapsedTime::stop.

Returns
224 {
225  //elapsedTime = 0;
226  return split();
227 }
double split()
ElapsedTime::split, gets the current elapsed time since the start()
Definition: elapsedtime.cpp:234
void ElapsedTime::tic ( )

ElapsedTime::tic, equivalent to matlab to start a stopwatch timer.

166  {
167  start();
168 }
void start()
ElapsedTime::start.
Definition: elapsedtime.cpp:203
double ElapsedTime::toc ( )

ElapsedTime::toc, equivalent to matlab to stop a stopwatch timer.

Returns
174  {
175 
176  // stop();
177  split();
179 
180  return elapsedTime;
181 }
void printElapsedTime()
ElapsedTime::printElapsedTime.
Definition: elapsedtime.cpp:115
double elapsedTime
Definition: elapsedtime.h:98
double split()
ElapsedTime::split, gets the current elapsed time since the start()
Definition: elapsedtime.cpp:234
double ElapsedTime::toc ( string  text)

ElapsedTime::toc, equivalent to matlab to stop a stopwatch timer.

Parameters
text
Returns
190 {
191 
192  split();
193 
194  // print the text
195  printElapsedTime(text);
196 
197  return elapsedTime;
198 }
void printElapsedTime()
ElapsedTime::printElapsedTime.
Definition: elapsedtime.cpp:115
double elapsedTime
Definition: elapsedtime.h:98
double split()
ElapsedTime::split, gets the current elapsed time since the start()
Definition: elapsedtime.cpp:234
void ElapsedTime::info ( )

ElapsedTime::info, combines toc and print, this simplifies the calling of functions.

92  {
93 #ifndef CROSS_TYPE_arm
94  std::cout << "system_clock" << std::endl;
95  std::cout << std::chrono::system_clock::period::num << std::endl;
96  std::cout << std::chrono::system_clock::period::den << std::endl;
97  std::cout << "steady = " << std::boolalpha << std::chrono::system_clock::is_steady << std::endl << std::endl;
98 
99  std::cout << "high_resolution_clock" << std::endl;
100  std::cout << std::chrono::high_resolution_clock::period::num << std::endl;
101  std::cout << std::chrono::high_resolution_clock::period::den << std::endl;
102  std::cout << "steady = " << std::boolalpha << std::chrono::high_resolution_clock::is_steady << std::endl << std::endl;
103 
104  std::cout << "steady_clock" << std::endl;
105  std::cout << std::chrono::steady_clock::period::num << std::endl;
106  std::cout << std::chrono::steady_clock::period::den << std::endl;
107  std::cout << "steady = " << std::boolalpha << std::chrono::steady_clock::is_steady << std::endl << std::endl;
108 #endif
109 
110 }

Member Data Documentation

std::chrono::steady_clock::time_point ElapsedTime::timeStart
private
std::chrono::steady_clock::time_point ElapsedTime::timeStop
private
std::chrono::steady_clock::time_point ElapsedTime::timeNow
private
std::chrono::steady_clock::time_point ElapsedTime::timeCheck
private
bool ElapsedTime::print = true
double ElapsedTime::elapsedTime = 0.

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