OOFEM 3.0
Loading...
Searching...
No Matches
timer.C
Go to the documentation of this file.
1/*
2 *
3 * ##### ##### ###### ###### ### ###
4 * ## ## ## ## ## ## ## ### ##
5 * ## ## ## ## #### #### ## # ##
6 * ## ## ## ## ## ## ## ##
7 * ## ## ## ## ## ## ## ##
8 * ##### ##### ## ###### ## ##
9 *
10 *
11 * OOFEM : Object Oriented Finite Element Code
12 *
13 * Copyright (C) 1993 - 2025 Borek Patzak
14 *
15 *
16 *
17 * Czech Technical University, Faculty of Civil Engineering,
18 * Department of Structural Mechanics, 166 29 Prague, Czech Republic
19 *
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License as published by the Free Software Foundation; either
23 * version 2.1 of the License, or (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Lesser General Public License for more details.
29 *
30 * You should have received a copy of the GNU Lesser General Public
31 * License along with this library; if not, write to the Free Software
32 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33 */
34
35#include "timer.h"
36
37#include <cstdio>
38
39#ifndef _WIN32 //_MSC_VER and __MINGW32__ included
40//for getrusage - user time reporting
41 #include <sys/resource.h>
42#else
43 #include <ctime>
44#endif
45
46namespace oofem {
47void Timer :: getUtime(std :: chrono :: duration< double > &answer)
48{
49#ifdef _WIN32 //_MSC_VER and __MINGW32__ included
50 clock_t utime = clock();
51 answer = std :: chrono :: seconds(utime / CLOCKS_PER_SEC);
52#else
53 struct rusage rsg;
54 getrusage(RUSAGE_SELF, & rsg);
55 answer = std :: chrono :: seconds(rsg.ru_utime.tv_sec) + std :: chrono :: microseconds(rsg.ru_utime.tv_usec);
56#endif
57}
58
59void Timer :: getTime(std :: chrono :: time_point< std :: chrono :: high_resolution_clock > &answer)
60{
61 answer = std :: chrono :: high_resolution_clock :: now();
62}
63
64Timer :: Timer()
65{
66 initTimer();
67}
68
69void Timer :: startTimer()
70{
71 this->initTimer();
72 this->getTime(start_wtime);
73 this->getUtime(start_utime);
74 running = true;
75}
76
77void Timer :: stopTimer()
78{
79 this->pauseTimer();
80 running = false;
81}
82
83void Timer :: pauseTimer()
84{
85 this->getTime(end_wtime);
86 this->getUtime(end_utime);
87 running = false;
88 this->updateElapsedTime();
89}
90
91void Timer :: resumeTimer()
92{
93 this->getTime(start_wtime);
94 this->getUtime(start_utime);
95 running = true;
96}
97
98void Timer :: initTimer()
99{
100 elapsedWTime = elapsedWTime.zero();
101 elapsedUTime = elapsedUTime.zero();
102 running = false;
103}
104
105double Timer :: getUtime()
106{
107 this->updateElapsedTime();
108 return elapsedUTime.count();
109}
110
111double Timer :: getWtime()
112{
114 return elapsedWTime.count();
115}
116
117void Timer :: convert2HMS(int &nhrs, int &nmin, int &nsec, double tsec)
118{
119 long int _nsec = ( long int ) tsec;
120 nhrs = 0;
121 nmin = 0;
122 if ( _nsec > 60 ) {
123 nmin = _nsec / 60;
124 _nsec %= 60;
125 }
126
127 if ( nmin > 60 ) {
128 nhrs = nmin / 60;
129 nmin %= 60;
130 }
131
132 nsec = _nsec;
133}
134
135void Timer :: toString(char *buff)
136{
137 std :: sprintf( buff, "ut: %f.3s, wt: %f.3s", getUtime(), getWtime() );
138}
139
140void Timer :: updateElapsedTime()
141{
142 if ( running ) {
143 pauseTimer();
144 resumeTimer();
145 }
146
149
152}
153
154double EngngModelTimer :: getUtime(EngngModelTimer :: EngngModelTimerType t)
155{
156 return timers [ t ].getUtime();
157}
158
159double EngngModelTimer :: getWtime(EngngModelTimer :: EngngModelTimerType t)
160{
161 return timers [ t ].getWtime();
162}
163
164void EngngModelTimer :: convert2HMS(int &nhrs, int &nmin, int &nsec, double tsec)
165{
166 Timer :: convert2HMS(nhrs, nmin, nsec, tsec);
167}
168
169void EngngModelTimer :: toString(EngngModelTimer :: EngngModelTimerType t, char *buff)
170{
171 return timers [ t ].toString(buff);
172}
173}
Timer timers[EMTT_LastTimer]
Array of Timer classes.
Definition timer.h:120
std ::chrono ::time_point< std ::chrono ::high_resolution_clock > end_wtime
Definition timer.h:49
void resumeTimer()
Definition timer.C:91
void updateElapsedTime()
Definition timer.C:140
std ::chrono ::duration< double > end_utime
Definition timer.h:51
std ::chrono ::duration< double > elapsedUTime
Definition timer.h:53
void getTime(std ::chrono ::time_point< std ::chrono ::high_resolution_clock > &answer)
Platform independent wrapper for wall time.
Definition timer.C:59
bool running
Flag indicating whether timer is running.
Definition timer.h:55
void pauseTimer()
Definition timer.C:83
std ::chrono ::duration< double > start_utime
User time.
Definition timer.h:51
double getUtime()
Returns total user time elapsed in seconds.
Definition timer.C:105
std ::chrono ::duration< double > elapsedWTime
Accumulated wtime and utime (in seconds) from start.
Definition timer.h:53
void initTimer()
Definition timer.C:98
double getWtime()
Returns total elapsed wall clock time in seconds.
Definition timer.C:111
std ::chrono ::time_point< std ::chrono ::high_resolution_clock > start_wtime
Wall clock time markers.
Definition timer.h:49

This page is part of the OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak Bořek Patzák
Project e-mail: oofem@fsv.cvut.cz
Generated at for OOFEM by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2011