Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ItemEnumeratorTracer.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/* ItemEnumeratorTracer.cc (C) 2000-2023 */
9/* */
10/* Traces enumerator calls on entities. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/IPerformanceCounterService.h"
15
16#include "arcane/utils/PlatformUtils.h"
17#include "arcane/utils/Profiling.h"
18#include "arcane/utils/ForLoopTraceInfo.h"
19
22
23#include "arcane/impl/ItemEnumeratorTracer.h"
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace Arcane
29{
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34extern "C++" ARCANE_IMPL_EXPORT Ref<IItemEnumeratorTracer>
35arcaneCreateItemEnumeratorTracer(ITraceMng* tm, Ref<IPerformanceCounterService> perf_counter)
36{
38}
39
40/*---------------------------------------------------------------------------*/
41/*---------------------------------------------------------------------------*/
42
43ItemEnumeratorTracer::
44ItemEnumeratorTracer(ITraceMng* tm, Ref<IPerformanceCounterService> perf_counter)
45: TraceAccessor(tm)
46, m_perf_counter(perf_counter)
47{
48}
49
50/*---------------------------------------------------------------------------*/
51/*---------------------------------------------------------------------------*/
52
53ItemEnumeratorTracer::
54~ItemEnumeratorTracer()
55{
56}
57
58/*---------------------------------------------------------------------------*/
59/*---------------------------------------------------------------------------*/
60
61void ItemEnumeratorTracer::
62_beginLoop(EnumeratorTraceInfo& eti)
63{
64 ++m_nb_call;
65 m_perf_counter->getCounters(eti.counters(), false);
66 eti.setBeginTime(platform::getRealTimeNS());
67}
68
69/*---------------------------------------------------------------------------*/
70/*---------------------------------------------------------------------------*/
71
72void ItemEnumeratorTracer::
73_endLoop(EnumeratorTraceInfo& eti)
74{
75 m_perf_counter->getCounters(eti.counters(), true);
76 const TraceInfo* ti = eti.traceInfo();
77 ForLoopTraceInfo loop_trace_info;
78 if (ti)
79 loop_trace_info = ForLoopTraceInfo(*ti);
80 ForLoopOneExecStat exec_stat;
81 exec_stat.setBeginTime(eti.beginTime());
82 exec_stat.setEndTime(platform::getRealTimeNS());
83 ProfilingRegistry::_threadLocalForLoopInstance()->merge(exec_stat, loop_trace_info);
84}
85
86/*---------------------------------------------------------------------------*/
87/*---------------------------------------------------------------------------*/
88
89void ItemEnumeratorTracer::
90enterEnumerator(const ItemEnumerator& e, EnumeratorTraceInfo& eti)
91{
92 m_nb_loop += e.count();
93 Int64 begin_time = platform::getRealTimeNS();
94 const TraceInfo* ti = eti.traceInfo();
95 if (ti && m_is_verbose)
96 info() << "Loop:" << (*ti) << " count=" << e.count() << " begin_time=" << begin_time;
97 _beginLoop(eti);
98}
99
100/*---------------------------------------------------------------------------*/
101/*---------------------------------------------------------------------------*/
102
103void ItemEnumeratorTracer::
104exitEnumerator(const ItemEnumerator&, EnumeratorTraceInfo& eti)
105{
106 _endLoop(eti);
107 if (m_is_verbose)
108 info() << "EndLoop: cycle=" << eti.counters()[0] << " fp=" << eti.counters()[1]
109 << " L2DCM=" << eti.counters()[2];
110}
111
112/*---------------------------------------------------------------------------*/
113/*---------------------------------------------------------------------------*/
114
115void ItemEnumeratorTracer::
116enterEnumerator(const SimdItemEnumeratorBase& e, EnumeratorTraceInfo& eti)
117{
118 const TraceInfo* ti = eti.traceInfo();
119 if (ti && m_is_verbose)
120 info() << "SimdLoop:" << (*ti) << " count=" << e.count();
121 _beginLoop(eti);
122}
123
124/*---------------------------------------------------------------------------*/
125/*---------------------------------------------------------------------------*/
126
127void ItemEnumeratorTracer::
128exitEnumerator(const SimdItemEnumeratorBase&, EnumeratorTraceInfo& eti)
129{
130 _endLoop(eti);
131 if (m_is_verbose)
132 info() << "EndSimdLoop: cycle=" << eti.counters()[0] << " fp=" << eti.counters()[1]
133 << " L2DCM=" << eti.counters()[2];
134}
135
136/*---------------------------------------------------------------------------*/
137/*---------------------------------------------------------------------------*/
138
139void ItemEnumeratorTracer::
140dumpStats()
141{
142 info() << "ITEM_ENUMERATOR_TRACER Stats";
143 info() << " nb_call=" << m_nb_call
144 << " nb_loop=" << m_nb_loop
145 << " ratio=" << (Real)m_nb_loop / (Real)(m_nb_call + 1);
146}
147
148/*---------------------------------------------------------------------------*/
149/*---------------------------------------------------------------------------*/
150
151} // End namespace Arcane
152
153/*---------------------------------------------------------------------------*/
154/*---------------------------------------------------------------------------*/
Types and macros for iterating over mesh entities.
Information for an enumerator's traces.
const TraceInfo * traceInfo() const
Trace information (or nullptr) if none.
Int64ArrayView counters()
Hardware counter values.
constexpr Integer count() const
Number of elements in the enumerator.
Interface for an enumerator tracer on entities.
Enumerator over a list of entities.
Reference to an instance.
Base class for enumerators over vectorial entities (SimdItem).
Definition SimdItem.h:433
TraceMessage info() const
Flow for an information message.
Int64 getRealTimeNS()
Clock time in nanoseconds.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
double Real
Type representing a real number.
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Creates a reference on a pointer.