Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
Timer.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* Timer.h (C) 2000-2025 */
9/* */
10/* Management of a timer. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_TIMER_H
13#define ARCANE_CORE_TIMER_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/String.h"
18
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30class ITimerMng;
31class ITimeStats;
32
33/*---------------------------------------------------------------------------*/
34/*---------------------------------------------------------------------------*/
35
62class ARCANE_CORE_EXPORT Timer
63{
64 public:
65
79
80 public:
81
89 class ARCANE_CORE_EXPORT Sentry
90 {
91 public:
92
95 : m_timer(t)
96 {
97 m_timer->start();
98 }
99
101 {
102 m_timer->stop();
103 }
104
105 private:
106
108 };
109
118 class ARCANE_CORE_EXPORT Action
119 {
120 public:
121
122 Action(ISubDomain* sub_domain, const String& action_name, bool print_time = false);
123 Action(ITimeStats* stats, const String& action_name, bool print_time = false);
124 ~Action();
125
126 public:
127 private:
128
129 ITimeStats* m_stats;
130 String m_action_name;
131 bool m_print_time;
132
133 private:
134
135 void _init();
136 };
137
141 class ARCANE_CORE_EXPORT Phase
142 {
143 public:
144 public:
145
146 Phase(ISubDomain* sub_domain, eTimePhase pt);
147 Phase(ITimeStats* stats, eTimePhase pt);
148 ~Phase();
149
150 public:
151 private:
152
154 eTimePhase m_phase_type;
155
156 private:
157
158 void _init();
159 };
160
174 class ARCANE_CORE_EXPORT SimplePrinter
175 {
176 public:
177
178 SimplePrinter(ITraceMng* tm, const String& msg);
179 SimplePrinter(ITraceMng* tm, const String& msg, bool is_active);
180 ~SimplePrinter();
181
182 private:
183
184 ITraceMng* m_trace_mng;
185 Real m_begin_time;
186 bool m_is_active;
187 String m_message;
188
189 private:
190
191 void _init();
192 };
193
194 public:
195
203
211
212 ~Timer();
213
214 public:
215
221 void start();
222
231 Real stop();
232
234 bool isActivated() const { return m_is_activated; }
235
237 const String& name() const { return m_name; }
238
240 Real totalTime() const { return m_total_time; }
241
244
247
249 eTimerType type() const { return m_type; }
250
252 void reset();
253
255 ITimerMng* timerMng() const { return m_timer_mng; }
256
257 public:
258
259 static TimeMetricAction phaseAction(ITimeStats* s, eTimePhase phase);
260
261 public:
262
266 Real _startTime() const { return m_start_time; }
267
268 private:
269
278};
279
280/*---------------------------------------------------------------------------*/
281/*---------------------------------------------------------------------------*/
282
283} // End namespace Arcane
284
285/*---------------------------------------------------------------------------*/
286/*---------------------------------------------------------------------------*/
287
288#endif
Declarations of Arcane's general types.
Interface of the subdomain manager.
Definition ISubDomain.h:75
Interface managing execution time statistics.
Definition ITimeStats.h:44
Interface of a timer manager.
Definition ITimerMng.h:50
ITimeStats * m_stats
Sub-domain manager.
Definition Timer.h:153
Sentry(Timer *t)
Associates the timer t and starts it.
Definition Timer.h:94
~Sentry()
Stops the associated timer.
Definition Timer.h:100
Timer * m_timer
Associated timer.
Definition Timer.h:107
const String & name() const
Returns the name of the timer.
Definition Timer.h:237
void _setStartTime(Real t)
Definition Timer.h:264
Integer nbActivated() const
Returns the number of times the timer has been activated.
Definition Timer.h:246
eTimerType m_type
Timer type.
Definition Timer.h:271
Real m_activation_time
Time spent during the last activation.
Definition Timer.h:274
Integer m_nb_activated
Number of times the timer has been activated.
Definition Timer.h:272
String m_name
Timer name.
Definition Timer.h:276
Real _startTime() const
Definition Timer.h:266
ITimerMng * timerMng() const
Manager associated with this timer.
Definition Timer.h:255
Real stop()
Deactivates the timer.
Definition Timer.cc:87
eTimerType
Timer type.
Definition Timer.h:68
@ TimerReal
Timer using real time.
Definition Timer.h:77
@ TimerVirtual
Timer using CPU time (obsolete).
Definition Timer.h:75
ITimerMng * m_timer_mng
Timer manager.
Definition Timer.h:270
eTimerType type() const
Returns the type of time used.
Definition Timer.h:249
Timer(ISubDomain *sd, const String &name, eTimerType type)
Constructs a timer.
Definition Timer.cc:37
Real totalTime() const
Returns the total time (in seconds) spent in the timer.
Definition Timer.h:240
Real m_start_time
Time of the start of the last activation.
Definition Timer.h:277
bool isActivated() const
Returns the activation status of the timer.
Definition Timer.h:234
bool m_is_activated
true if the timer is active
Definition Timer.h:273
void start()
Activates the timer.
Definition Timer.cc:70
Real lastActivationTime() const
Returns the time (in seconds) spent during the last activation of the timer.
Definition Timer.h:243
Real m_total_time
Total time spent in the timer.
Definition Timer.h:275
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
double Real
Type representing a real number.
eTimePhase
Phase of a temporal action.