MeteoIODoc 20240503.aefd3c94
Timer.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2/***********************************************************************************/
3/* Copyright GridGroup, EIA-FR 2010 */
4/* Copyright 2010 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
5/***********************************************************************************/
6/* This file is part of MeteoIO.
7 MeteoIO is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 MeteoIO is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#ifndef TIMER_H
22#define TIMER_H
23
24#if !defined _WIN32 && !defined __MINGW32__
25 #include <sys/resource.h>
26#endif
27
29
30namespace mio {
31
40class Timer {
41public:
42 Timer();
43 void start();
44 void restart();
45 void stop();
46 void reset();
47 double getElapsed() const;
48 static long double getCurrentTime();
49
50protected:
51 long double start_point;
52 double elapsed;
54};
55
56#if !defined _WIN32 && !defined __MINGW32__
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;
83};
84#endif
85
104class WatchDog {
105 public:
110 WatchDog(const unsigned int& seconds);
111};
112
113} //end namespace mio
114#endif
Time code execution with at least 1 us resolution. The time resolution can be stored up to ....
Definition: Timer.h:40
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:87
Timer()
Default constructor. Initialize internal variables. It does NOT start timing.
Definition: Timer.cc:42
static long double getCurrentTime()
Get the current time.
Definition: Timer.cc:115
void stop()
Stop the timer. It can be restarted afterward, adding time to what was already timed.
Definition: Timer.cc:67
void reset()
Reset the timer to zero.
Definition: Timer.cc:77
void restart()
Reset and start the timer.
Definition: Timer.cc:58
long double start_point
Definition: Timer.h:51
void start()
Start the timer.
Definition: Timer.cc:48
double elapsed
Definition: Timer.h:52
bool isRunning
Definition: Timer.h:53
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
bool is_running
Definition: Timer.h:82
void restart()
Definition: Timer.cc:144
void getElapsedTimes()
Definition: Timer.cc:182
double getElapsed()
Definition: Timer.cc:155
struct rusage start_usage current_usage
Definition: Timer.h:80
double sys_time
Definition: Timer.h:81
double user_time
Definition: Timer.h:81
void stop()
Definition: Timer.cc:136
UsageTimer()
Definition: Timer.cc:126
double elapsed
Definition: Timer.h:81
void start()
Definition: Timer.cc:128
void reset()
Definition: Timer.cc:151
double getElapsedSystemTime()
Definition: Timer.cc:173
double getElapsedUserTime()
Definition: Timer.cc:164
A software watchdog, killing the current process after the given number of seconds.
Definition: Timer.h:104
WatchDog(const unsigned int &seconds)
Create the watchdog.
Definition: Timer.cc:232
Definition: Config.cc:31