MeteoIODoc  MeteoIODoc-2.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Timer.h
Go to the documentation of this file.
1 /***********************************************************************************/
2 /* Copyright GridGroup, EIA-FR 2010 */
3 /* Copyright 2010 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
4 /***********************************************************************************/
5 /* This file is part of MeteoIO.
6  MeteoIO is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  MeteoIO is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef TIMER_H
21 #define TIMER_H
22 
23 #if !defined _WIN32 && !defined __MINGW32__
24  #include <sys/resource.h>
25 #endif
26 
27 #include <meteoio/IOExceptions.h>
28 
29 namespace mio {
30 
39 class Timer {
40 public:
41  Timer();
42  void start();
43  void restart();
44  void stop();
45  void reset();
46  double getElapsed() const;
47 
48 protected:
49  long double getCurrentTime() const;
50 
51  long double start_point;
52  double elapsed;
53  bool isRunning;
54 };
55 
56 #if !defined _WIN32 && !defined __MINGW32__
57 
63 class UsageTimer {
64  public:
65  UsageTimer();
66  void start();
67  void restart();
68  void stop();
69  void reset();
70 
71  double getElapsed();
72  double getElapsedUserTime();
73  double getElapsedSystemTime();
74 
75  protected:
76  void getElapsedTimes();
77 
78  static const int who;
79 
80  struct rusage start_usage, current_usage;
82  bool is_running;
83 };
84 #endif
85 
86 } //end namespace mio
87 #endif
double getElapsedSystemTime()
Definition: Timer.cc:166
void reset()
Definition: Timer.cc:144
double elapsed
Definition: Timer.h:81
void getElapsedTimes()
Definition: Timer.cc:175
bool isRunning
Definition: Timer.h:53
void start()
Start the timer.
Definition: Timer.cc:43
double getElapsedUserTime()
Definition: Timer.cc:157
double user_time
Definition: Timer.h:81
Process usage timer for Posix This is based on getrusage and thus returns detailed timing information...
Definition: Timer.h:63
static const int who
Definition: Timer.h:78
long double start_point
Definition: Timer.h:51
bool is_running
Definition: Timer.h:82
void stop()
Stop the timer. It can be restarted afterward, adding time to what was already timed.
Definition: Timer.cc:62
double getElapsed()
Definition: Timer.cc:148
double sys_time
Definition: Timer.h:81
void start()
Definition: Timer.cc:121
double elapsed
Definition: Timer.h:52
Time code execution with at least 1 us resolution. The time resolution can be stored up to ...
Definition: Timer.h:39
long double getCurrentTime() const
Definition: Timer.cc:106
UsageTimer()
Definition: Timer.cc:119
void restart()
Definition: Timer.cc:137
void stop()
Definition: Timer.cc:129
Timer()
Default constructor. Initialize internal variables. It does NOT start timing.
Definition: Timer.cc:37
void restart()
Reset and start the timer.
Definition: Timer.cc:53
struct rusage start_usage current_usage
Definition: Timer.h:80
void reset()
Reset the timer to zero.
Definition: Timer.cc:72
double getElapsed() const
Get total elapsed time. It returns the sum of all the elapsed time between all the start/stop session...
Definition: Timer.cc:82