Arcane  4.2.3.0
User documentation
Loading...
Searching...
No Matches
IProfilingService.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/* IProfilingService.h (C) 2000-2026 */
9/* */
10/* Interface of a profiling service. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_IPROFILINGSERVICE_H
13#define ARCANE_UTILS_IPROFILINGSERVICE_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane
23{
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28class ITimerMng;
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32/*!
33 * \internal
34 * \brief Interface of a profiling service.
35 *
36 * initialize() must be called before using the instance. You can
37 * then call startProfiling()/stopProfiling() to start and
38 * stop profiling.
39 *
40 * When profiling is stopped, you can call printInfos() to
41 * display the profiling information. The reset() method allows you to
42 * reset the profiling information.
43 */
44class ARCANE_UTILS_EXPORT IProfilingService
45{
46 public:
47
48 virtual ~IProfilingService() = default;
49
50 public:
51
52 /*!
53 * \brief Initializes the profiling service.
54 *
55 * This method can only be called once.
56 */
57 virtual void initialize() = 0;
58
59 //! Indicates if initialize() has already been called
60 virtual bool isInitialized() const { return false; }
61
62 //! Starts profiling
63 virtual void startProfiling() = 0;
64
65 virtual void switchEvent() = 0;
66
67 //! Stops profiling
68 virtual void stopProfiling() = 0;
69
70 /*!
71 * \brief Indicates if the profiling is running.
72 *
73 * The profiling is running between a call to startProfiling()
74 * and stopProfiling().
75 */
76 virtual bool isRunning() const =0;
77
78 /*!
79 * \brief Displays profiling information.
80 *
81 * Profiling must be stopped.
82 * If \a dump_file is true, file outputs containing the information
83 * are generated, which may take time.
84 */
85 virtual void printInfos(bool dump_file = false) = 0;
86
87 virtual void getInfos(Int64Array&) = 0;
88
89 //! Writes the profiling information to the writer \a writer.
90 virtual void dumpJSON(JSONWriter& writer) = 0;
91
92 /*!
93 * \brief Resets the counters.
94 *
95 * Profiling must be stopped for this.
96 */
97 virtual void reset() = 0;
98
99 //! Timer using the features of this service if they exist. Can be null.
100 virtual ITimerMng* timerMng() = 0;
101};
102
103/*---------------------------------------------------------------------------*/
104/*---------------------------------------------------------------------------*/
105/*!
106 * \brief Class allowing automatic start and stop of a service.
107 */
108class ARCANE_UTILS_EXPORT ProfilingSentry
109{
110 public:
111
112 explicit ProfilingSentry(IProfilingService* s)
113 : m_service(s)
114 {
115 if (m_service)
116 m_service->startProfiling();
117 }
118 ~ProfilingSentry()
119 {
120 if (m_service)
121 m_service->stopProfiling();
122 }
123
124 public:
125
126 IProfilingService* service() { return m_service; }
127
128 private:
129
130 IProfilingService* m_service;
131};
132
133/*---------------------------------------------------------------------------*/
134/*---------------------------------------------------------------------------*/
135
136/*!
137 * \brief Class allowing automatic start and stop of a service.
138 *
139 * The service is initialized if necessary.
140 */
141class ARCANE_UTILS_EXPORT ProfilingSentryWithInitialize
142{
143 public:
144
145 /*!
146 * \brief Constructs an instance associated with the service \a s.
147 *
148 * If \a s is \a null, the instance does nothing.
149 */
151 : m_service(s)
152 {
153 if (m_service) {
154 if (!m_service->isInitialized())
155 m_service->initialize();
156 m_service->startProfiling();
157 }
158 }
159
161 {
162 if (m_service) {
163 m_service->stopProfiling();
164 if (m_print_at_end)
165 m_service->printInfos(false);
166 }
167 }
168
169 public:
170
171 IProfilingService* service() { return m_service; }
172 //! Indicates if results are printed at the end of profiling
173 void setPrintAtEnd(bool v) { m_print_at_end = v; }
174
175 private:
176
177 IProfilingService* m_service = nullptr;
178 bool m_print_at_end = false;
179};
180
181/*---------------------------------------------------------------------------*/
182/*---------------------------------------------------------------------------*/
183
184} // End namespace Arcane
185
186/*---------------------------------------------------------------------------*/
187/*---------------------------------------------------------------------------*/
188
189#endif
Declarations of types used in Arcane.
virtual bool isInitialized() const
Indicates if initialize() has already been called.
virtual ITimerMng * timerMng()=0
Timer using the features of this service if they exist. Can be null.
virtual bool isRunning() const =0
Indicates if the profiling is running.
virtual void stopProfiling()=0
Stops profiling.
virtual void startProfiling()=0
Starts profiling.
virtual void initialize()=0
Initializes the profiling service.
virtual void dumpJSON(JSONWriter &writer)=0
Writes the profiling information to the writer writer.
virtual void reset()=0
Resets the counters.
virtual void printInfos(bool dump_file=false)=0
Displays profiling information.
Interface of a timer manager.
Definition ITimerMng.h:50
Class allowing automatic start and stop of a service.
void setPrintAtEnd(bool v)
Indicates if results are printed at the end of profiling.
ProfilingSentryWithInitialize(IProfilingService *s)
Constructs an instance associated with the service s.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Array< Int64 > Int64Array
Dynamic one-dimensional array of 64-bit integers.
Definition UtilsTypes.h:119