Arcane  4.1.12.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-2023 */
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/*!
34 * \internal
35 * \brief Interface of a profiling service.
36 *
37 * initialize() must be called before using the instance. You can
38 * then call startProfiling()/stopProfiling() to start and
39 * stop profiling.
40 *
41 * When profiling is stopped, you can call printInfos() to
42 * display the profiling information. The reset() method allows you to
43 * reset the profiling information.
44 */
45class ARCANE_UTILS_EXPORT IProfilingService
46{
47 public:
48
49 virtual ~IProfilingService() = default;
50
51 public:
52
53 /*!
54 * \brief Initializes the profiling service.
55 *
56 * This method can only be called once.
57 */
58 virtual void initialize() = 0;
59
60 //! Indicates if initialize() has already been called
61 virtual bool isInitialized() const { return false; }
62
63 //! Starts profiling
64 virtual void startProfiling() = 0;
65
66 virtual void switchEvent() = 0;
67
68 //! Stops profiling
69 virtual void stopProfiling() = 0;
70
71 /*!
72 * \brief Displays profiling information.
73 *
74 * Profiling must be stopped.
75 * If \a dump_file is true, file outputs containing the information
76 * are generated, which may take time.
77 */
78 virtual void printInfos(bool dump_file = false) = 0;
79
80 virtual void getInfos(Int64Array&) = 0;
81
82 //! Writes the profiling information to the writer \a writer.
83 virtual void dumpJSON(JSONWriter& writer) = 0;
84
85 /*!
86 * \brief Resets the counters.
87 *
88 * Profiling must be stopped for this.
89 */
90 virtual void reset() = 0;
91
92 //! Timer using the features of this service if they exist. Can be null.
93 virtual ITimerMng* timerMng() = 0;
94};
95
96/*---------------------------------------------------------------------------*/
97/*---------------------------------------------------------------------------*/
98
99/*!
100 * \brief Class allowing automatic start and stop of a service.
101 */
102class ARCANE_UTILS_EXPORT ProfilingSentry
103{
104 public:
105
106 explicit ProfilingSentry(IProfilingService* s)
107 : m_service(s)
108 {
109 if (m_service)
110 m_service->startProfiling();
111 }
112 ~ProfilingSentry()
113 {
114 if (m_service)
115 m_service->stopProfiling();
116 }
117
118 public:
119
120 IProfilingService* service() { return m_service; }
121
122 private:
123
124 IProfilingService* m_service;
125};
126
127/*---------------------------------------------------------------------------*/
128/*---------------------------------------------------------------------------*/
129
130/*!
131 * \brief Class allowing automatic start and stop of a service.
132 *
133 * The service is initialized if necessary.
134 */
135class ARCANE_UTILS_EXPORT ProfilingSentryWithInitialize
136{
137 public:
138
139 /*!
140 * \brief Constructs an instance associated with the service \a s.
141 *
142 * If \a s is \a null, the instance does nothing.
143 */
145 : m_service(s)
146 {
147 if (m_service) {
148 if (!m_service->isInitialized())
149 m_service->initialize();
150 m_service->startProfiling();
151 }
152 }
153
155 {
156 if (m_service) {
157 m_service->stopProfiling();
158 if (m_print_at_end)
159 m_service->printInfos(false);
160 }
161 }
162
163 public:
164
165 IProfilingService* service() { return m_service; }
166 //! Indicates if results are printed at the end of profiling
167 void setPrintAtEnd(bool v) { m_print_at_end = v; }
168
169 private:
170
171 IProfilingService* m_service = nullptr;
172 bool m_print_at_end = false;
173};
174
175/*---------------------------------------------------------------------------*/
176/*---------------------------------------------------------------------------*/
177
178} // End namespace Arcane
179
180/*---------------------------------------------------------------------------*/
181/*---------------------------------------------------------------------------*/
182
183#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 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:125