Arcane  4.2.3.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
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 d'un service de profiling. */
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 d'un service de profiling.
35 *
36 * Il faut appeler initialize() avant d'utiliser l'instance. On peut
37 * ensuite appeler startProfiling()/stopProfiling() pour démarrer et
38 * arrêter le profiling.
39 *
40 * Lorsque le profiling est arrêté, on peut appeler printInfos() pour
41 * afficher les informations de profiling. La méthode reset() permet de
42 * remettre à zéro les informations de profiling.
43 */
44class ARCANE_UTILS_EXPORT IProfilingService
45{
46 public:
47
48 virtual ~IProfilingService() = default;
49
50 public:
51
52 /*!
53 * \brief Initialise le service de profiling.
54 *
55 * Cette méthode ne peut être appelée qu'une seule fois.
56 */
57 virtual void initialize() = 0;
58
59 //! Indique si initialize() a déjà été appelé
60 virtual bool isInitialized() const { return false; }
61
62 //! Démarre un profiling
63 virtual void startProfiling() = 0;
64
65 virtual void switchEvent() = 0;
66
67 //! Stoppe le profiling
68 virtual void stopProfiling() = 0;
69
70 /*!
71 * \brief Indique si le profiling est en cours.
72 *
73 * Le profiling est en cours entre un appel à startProfiling()
74 * et stopProfiling().
75 */
76 virtual bool isRunning() const =0;
77
78 /*!
79 * \brief Affiche les infos de profiling.
80 *
81 * Le profiling doit être arrêté.
82 * Si \a dump_file est vrai, des sorties fichiers contenant les infos
83 * sont générées ce qui peut prendre du temps.
84 */
85 virtual void printInfos(bool dump_file = false) = 0;
86
87 virtual void getInfos(Int64Array&) = 0;
88
89 //! Ecrit les infos de profiling dans l'écrivain \a writer.
90 virtual void dumpJSON(JSONWriter& writer) = 0;
91
92 /*!
93 * \brief Remet à zéro les compteurs.
94 *
95 * Le profiling doit être arrêté pour cela.
96 */
97 virtual void reset() = 0;
98
99 //! Timer utilisant les fonctionnalités de ce service si elles existent. Peut être nul.
100 virtual ITimerMng* timerMng() = 0;
101};
102
103/*---------------------------------------------------------------------------*/
104/*---------------------------------------------------------------------------*/
105/*!
106 * \brief Classe permettant de démarrer et arrêter automatiquement un 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 * \brief Classe permettant de démarrer et arrêter automatiquement un service.
137 *
138 * Le service est initialisé si nécessaire.
139 */
140class ARCANE_UTILS_EXPORT ProfilingSentryWithInitialize
141{
142 public:
143
144 /*!
145 * \brief Construit une instance associée au service \a s.
146 *
147 * Si \a s est \a null, alors l'instance ne fait rien.
148 */
150 : m_service(s)
151 {
152 if (m_service) {
153 if (!m_service->isInitialized())
154 m_service->initialize();
155 m_service->startProfiling();
156 }
157 }
158
160 {
161 if (m_service) {
162 m_service->stopProfiling();
163 if (m_print_at_end)
164 m_service->printInfos(false);
165 }
166 }
167
168 public:
169
170 IProfilingService* service() { return m_service; }
171 //! Indique si on imprime les résultats à la fin du profiling
172 void setPrintAtEnd(bool v) { m_print_at_end = v; }
173
174 private:
175
176 IProfilingService* m_service = nullptr;
177 bool m_print_at_end = false;
178};
179
180/*---------------------------------------------------------------------------*/
181/*---------------------------------------------------------------------------*/
182
183} // End namespace Arcane
184
185/*---------------------------------------------------------------------------*/
186/*---------------------------------------------------------------------------*/
187
188#endif
Déclarations des types utilisés dans Arcane.
virtual bool isInitialized() const
Indique si initialize() a déjà été appelé
virtual ITimerMng * timerMng()=0
Timer utilisant les fonctionnalités de ce service si elles existent. Peut être nul.
virtual bool isRunning() const =0
Indique si le profiling est en cours.
virtual void stopProfiling()=0
Stoppe le profiling.
virtual void startProfiling()=0
Démarre un profiling.
virtual void initialize()=0
Initialise le service de profiling.
virtual void dumpJSON(JSONWriter &writer)=0
Ecrit les infos de profiling dans l'écrivain writer.
virtual void reset()=0
Remet à zéro les compteurs.
virtual void printInfos(bool dump_file=false)=0
Affiche les infos de profiling.
Interface d'un gestionnaire de timer.
Definition ITimerMng.h:49
Classe permettant de démarrer et arrêter automatiquement un service.
void setPrintAtEnd(bool v)
Indique si on imprime les résultats à la fin du profiling.
ProfilingSentryWithInitialize(IProfilingService *s)
Construit une instance associée au service s.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Array< Int64 > Int64Array
Tableau dynamique à une dimension d'entiers 64 bits.
Definition UtilsTypes.h:119