Arcane  4.1.12.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-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
45class ARCANE_UTILS_EXPORT IProfilingService
46{
47 public:
48
49 virtual ~IProfilingService() = default;
50
51 public:
52
58 virtual void initialize() = 0;
59
61 virtual bool isInitialized() const { return false; }
62
64 virtual void startProfiling() = 0;
65
66 virtual void switchEvent() = 0;
67
69 virtual void stopProfiling() = 0;
70
78 virtual void printInfos(bool dump_file = false) = 0;
79
80 virtual void getInfos(Int64Array&) = 0;
81
83 virtual void dumpJSON(JSONWriter& writer) = 0;
84
90 virtual void reset() = 0;
91
93 virtual ITimerMng* timerMng() = 0;
94};
95
96/*---------------------------------------------------------------------------*/
97/*---------------------------------------------------------------------------*/
98
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
135class ARCANE_UTILS_EXPORT ProfilingSentryWithInitialize
136{
137 public:
138
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; }
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.
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 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