UG

Ubiquity Generator framework

paraSysTimer.h
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the program and software framework */
4/* UG --- Ubquity Generator Framework */
5/* */
6/* Copyright Written by Yuji Shinano <shinano@zib.de>, */
7/* Copyright (C) 2021-2026 by Zuse Institute Berlin, */
8/* licensed under LGPL version 3 or later. */
9/* Commercial licenses are available through <licenses@zib.de> */
10/* */
11/* This code is free software; you can redistribute it and/or */
12/* modify it under the terms of the GNU Lesser General Public License */
13/* as published by the Free Software Foundation; either version 3 */
14/* of the License, or (at your option) any later version. */
15/* */
16/* This program is distributed in the hope that it will be useful, */
17/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
19/* GNU Lesser General Public License for more details. */
20/* */
21/* You should have received a copy of the GNU Lesser General Public License */
22/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
23/* */
24/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
25
26/**@file paraSysTimer.h
27 * @brief System timer.
28 * @author Yuji Shinano
29 *
30 *
31 *
32 */
33
34/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35
36
37#ifndef __PARA_SYS_TIMER_H__
38#define __PARA_SYS_TIMER_H__
39
40//-------------------
41// include files
42//-------------------
43#include <chrono>
44#include "paraTimer.h"
45
46namespace UG
47{
48
49///
50/// Class ParaSysTimer
51///
52/// Wall-clock timing uses std::chrono::steady_clock (monotonic, high
53/// resolution). Process CPU user/system time uses getrusage() where available.
54///
55/// (Historically the real-time path was implemented with times()/HZ under a
56/// SYSV code path. On Linux times() reports in units of sysconf(_SC_CLK_TCK)
57/// (100), but TICKS was defined as the kernel HZ, so the elapsed wall time was
58/// scaled by the wrong constant -- a ~600 s run was measured as ~14 s, which in
59/// turn made the "limits/time" derived from it far too large. Using std::chrono
60/// removes the platform-specific tick arithmetic entirely.)
61///
62class ParaSysTimer : public ParaTimer {
63
64 std::chrono::steady_clock::time_point startPoint; ///< real time at start()
65 std::chrono::steady_clock::time_point stopPoint; ///< real time at stop()
66 double uTimeStart; ///< process user CPU seconds at start()
67 double uTimeStop; ///< process user CPU seconds at stop()
68 double sTimeStart; ///< process system CPU seconds at start()
69 double sTimeStop; ///< process system CPU seconds at stop()
70
71public:
72
73 ///
74 /// default constructor
75 ///
77 )
78 : startPoint(), stopPoint(),
79 uTimeStart(0.0), uTimeStop(0.0), sTimeStart(0.0), sTimeStop(0.0)
80 {
81 }
82
83 ///
84 /// destructor
85 ///
87 )
88 {
89 }
90
91 ///
92 /// initialize timer
93 ///
94 void init(
95 ParaComm* paraComm ///< communicator used
96 )
97 {
98 start();
99 }
100
101 ///
102 /// get elapsed time
103 /// @return elapsed time
104 ///
106 )
107 {
108 return getRTimeInterval();
109 }
110
111 ///
112 /// start timer
113 ///
114 void start(
115 void
116 );
117
118 ///
119 /// stop timer
120 ///
121 void stop(
122 void
123 );
124
125 ///
126 /// get start time
127 /// @return start time
128 ///
129 double getStartTime(
130 void
131 );
132
133 ///
134 /// get elapsed time from start time
135 /// @return elapsed time
136 ///
137 double getRTimeInterval(
138 void
139 );
140
141 ///
142 /// get real time between start timne and stop time
143 /// @return real time
144 ///
145 double getRTime(
146 void
147 );
148
149 ///
150 /// get user time between start timne and stop time
151 /// @return user time
152 ///
153 double getUTime(
154 void
155 );
156
157 ///
158 /// get system time between start timne and stop time
159 /// @return system time
160 ///
161 double getSTime(
162 void
163 );
164
165};
166
167}
168
169#endif // __PARA_SYS_TIMER_H__
Base class of communicator object.
Definition: paraComm.h:102
Class ParaSysTimer.
Definition: paraSysTimer.h:62
double sTimeStart
process system CPU seconds at start()
Definition: paraSysTimer.h:68
double getUTime(void)
get user time between start timne and stop time
~ParaSysTimer()
destructor
Definition: paraSysTimer.h:86
double uTimeStop
process user CPU seconds at stop()
Definition: paraSysTimer.h:67
double getSTime(void)
get system time between start timne and stop time
double getElapsedTime()
get elapsed time
Definition: paraSysTimer.h:105
void stop(void)
stop timer
double getStartTime(void)
get start time
void init(ParaComm *paraComm)
initialize timer
Definition: paraSysTimer.h:94
double uTimeStart
process user CPU seconds at start()
Definition: paraSysTimer.h:66
ParaSysTimer()
default constructor
Definition: paraSysTimer.h:76
double getRTimeInterval(void)
get elapsed time from start time
double sTimeStop
process system CPU seconds at stop()
Definition: paraSysTimer.h:69
std::chrono::steady_clock::time_point startPoint
real time at start()
Definition: paraSysTimer.h:64
std::chrono::steady_clock::time_point stopPoint
real time at stop()
Definition: paraSysTimer.h:65
void start(void)
start timer
double getRTime(void)
get real time between start timne and stop time
class ParaTimer
Definition: paraTimer.h:49
Base class for Timer.