Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
TimeStats.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/* TimeStats.h (C) 2000-2024 */
9/* */
10/* Statistics on execution times. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_IMPL_TIMESTATS_H
13#define ARCANE_IMPL_TIMESTATS_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/List.h"
18#include "arcane/utils/TraceAccessor.h"
19#include "arcane/utils/FixedArray.h"
20
21#include "arcane/core/ITimeStats.h"
22
23#include <stack>
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace Arcane
29{
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
37class TimeStats
38: public TraceAccessor
39, public ITimeStats
40{
41 public:
42
43 class Action;
44 class ActionSeries;
45 class PhaseValue;
46 class MetricCollector;
47 using ActionList = List<Action*>;
48
49 enum eTimeType
50 {
51 TT_Real = 0,
52 TT_Virtual
53 };
54
56 static const Integer NB_TIME_TYPE = 2;
57
58 static const Integer TC_Local = 0;
59 static const Integer TC_Cumulative = 1;
60
61 struct TimeValue
62 {
63 public:
64
65 TimeValue(Real real_time, Real virtual_time)
66 {
67 m_time[TT_Real][TC_Local] = real_time;
68 m_time[TT_Virtual][TC_Local] = virtual_time;
69 }
70 TimeValue()
71 {
72 }
73
74 public:
75
76 void add(const TimeValue& phase)
77 {
78 for (Integer i = 0; i < NB_TIME_TYPE; ++i)
79 m_time[i][TC_Local] += phase.m_time[i][TC_Local];
80 }
81
82 public:
83
85 };
86
87 class PhaseValue
88 : public TimeValue
89 {
90 public:
91
92 PhaseValue(eTimePhase pt, Real real_time, Real virtual_time)
93 : TimeValue(real_time, virtual_time)
94 , m_type(pt)
95 {}
96 PhaseValue() = default;
97
98 public:
99
100 eTimePhase phase() const { return m_type; }
101
102 public:
103
104 eTimePhase m_type = TP_Computation;
105 };
106
107 public:
108
109 TimeStats(ITimerMng* timer_mng, ITraceMng* trm, const String& name);
110 TimeStats(const TimeStats& rhs) = delete;
111 TimeStats& operator=(const TimeStats& rhs) = delete;
112 ~TimeStats() override;
113
114 public:
115
116 void beginGatherStats() override;
117 void endGatherStats() override;
118
119 public:
120
121 void beginAction(const String& action_name) override;
122 void endAction(const String& action_name, bool print_time) override;
123 void beginPhase(eTimePhase phase_type) override;
124 void endPhase(eTimePhase phase_type) override;
125
126 public:
127
128 Real elapsedTime(eTimePhase phase) override;
129 Real elapsedTime(eTimePhase phase, const String& action) override;
130
131 public:
132
133 void dumpStats(std::ostream& ostr, bool is_verbose, Real nb,
134 const String& name, bool use_elapsed_time) override;
135 void dumpCurrentStats(const String& action) override;
136
137 void dumpTimeAndMemoryUsage(IParallelMng* pm) override;
138
139 bool isGathering() const override;
140
141 void dumpStatsJSON(JSONWriter& writer) override;
142
144
145 void notifyNewIterationLoop() override;
146 void saveTimeValues(Properties* p) override;
147 void mergeTimeValues(Properties* p) override;
148
149 void resetStats(const String& name) override;
150
151 private:
152
153 ITimerMng* m_timer_mng = nullptr;
154 Timer* m_virtual_timer = nullptr;
155 Timer* m_real_timer = nullptr;
156 bool m_is_gathering = false;
157 PhaseValue m_current_phase;
162 Action* m_main_action = nullptr;
163 Action* m_current_action = nullptr;
164 std::stack<eTimePhase> m_phases_type;
165 bool m_need_compute_elapsed_time = false;
166 std::ostringstream m_full_stats_str;
167 bool m_full_stats = false;
168 String m_name;
169 ITimeMetricCollector* m_metric_collector = nullptr;
170
171 private:
172
173 Action* _currentAction();
174 PhaseValue _currentPhaseValue();
175 void _checkGathering();
176 void _computeCumulativeTimes();
177 void _dumpCumulativeTime(std::ostream& ostr, Action& action, eTimePhase tp, eTimeType tt);
178 void _dumpAllPhases(std::ostream& ostr, Action& action, eTimeType tt, int tc, Real nb);
179};
180
181/*---------------------------------------------------------------------------*/
182/*---------------------------------------------------------------------------*/
183
184} // End namespace Arcane
185
186/*---------------------------------------------------------------------------*/
187/*---------------------------------------------------------------------------*/
188
189#endif
Interface of the parallelism manager for a subdomain.
Interface managing statistics on execution.
Interface managing execution time statistics.
Definition ITimeStats.h:44
Interface of a timer manager.
Definition ITimerMng.h:50
Implementation of a collection of elements in vector form.
List of properties.
Definition Properties.h:65
Real elapsedTime(eTimePhase phase) override
Real elapsed time for phase phase.
Definition TimeStats.cc:427
void dumpStats(std::ostream &ostr, bool is_verbose, Real nb, const String &name, bool use_elapsed_time) override
Displays execution time statistics.
Definition TimeStats.cc:518
void endGatherStats() override
Stops time collection.
Definition TimeStats.cc:324
void dumpCurrentStats(const String &action) override
Displays statistics for an action.
Definition TimeStats.cc:536
ActionSeries * m_previous_action_series
Statistics on previous executions.
Definition TimeStats.h:161
bool isGathering() const override
Indicates if statistics are active.
Definition TimeStats.cc:831
void dumpStatsJSON(JSONWriter &writer) override
Serializes the temporal statistics into the writer writer.
Definition TimeStats.cc:850
ITimeMetricCollector * metricCollector() override
Associated collection interface.
void notifyNewIterationLoop() override
Notifies that a new iteration of the calculation loop begins.
static const Integer NB_TIME_TYPE
Number of eTimeType values.
Definition TimeStats.h:56
void beginGatherStats() override
Starts time collection.
Definition TimeStats.cc:300
ActionSeries * m_current_action_series
Statistics on current execution.
Definition TimeStats.h:159
void dumpTimeAndMemoryUsage(IParallelMng *pm) override
Displays the current date and memory consumption.
Definition TimeStats.cc:841
Management of a timer.
Definition Timer.h:63
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
-- 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.