Arcane  4.2.3.0
Developer 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/*---------------------------------------------------------------------------*/
44class ARCANE_UTILS_EXPORT IProfilingService
45{
46 public:
47
48 virtual ~IProfilingService() = default;
49
50 public:
51
57 virtual void initialize() = 0;
58
60 virtual bool isInitialized() const { return false; }
61
63 virtual void startProfiling() = 0;
64
65 virtual void switchEvent() = 0;
66
68 virtual void stopProfiling() = 0;
69
76 virtual bool isRunning() const =0;
77
85 virtual void printInfos(bool dump_file = false) = 0;
86
87 virtual void getInfos(Int64Array&) = 0;
88
90 virtual void dumpJSON(JSONWriter& writer) = 0;
91
97 virtual void reset() = 0;
98
100 virtual ITimerMng* timerMng() = 0;
101};
102
103/*---------------------------------------------------------------------------*/
104/*---------------------------------------------------------------------------*/
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
141class ARCANE_UTILS_EXPORT ProfilingSentryWithInitialize
142{
143 public:
144
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; }
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.
Interface of a profiling service.
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