Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
Timer.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 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.cc (C) 2000-2019 */
9/* */
10/* Gestion d'un timer. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/ArcanePrecomp.h"
15
16#include "arcane/utils/PlatformUtils.h"
17#include "arcane/utils/String.h"
18#include "arcane/utils/TraceInfo.h"
19#include "arcane/utils/FatalErrorException.h"
20#include "arcane/utils/ITraceMng.h"
21#include "arcane/utils/Iostream.h"
22
23#include "arcane/Timer.h"
24#include "arcane/ISubDomain.h"
25#include "arcane/ITimerMng.h"
26#include "arcane/ITimeStats.h"
27
28#include "arccore/trace/TimeMetric.h"
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33ARCANE_BEGIN_NAMESPACE
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
37
38Timer::
39Timer(ISubDomain* sd,const String& name,eTimerType type)
40: Timer(sd->timerMng(),name,type)
41{
42}
43
44/*---------------------------------------------------------------------------*/
45/*---------------------------------------------------------------------------*/
46
48Timer(ITimerMng* tm,const String& name,eTimerType type)
49: m_timer_mng(tm)
50, m_type(type)
51, m_nb_activated(0)
52, m_is_activated(false)
53, m_activation_time(0.0)
54, m_total_time(0.0)
55, m_name(name)
56, m_start_time(0.0)
57{
58}
59
60/*---------------------------------------------------------------------------*/
61/*---------------------------------------------------------------------------*/
62
64~Timer()
65{
66}
67
68/*---------------------------------------------------------------------------*/
69/*---------------------------------------------------------------------------*/
70
72start()
73{
75 ARCANE_FATAL("Timer is already activated");
76
77 //\todo Get time
80
82 m_is_activated = true;
83}
84
85/*---------------------------------------------------------------------------*/
86/*---------------------------------------------------------------------------*/
87
89stop()
90{
91 if (m_is_activated){
93 m_is_activated = false;
95 }
96 else
97 ARCANE_FATAL("Timer is not activated");
98 return m_activation_time;
99}
100
102reset()
103{
104 m_is_activated = false;
105 m_activation_time = 0.0;
106 m_total_time = 0.0;
107
108}
109
110/*---------------------------------------------------------------------------*/
111/*---------------------------------------------------------------------------*/
112
113/*---------------------------------------------------------------------------*/
114/*---------------------------------------------------------------------------*/
115
116/*---------------------------------------------------------------------------*/
117/*---------------------------------------------------------------------------*/
118
119void Timer::Action::
120_init()
121{
122 if (m_stats)
123 if (!m_stats->isGathering())
124 m_stats = 0;
125 if (m_stats)
126 m_stats->beginAction(m_action_name);
127}
128
129/*---------------------------------------------------------------------------*/
130/*---------------------------------------------------------------------------*/
131
132Timer::Action::
133Action(ISubDomain* sub_domain,const String& action_name,bool print_time)
134: m_stats(0)
135, m_action_name(action_name)
136, m_print_time(print_time)
137{
138 if (sub_domain)
139 m_stats = sub_domain->timeStats();
140 _init();
141}
142
143/*---------------------------------------------------------------------------*/
144/*---------------------------------------------------------------------------*/
145
146Timer::Action::
147Action(ITimeStats* stats,const String& action_name,bool print_time)
148: m_stats(stats)
149, m_action_name(action_name)
150, m_print_time(print_time)
151{
152 _init();
153}
154
155/*---------------------------------------------------------------------------*/
156/*---------------------------------------------------------------------------*/
157
158Timer::Action::
159~Action()
160{
161 if (m_stats)
162 m_stats->endAction(m_action_name,m_print_time);
163}
164
165/*---------------------------------------------------------------------------*/
166/*---------------------------------------------------------------------------*/
167
168/*---------------------------------------------------------------------------*/
169/*---------------------------------------------------------------------------*/
170
171void Timer::Phase::
172_init()
173{
174 if (m_stats)
175 if (!m_stats->isGathering())
176 m_stats = 0;
177 if (m_stats)
178 m_stats->beginPhase(m_phase_type);
179}
180
181/*---------------------------------------------------------------------------*/
182/*---------------------------------------------------------------------------*/
183
184Timer::Phase::
185Phase(ISubDomain* sub_domain,eTimePhase pt)
186: m_stats(0)
187, m_phase_type(pt)
188{
189 if (sub_domain)
190 m_stats = sub_domain->timeStats();
191 _init();
192}
193
194/*---------------------------------------------------------------------------*/
195/*---------------------------------------------------------------------------*/
196
197Timer::Phase::
198Phase(ITimeStats* stats,eTimePhase pt)
199: m_stats(stats)
200, m_phase_type(pt)
201{
202 _init();
203}
204
205/*---------------------------------------------------------------------------*/
206/*---------------------------------------------------------------------------*/
207
208Timer::Phase::
209~Phase()
210{
211 if (m_stats)
212 m_stats->endPhase(m_phase_type);
213}
214
215/*---------------------------------------------------------------------------*/
216/*---------------------------------------------------------------------------*/
217
218/*---------------------------------------------------------------------------*/
219/*---------------------------------------------------------------------------*/
220
221Timer::SimplePrinter::
222SimplePrinter(ITraceMng* tm,const String& msg)
223: m_trace_mng(tm)
224, m_begin_time(0.0)
225, m_is_active(true)
226, m_message(msg)
227{
228 _init();
229}
230
231/*---------------------------------------------------------------------------*/
232/*---------------------------------------------------------------------------*/
233
234Timer::SimplePrinter::
235SimplePrinter(ITraceMng* tm,const String& msg,bool is_active)
236: m_trace_mng(tm)
237, m_begin_time(0.0)
238, m_is_active(is_active)
239, m_message(msg)
240{
241 _init();
242}
243
244/*---------------------------------------------------------------------------*/
245/*---------------------------------------------------------------------------*/
246
247Timer::SimplePrinter::
248~SimplePrinter()
249{
250 if (m_is_active){
251 Real end_time = platform::getRealTime();
252 Real diff_time = end_time - m_begin_time;
253 m_trace_mng->info() << m_message << " time=" << diff_time;
254 }
255}
256
257/*---------------------------------------------------------------------------*/
258/*---------------------------------------------------------------------------*/
259
260void Timer::SimplePrinter::
261_init()
262{
263 if (m_is_active)
264 m_begin_time = platform::getRealTime();
265}
266
267/*---------------------------------------------------------------------------*/
268/*---------------------------------------------------------------------------*/
269
270TimeMetricAction Timer::
271phaseAction(ITimeStats* s,eTimePhase phase)
272{
273 ITimeMetricCollector* c = nullptr;
274 if (s)
275 c = s->metricCollector();
276 if (!c)
277 return TimeMetricAction();
278 return TimeMetricAction(c,TimeMetricActionBuildInfo(String(),phase));
279}
280
281/*---------------------------------------------------------------------------*/
282/*---------------------------------------------------------------------------*/
283
284ARCANE_END_NAMESPACE
285
286/*---------------------------------------------------------------------------*/
287/*---------------------------------------------------------------------------*/
288
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Interface du gestionnaire d'un sous-domaine.
Definition ISubDomain.h:74
virtual bool isGathering() const =0
Indique si les statistiques sont actives.
Interface d'un gestionnaire de timer.
Definition ITimerMng.h:53
virtual Real endTimer(Timer *timer)=0
Relâche le timer timer.
virtual void beginTimer(Timer *timer)=0
Attache le timer timer à ce gestionnaire.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
ITimeStats * m_stats
Gestionnaire de sous-domaine.
Definition Timer.h:136
Gestion d'un timer.
Definition Timer.h:62
Real m_activation_time
Temps passé lors de la dernière activation.
Definition Timer.h:245
Integer m_nb_activated
Nombre de fois que le timer a été activé
Definition Timer.h:243
Real stop()
Désactive le timer.
Definition Timer.cc:89
eTimerType
Type du timer.
Definition Timer.h:67
~Timer()
Libère les ressources.
Definition Timer.cc:64
ITimerMng * m_timer_mng
Gestionnaire de timer.
Definition Timer.h:241
Timer(ISubDomain *sd, const String &name, eTimerType type)
Construit un timer.
Definition Timer.cc:39
void reset()
Remet à zéro les compteurs de temps.
Definition Timer.cc:102
bool m_is_activated
true si le timer est actif
Definition Timer.h:244
void start()
Active le timer.
Definition Timer.cc:72
Real m_total_time
Temps total passé dans le timer.
Definition Timer.h:246
virtual TraceMessage info()=0
Flot pour un message d'information.
Chaîne de caractères unicode.
eTimePhase
Phase d'une action temporelle.