COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
elapsedtime.h
Go to the documentation of this file.
1 /********************************************************************
2 * Copyright (C) 2015 by Interstel Technologies, Inc.
3 * and Hawaii Space Flight Laboratory.
4 *
5 * This file is part of the COSMOS/core that is the central
6 * module for COSMOS. For more information on COSMOS go to
7 * <http://cosmos-project.com>
8 *
9 * The COSMOS/core software is licenced under the
10 * GNU Lesser General Public License (LGPL) version 3 licence.
11 *
12 * You should have received a copy of the
13 * GNU Lesser General Public License
14 * If not, go to <http://www.gnu.org/licenses/>
15 *
16 * COSMOS/core is free software: you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public License
18 * as published by the Free Software Foundation, either version 3 of
19 * the License, or (at your option) any later version.
20 *
21 * COSMOS/core is distributed in the hope that it will be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
25 *
26 * Refer to the "licences" folder for further information on the
27 * condititons and terms to use this software.
28 ********************************************************************/
29 
30 //TODO: consider renaming this class to Timer or StopWatch
31 
32 #ifndef ELAPSED_TIME
33 #define ELAPSED_TIME
34 
35 #include "support/configCosmos.h"
36 #include <iostream>
37 #include <string>
38 #include <ctime>
39 
40 #ifdef CROSS_TYPE_arm
41 #include <sys/time.h>
42 #else
43 #include <chrono>
44 #endif
45 
50 
59 
60 // profiling class
61 // On windows using MinGw32 it does not get better than 1ms
62 class ElapsedTime {
63  //new for c++11
64 #ifdef CROSS_TYPE_arm
65  // struct timespec timeStart, timeNow, timeCheck;
67 #else
68  std::chrono::steady_clock::time_point timeStart, timeStop, timeNow, timeCheck; //
69 #endif
70 
71 public:
72  ElapsedTime();
73  //int timeval_subtract (struct timeval* result, struct timeval* x, struct timeval* y);
74  //float elapsed_time(struct timeval a,struct timeval b);
75  void printElapsedTime();
76  void printElapsedTime(string text);
77 
79  double getElapsedTime();
80  double getElapsedTimeSince(double startTimeMjd);
81  double getElapsedTime(double startMjd, double endMjd);
82 
83  double lap();
84  double split();
85  double check();
86  void reset();
87 
88  void start();
89  double stop();
90 
91  void tic();
92  double toc();
93  //double toc(bool print_flag);
94  double toc(string text);
95 
96  // turn on/off printing
97  bool print = true; //
98  double elapsedTime = 0.; // equivalent to reset chrono
99  void info();
100 
101 
102 };
103 
104 
105 
106 //class ElapsedTimeOld {
107 // // old plain c
108 // struct timeval time1, time2;
109 
110 // //IN UNIX the use of the timezone struct is obsolete;
111 // //See http://linux.about.com/od/commands/l/blcmdl2_gettime.htm
112 // struct timezone x;
113 // float timeDiff;
114 
115 
116 //public:
117 // int timeval_subtract (struct timeval* result, struct timeval* x, struct timeval* y);
118 // float elapsed_time(struct timeval a,struct timeval b);
119 //};
121 
122 
123 #endif
std::chrono::steady_clock::time_point timeCheck
Definition: elapsedtime.h:68
double getElapsedTime()
Definition: elapsedtime.cpp:251
void printElapsedTime()
ElapsedTime::printElapsedTime.
Definition: elapsedtime.cpp:115
double getElapsedTimeMiliSeconds()
double getElapsedTimeSince(double startTimeMjd)
Definition: elapsedtime.cpp:256
std::chrono::steady_clock::time_point timeStop
Definition: elapsedtime.h:68
double elapsedTime
Definition: elapsedtime.h:98
std::chrono::steady_clock::time_point timeStart
Definition: elapsedtime.h:68
void start()
ElapsedTime::start.
Definition: elapsedtime.cpp:203
bool print
Definition: elapsedtime.h:97
void tic()
ElapsedTime::tic, equivalent to matlab to start a stopwatch timer.
Definition: elapsedtime.cpp:166
double lap()
Lap Time.
Definition: elapsedtime.cpp:145
void info()
ElapsedTime::info, combines toc and print, this simplifies the calling of functions.
Definition: elapsedtime.cpp:92
Headers and definitions common to all COSMOS.
ElapsedTime()
ElapsedTime::ElapsedTime.
Definition: elapsedtime.cpp:82
double check()
Definition: elapsedtime.h:62
double stop()
ElapsedTime::stop.
Definition: elapsedtime.cpp:223
double toc()
ElapsedTime::toc, equivalent to matlab to stop a stopwatch timer.
Definition: elapsedtime.cpp:174
double split()
ElapsedTime::split, gets the current elapsed time since the start()
Definition: elapsedtime.cpp:234
void reset()
ElapsedTime::reset.
Definition: elapsedtime.cpp:278
std::chrono::steady_clock::time_point timeNow
Definition: elapsedtime.h:68