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;
70 void reset()
override;
75 bool m_is_initialized =
false;
83 ProfProfilingService);
88ProfPerformanceService::
89ProfPerformanceService(
const ServiceBuildInfo& sbi)
97ProfPerformanceService::
98~ProfPerformanceService()
108 struct itimerval time_val;
109 struct itimerval otime_val;
110 time_val.it_value.tv_sec = 0;
111 time_val.it_value.tv_usec = usecond;
112 time_val.it_interval.tv_sec = 0;
113 time_val.it_interval.tv_usec = 0;
114 int r = setitimer(ITIMER_PROF, &time_val, &otime_val);
116 cout <<
"** ERROR in setitimer r=" << r <<
'\n';
127 bool global_is_active =
false;
129 int global_timer_period = 10000;
135 static bool is_in_handler =
false;
142 cout <<
"** WARNING: ProfHandler in pending exception\n";
146 cout <<
"** In handler\n";
149 is_in_handler =
true;
152 int overflow_event[MAX_COUNTER];
153 int nb_overflow_event = 1;
154 overflow_event[0] = 0;
156 unw_word_t func_ip = 0;
157 unw_word_t offset = 0;
162 unw_init_local(&cursor, &uc);
163 int current_func = 0;
169 while (unw_step(&cursor) > 0 && current_func < 3) {
172 unw_get_reg(&cursor, UNW_REG_IP, &func_ip);
174 char func_name_buf[10000];
175 unw_get_proc_name(&cursor,func_name_buf,10000,&offset);
176 cout <<
"** I=" << current_func <<
" FUNC NAME=" << func_name_buf
177 <<
" ip=" << (
void*)func_ip <<
'\n';
183 global_infos->addEvent((
void*)(func_ip + offset), overflow_event, nb_overflow_event);
185 is_in_handler =
false;
192_arcaneProfilingSigFunc(
int signum)
195 if (signum != SIGPROF)
197 if (global_is_active) {
198 arcane_prof_handler();
202 _setTimer(global_timer_period);
207_arcaneProfilingSigactionFunc(
int val, siginfo_t*,
void*)
209 _arcaneProfilingSigFunc(val);
218 if (m_is_initialized)
220 m_is_initialized =
true;
224 global_infos->setFunctionDepth(4);
225 global_infos->setNbEventBeforeGettingStack(100);
234 if (global_is_active)
236 global_is_active =
true;
237 global_infos->startProfiling();
240 sa.sa_flags = SA_SIGINFO | SA_NODEFER;
241 sigemptyset(&sa.sa_mask);
242 sa.sa_sigaction = _arcaneProfilingSigactionFunc;
243 sigaction(SIGPROF, &sa,
nullptr);
245 _setTimer(global_timer_period);
251void ProfPerformanceService::
265 global_is_active =
false;
266 _setTimer(global_timer_period);
269 sa.sa_flags = SA_SIGINFO | SA_NODEFER;
270 sigemptyset(&sa.sa_mask);
271 sa.sa_handler = SIG_IGN;
272 sigaction(SIGPROF, &sa,
nullptr);
275 global_infos->stopProfiling();
286 global_infos->printInfos(dump_file);
296 global_infos->dumpJSON(writer);
302void ProfPerformanceService::
315 global_infos->reset();
324 return global_is_active;
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
#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.