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/core/FactoryService.h"
21#include "arcane/core/AbstractService.h"
23#include "arcane/utils/IProfilingService.h"
25#include "arcane/std/ProfilingInfo.h"
50class ProfPerformanceService
57 ~ProfPerformanceService()
override;
64 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';
126 bool global_is_active =
false;
128 int 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)
194 if (signum != SIGPROF)
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 global_is_active =
true;
234 global_infos->startProfiling();
237 sa.sa_flags = SA_SIGINFO | SA_NODEFER;
238 sigemptyset(&sa.sa_mask);
239 sa.sa_sigaction = _arcaneProfilingSigactionFunc;
240 sigaction(SIGPROF, &sa,
nullptr);
242 _setTimer(global_timer_period);
248void ProfPerformanceService::
261 global_is_active =
false;
262 _setTimer(global_timer_period);
265 sa.sa_flags = SA_SIGINFO | SA_NODEFER;
266 sigemptyset(&sa.sa_mask);
267 sa.sa_handler = SIG_IGN;
268 sigaction(SIGPROF, &sa,
nullptr);
271 global_infos->stopProfiling();
282 global_infos->printInfos(dump_file);
292 global_infos->dumpJSON(writer);
298void ProfPerformanceService::
311 global_infos->reset();
#define ARCANE_REGISTER_APPLICATION_FACTORY(aclass, ainterface, aname)
Registers a factory service for the class aclass.
AbstractService(const ServiceBuildInfo &)
Constructor from a ServiceBuildInfo.
static bool hasPendingException()
Indicates if there are pending exceptions.
Interface of a profiling service.
Interface of a timer manager.
Exception when a function is not implemented.
Structure containing the information to create a service.
Unicode character string.
ITraceMng * traceMng() const
Trace manager.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Array< Int64 > Int64Array
Dynamic one-dimensional array of 64-bit integers.
Int32 Integer
Type representing an integer.