Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
EnumeratorTracer.cc
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/* EnumeratorTracer.cc (C) 2000-2023 */
9/* */
10/* Enumerators on material cells. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/materials/EnumeratorTracer.h"
15
16#include "arcane/utils/IPerformanceCounterService.h"
17#include "arcane/utils/Profiling.h"
18#include "arcane/utils/PlatformUtils.h"
19#include "arcane/utils/ForLoopTraceInfo.h"
20
21#include "arcane/materials/MatItemEnumerator.h"
22
23#include <iostream>
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace Arcane::Materials
29{
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34EnumeratorTracer::
35EnumeratorTracer(ITraceMng* tm, Ref<IPerformanceCounterService> perf_service)
36: TraceAccessor(tm)
37, m_perf_counter(perf_service)
38{
39}
40
41/*---------------------------------------------------------------------------*/
42/*---------------------------------------------------------------------------*/
43
44EnumeratorTracer::
45~EnumeratorTracer()
46{
47}
48
49/*---------------------------------------------------------------------------*/
50/*---------------------------------------------------------------------------*/
51
52void EnumeratorTracer::
53_beginLoop(EnumeratorTraceInfo& eti)
54{
55 ++m_nb_call;
56 m_perf_counter->getCounters(eti.counters(), false);
57 eti.setBeginTime(platform::getRealTimeNS());
58}
59
60/*---------------------------------------------------------------------------*/
61/*---------------------------------------------------------------------------*/
62
63void EnumeratorTracer::
64_endLoop(EnumeratorTraceInfo& eti)
65{
66 m_perf_counter->getCounters(eti.counters(), true);
67 const TraceInfo* ti = eti.traceInfo();
68 ForLoopTraceInfo loop_trace_info;
69 if (ti)
70 loop_trace_info = ForLoopTraceInfo(*ti);
71 ForLoopOneExecStat exec_stat;
72 exec_stat.setBeginTime(eti.beginTime());
73 exec_stat.setEndTime(platform::getRealTimeNS());
74 ProfilingRegistry::_threadLocalForLoopInstance()->merge(exec_stat, loop_trace_info);
75}
76
77/*---------------------------------------------------------------------------*/
78/*---------------------------------------------------------------------------*/
79
80void EnumeratorTracer::
81enterEnumerator(const ComponentEnumerator& e, EnumeratorTraceInfo& eti)
82{
83 _beginLoop(eti);
84 const TraceInfo* ti = eti.traceInfo();
85 if (ti && m_is_verbose)
86 info() << "Enum size=" << e.m_size << " where=" << *ti;
87}
88
89/*---------------------------------------------------------------------------*/
90/*---------------------------------------------------------------------------*/
91
92void EnumeratorTracer::
93exitEnumerator(const ComponentEnumerator&, EnumeratorTraceInfo& eti)
94{
95 _endLoop(eti);
96 if (m_is_verbose)
97 info() << "EndLoop: Component counters=" << eti.counters();
98}
99
100/*---------------------------------------------------------------------------*/
101/*---------------------------------------------------------------------------*/
102
103void EnumeratorTracer::
104enterEnumerator(const MatEnumerator&, EnumeratorTraceInfo& eti)
105{
106 _beginLoop(eti);
107}
108
109/*---------------------------------------------------------------------------*/
110/*---------------------------------------------------------------------------*/
111
112void EnumeratorTracer::
113exitEnumerator(const MatEnumerator&, EnumeratorTraceInfo& eti)
114{
115 _endLoop(eti);
116}
117
118/*---------------------------------------------------------------------------*/
119/*---------------------------------------------------------------------------*/
120
121void EnumeratorTracer::
122enterEnumerator(const EnvEnumerator&, EnumeratorTraceInfo& eti)
123{
124 _beginLoop(eti);
125}
126
127/*---------------------------------------------------------------------------*/
128/*---------------------------------------------------------------------------*/
129
130void EnumeratorTracer::
131exitEnumerator(const EnvEnumerator&, EnumeratorTraceInfo& eti)
132{
133 _endLoop(eti);
134}
135
136/*---------------------------------------------------------------------------*/
137/*---------------------------------------------------------------------------*/
138
139void EnumeratorTracer::
140enterEnumerator(const ComponentCellEnumerator& e, EnumeratorTraceInfo& eti)
141{
142 ++m_nb_call_component_cell;
143 m_nb_loop_component_cell += e.m_size;
144 const TraceInfo* ti = eti.traceInfo();
145 if (ti && m_is_verbose)
146 info() << "ComponentCell size=" << e.m_size << " where=" << *ti;
147 _beginLoop(eti);
148}
149
150/*---------------------------------------------------------------------------*/
151/*---------------------------------------------------------------------------*/
152
153void EnumeratorTracer::
154exitEnumerator(const ComponentCellEnumerator&, EnumeratorTraceInfo& eti)
155{
156 _endLoop(eti);
157 if (m_is_verbose)
158 info() << "EndLoop: ComponentCell counters=" << eti.counters();
159}
160
161/*---------------------------------------------------------------------------*/
162/*---------------------------------------------------------------------------*/
163
164void EnumeratorTracer::
165enterEnumerator(const AllEnvCellEnumerator& e, EnumeratorTraceInfo& eti)
166{
167 ++m_nb_call_all_env_cell;
168 m_nb_loop_all_env_cell += e.m_size;
169
170 const TraceInfo* ti = eti.traceInfo();
171 if (ti && m_is_verbose)
172 info() << "ComponentCell size=" << e.m_size << " where=" << *ti;
173 _beginLoop(eti);
174}
175
176/*---------------------------------------------------------------------------*/
177/*---------------------------------------------------------------------------*/
178
179void EnumeratorTracer::
180exitEnumerator(const AllEnvCellEnumerator&, EnumeratorTraceInfo& eti)
181{
182 _endLoop(eti);
183 if (m_is_verbose)
184 info() << "EndLoop: AllEnvCell counters=" << eti.counters();
185}
186
187/*---------------------------------------------------------------------------*/
188/*---------------------------------------------------------------------------*/
189
190void EnumeratorTracer::
191enterEnumerator(const CellComponentCellEnumerator& e, EnumeratorTraceInfo& eti)
192{
193 ++m_nb_call_cell_component_cell;
194 m_nb_loop_cell_component_cell += e.m_size;
195 _beginLoop(eti);
196}
197
198/*---------------------------------------------------------------------------*/
199/*---------------------------------------------------------------------------*/
200
201void EnumeratorTracer::
202exitEnumerator(const CellComponentCellEnumerator&, EnumeratorTraceInfo& eti)
203{
204 _endLoop(eti);
205}
206
207/*---------------------------------------------------------------------------*/
208/*---------------------------------------------------------------------------*/
209
210void EnumeratorTracer::
211enterEnumerator(const ComponentPartSimdCellEnumerator&, EnumeratorTraceInfo& eti)
212{
213 _beginLoop(eti);
214}
215
216/*---------------------------------------------------------------------------*/
217/*---------------------------------------------------------------------------*/
218
219void EnumeratorTracer::
220exitEnumerator(const ComponentPartSimdCellEnumerator&, EnumeratorTraceInfo& eti)
221{
222 _endLoop(eti);
223}
224
225/*---------------------------------------------------------------------------*/
226/*---------------------------------------------------------------------------*/
227
228void EnumeratorTracer::
229enterEnumerator(const ComponentPartCellEnumerator&, EnumeratorTraceInfo& eti)
230{
231 _beginLoop(eti);
232}
233
234/*---------------------------------------------------------------------------*/
235/*---------------------------------------------------------------------------*/
236
237void EnumeratorTracer::
238exitEnumerator(const ComponentPartCellEnumerator&, EnumeratorTraceInfo& eti)
239{
240 _endLoop(eti);
241}
242
243/*---------------------------------------------------------------------------*/
244/*---------------------------------------------------------------------------*/
245
246void EnumeratorTracer::
247dumpStats()
248{
249 info() << "ENUMERATOR_TRACER_DUMP_STATS nb_call=" << m_nb_call;
250 info() << " nb_call_all_env_cell=" << m_nb_call_all_env_cell
251 << " nb_loop_all_env_cell=" << m_nb_loop_all_env_cell
252 << " ratio=" << (Real)m_nb_loop_all_env_cell / (Real)(m_nb_call_all_env_cell + 1);
253 info() << " nb_call_component_cell=" << m_nb_call_component_cell
254 << " nb_loop_component_cell=" << m_nb_loop_component_cell
255 << " ratio=" << (Real)m_nb_loop_component_cell / (Real)(m_nb_call_component_cell + 1);
256 info() << " nb_call_cell_component_cell=" << m_nb_call_cell_component_cell
257 << " nb_loop_cell_component_cell=" << m_nb_loop_cell_component_cell
258 << " ratio=" << (Real)m_nb_loop_cell_component_cell / (Real)(m_nb_call_cell_component_cell + 1);
259}
260
261/*---------------------------------------------------------------------------*/
262/*---------------------------------------------------------------------------*/
263
264} // End namespace Arcane::Materials
265
266/*---------------------------------------------------------------------------*/
267/*---------------------------------------------------------------------------*/
Always enables tracing in Arcane parts concerning materials.
double Real
Type representing a real number.