14#include "arcane/utils/ValueConvert.h"
15#include "arcane/utils/NotImplementedException.h"
16#include "arcane/utils/PlatformUtils.h"
17#include "arcane/utils/FatalErrorException.h"
18#include "arcane/utils/TraceInfo.h"
20#include "arcane/FactoryService.h"
21#include "arcane/AbstractService.h"
23#include "arcane/utils/IProfilingService.h"
25#include "arcane/std/ProfilingInfo.h"
49class ProfPerformanceService
56 ~ProfPerformanceService()
override;
63 void switchEvent()
override;
69 void reset()
override;
74 bool m_is_initialized =
false;
82 ProfProfilingService);
87ProfPerformanceService::
88ProfPerformanceService(
const ServiceBuildInfo& sbi)
96ProfPerformanceService::
97~ProfPerformanceService()
107 struct itimerval time_val;
108 struct itimerval otime_val;
109 time_val.it_value.tv_sec = 0;
110 time_val.it_value.tv_usec = usecond;
111 time_val.it_interval.tv_sec = 0;
112 time_val.it_interval.tv_usec = 0;
113 int r = setitimer(ITIMER_PROF,&time_val,&otime_val);
115 cout <<
"** ERROR in setitimer r=" << r <<
'\n';
126bool global_is_active =
false;
128int global_timer_period = 10000;
134 static bool is_in_handler =
false;
141 cout <<
"** WARNING: ProfHandler in pending exception\n";
145 cout <<
"** In handler\n";
148 is_in_handler =
true;
151 int overflow_event[MAX_COUNTER];
152 int nb_overflow_event = 1;
153 overflow_event[0] = 0;
155 unw_word_t func_ip = 0;
156 unw_word_t offset = 0;
161 unw_init_local(&cursor, &uc);
162 int current_func = 0;
168 while (unw_step(&cursor) > 0 && current_func<3) {
171 unw_get_reg(&cursor, UNW_REG_IP, &func_ip);
173 char func_name_buf[10000];
174 unw_get_proc_name(&cursor,func_name_buf,10000,&offset);
175 cout <<
"** I=" << current_func <<
" FUNC NAME=" << func_name_buf
176 <<
" ip=" << (
void*)func_ip <<
'\n';
182 global_infos->addEvent((
void*)(func_ip+offset),overflow_event,nb_overflow_event);
184 is_in_handler =
false;
191_arcaneProfilingSigFunc(
int signum)
196 if (global_is_active){
197 arcane_prof_handler();
201 _setTimer(global_timer_period);
206_arcaneProfilingSigactionFunc(
int val, siginfo_t*,
void*)
208 _arcaneProfilingSigFunc(val);
217 if (m_is_initialized)
219 m_is_initialized =
true;
223 global_infos->setFunctionDepth(4);
224 global_infos->setNbEventBeforeGettingStack(100);
233 if (global_is_active)
235 global_is_active =
true;
236 global_infos->startProfiling();
239 sa.sa_flags = SA_SIGINFO | SA_NODEFER;
240 sigemptyset(&sa.sa_mask);
241 sa.sa_sigaction = _arcaneProfilingSigactionFunc;
242 sigaction(SIGPROF, &sa,
nullptr);
244 _setTimer(global_timer_period);
250void ProfPerformanceService::
264 global_is_active =
false;
265 _setTimer(global_timer_period);
268 sa.sa_flags = SA_SIGINFO | SA_NODEFER;
269 sigemptyset(&sa.sa_mask);
270 sa.sa_handler = SIG_IGN;
271 sigaction(SIGPROF, &sa,
nullptr);
274 global_infos->stopProfiling();
285 global_infos->printInfos(dump_file);
295 global_infos->dumpJSON(writer);
301void ProfPerformanceService::
315 global_infos->reset();
324 return global_is_active;
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
#define ARCANE_REGISTER_APPLICATION_FACTORY(aclass, ainterface, aname)
Enregistre un service de fabrique pour la classe aclass.
AbstractService(const ServiceBuildInfo &)
Constructeur à partir d'un ServiceBuildInfo.
static bool hasPendingException()
Indique si des exceptions sont en cours.
Interface d'un service de profiling.
Interface d'un gestionnaire de timer.
Exception lorsqu'une fonction n'est pas implémentée.
Structure contenant les informations pour créer un service.
Chaîne de caractères unicode.
ITraceMng * traceMng() const
Gestionnaire de trace.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Array< Int64 > Int64Array
Tableau dynamique à une dimension d'entiers 64 bits.
Int32 Integer
Type représentant un entier.