Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
EnumeratorTraceWrapper.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/* EnumeratorTraceWrapper.h (C) 2000-2024 */
9/* */
10/* Enumerator over groups of mesh entities. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_ENUMERATORTRACEWRAPPER_H
13#define ARCANE_ENUMERATORTRACEWRAPPER_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/ArrayView.h"
18#include "arcane/utils/TraceInfo.h"
19
20#include <array>
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25#ifndef ARCANE_TRACE_ENUMERATOR
26// Uncomment if you want to always enable enumerator traces
27//#define ARCANE_TRACE_ENUMERATOR
28#endif
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33namespace Arcane
34{
35
36/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
38
39/*!
40 * \brief Information for an enumerator's traces.
41 */
43{
44 public:
45
46 //! Hardware counter values.
47 Int64ArrayView counters() { return Int64ArrayView(8, m_counters.data()); }
48
49 //! Start time in nanoseconds
50 Int64 beginTime() const { return m_begin_time; }
51
52 //! Sets the start time
53 void setBeginTime(Int64 v) { m_begin_time = v; }
54
55 //! Sets the trace information
56 void setTraceInfo(const TraceInfo* ti)
57 {
58 if (ti) {
59 m_trace_info = *ti;
60 m_has_trace_info = true;
61 }
62 else
63 m_has_trace_info = false;
64 }
65
66 //! Trace information (or nullptr) if none
67 const TraceInfo* traceInfo() const
68 {
69 return (m_has_trace_info) ? &m_trace_info : nullptr;
70 }
71
72 private:
73
74 std::array<Int64, 8> m_counters = {};
75 Int64 m_begin_time = 0;
76 TraceInfo m_trace_info;
77 bool m_has_trace_info = false;
78};
79
80/*---------------------------------------------------------------------------*/
81/*---------------------------------------------------------------------------*/
82
83/*!
84 * \brief Wrapper around an enumerator for traces.
85 *
86 * \a TrueEnumerator is the type of the actual enumerator and
87 * \a TraceInterface is that of the management interface. The type \a TraceInterface
88 * must have the following properties:
89 * - a singleton() method returning an instance.
90 * - an enterEnumerator() method and an exitEnumerator() method for
91 * each supported enumerator type.
92 */
93template <typename TrueEnumerator, typename TracerInterface>
94class EnumeratorTraceWrapper
95: public TrueEnumerator
96{
97 public:
98
99 ARCCORE_HOST_DEVICE EnumeratorTraceWrapper(TrueEnumerator&& tenum)
100 : TrueEnumerator(tenum)
101 {
102#ifndef ARCCORE_DEVICE_CODE
103 m_tracer = TracerInterface::singleton();
104 if (m_tracer)
105 m_tracer->enterEnumerator(*this, m_infos);
106#endif
107 }
108 ARCCORE_HOST_DEVICE EnumeratorTraceWrapper(TrueEnumerator&& tenum, [[maybe_unused]] const TraceInfo& ti)
109 : TrueEnumerator(tenum)
110 {
111#ifndef ARCCORE_DEVICE_CODE
112 m_tracer = TracerInterface::singleton();
113 if (m_tracer) {
114 m_infos.setTraceInfo(&ti);
115 m_tracer->enterEnumerator(*this, m_infos);
116 }
117#endif
118 }
119 ARCCORE_HOST_DEVICE ~EnumeratorTraceWrapper() ARCANE_NOEXCEPT_FALSE
120 {
121#ifndef ARCCORE_DEVICE_CODE
122 if (m_tracer)
123 m_tracer->exitEnumerator(*this, m_infos);
124#endif
125 }
126
127 private:
128
129 TracerInterface* m_tracer = nullptr;
130 EnumeratorTraceInfo m_infos;
131};
132
133/*---------------------------------------------------------------------------*/
134/*---------------------------------------------------------------------------*/
135
136#if defined(ARCANE_TRACE_ENUMERATOR)
137#define A_TRACE_ITEM_ENUMERATOR(_EnumeratorClassName) \
138 ::Arcane::EnumeratorTraceWrapper<_EnumeratorClassName, ::Arcane::IItemEnumeratorTracer>
139#define A_TRACE_ENUMERATOR_WHERE , A_FUNCINFO
140#else
141#define A_TRACE_ITEM_ENUMERATOR(_EnumeratorClassName) \
142 _EnumeratorClassName
143#define A_TRACE_ENUMERATOR_WHERE
144#endif
145
146/*---------------------------------------------------------------------------*/
147/*---------------------------------------------------------------------------*/
148
149} // namespace Arcane
150
151/*---------------------------------------------------------------------------*/
152/*---------------------------------------------------------------------------*/
153
154#endif
Information for an enumerator's traces.
const TraceInfo * traceInfo() const
Trace information (or nullptr) if none.
Int64 beginTime() const
Start time in nanoseconds.
Int64ArrayView counters()
Hardware counter values.
void setTraceInfo(const TraceInfo *ti)
Sets the trace information.
void setBeginTime(Int64 v)
Sets the start time.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
ArrayView< Int64 > Int64ArrayView
C equivalent of a 1D array of 64-bit integers.
Definition UtilsTypes.h:451
std::int64_t Int64
Signed integer type of 64 bits.