OMSimulatorLib The OMSimulator project is a FMI-based co-simulation environment.

Loading...
Searching...
No Matches
Clock.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenModelica.
3 *
4 * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
5 * c/o Linköpings universitet, Department of Computer and Information Science,
6 * SE-58183 Linköping, Sweden.
7 *
8 * All rights reserved.
9 *
10 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR
11 * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8.
12 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13 * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL
14 * VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
15 *
16 * The OpenModelica software and the OSMC (Open Source Modelica Consortium)
17 * Public License (OSMC-PL) are obtained from OSMC, either from the above
18 * address, from the URLs:
19 * http://www.openmodelica.org or
20 * https://github.com/OpenModelica/ or
21 * http://www.ida.liu.se/projects/OpenModelica,
22 * and in the OpenModelica distribution.
23 *
24 * GNU AGPL version 3 is obtained from:
25 * https://www.gnu.org/licenses/licenses.html#GPL
26 *
27 * This program is distributed WITHOUT ANY WARRANTY; without
28 * even the implied warranty of MERCHANTABILITY or FITNESS
29 * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
30 * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
31 *
32 * See the full OSMC Public License conditions for more details.
33 *
34 */
35
36#ifndef _OMS_CLOCK_H_
37#define _OMS_CLOCK_H_
38
39#include <ctime>
40#include <chrono>
41
42 class Clock
43{
44 public:
45 Clock();
46 ~Clock();
47
48 void tic();
49 void toc();
50 void reset();
51
52 double& getElapsedCPUTime();
53 double& getElapsedWallTime();
54
55 bool& isActive() {return active;}
56
57 private:
58 bool active;
59 std::clock_t startCPUTime;
60 std::chrono::system_clock::time_point startWallTime;
61 double elapsedCPUTime;
62 double elapsedWallTime;
63};
64
65 class CallClock
66{
67 public:
68 CallClock(Clock& clock) : clock(clock), active(clock.isActive()) {clock.tic();}
69 ~CallClock() {if (!active) clock.toc();}
70
71 private:
72 Clock& clock;
73 bool active;
74};
75
76#endif
CallClock
Definition Clock.h:66
CallClock::~CallClock
~CallClock()
Definition Clock.h:69
CallClock::CallClock
CallClock(Clock &clock)
Definition Clock.h:68
CallClock::clock
Clock & clock
Definition Clock.h:72
CallClock::active
bool active
Definition Clock.h:73
Clock
Definition Clock.h:43
Clock::reset
void reset()
Definition Clock.cpp:78
Clock::startWallTime
std::chrono::system_clock::time_point startWallTime
Definition Clock.h:60
Clock::toc
void toc()
Definition Clock.cpp:61
Clock::elapsedWallTime
double elapsedWallTime
Definition Clock.h:62
Clock::getElapsedCPUTime
double & getElapsedCPUTime()
Definition Clock.cpp:85
Clock::active
bool active
Definition Clock.h:58
Clock::getElapsedWallTime
double & getElapsedWallTime()
Definition Clock.cpp:96
Clock::elapsedCPUTime
double elapsedCPUTime
Definition Clock.h:61
Clock::startCPUTime
std::clock_t startCPUTime
Definition Clock.h:59
Clock::tic
void tic()
Definition Clock.cpp:51
Clock::isActive
bool & isActive()
Definition Clock.h:55
Clock::Clock
Clock()
Definition Clock.cpp:42
Clock::~Clock
~Clock()
Definition Clock.cpp:47