14#include "arcane/utils/PlatformUtils.h"
15#include "arcane/utils/String.h"
16#include "arcane/utils/StdHeader.h"
17#include "arcane/utils/StackTrace.h"
18#include "arcane/utils/IStackTraceService.h"
19#include "arcane/utils/IOnlineDebuggerService.h"
20#include "arcane/utils/Iostream.h"
21#include "arcane/utils/StringBuilder.h"
22#include "arcane/utils/NotSupportedException.h"
23#include "arcane/utils/Array.h"
24#include "arcane/utils/StringList.h"
25#include "arcane/utils/internal/MemoryRessourceMng.h"
29#ifndef ARCANE_OS_WIN32
45#include <sys/resource.h>
55#if !defined(ARCANE_OS_CYGWIN) && !defined(ARCANE_OS_WIN32)
57#define ARCANE_HAS_I386_FPU_CONTROL_H
58#include <fpu_control.h>
62#ifndef ARCANE_OS_WIN32
73#if defined(ARCANE_OS_LINUX) && defined(__USE_GNU)
75# define ARCANE_GLIBC_FENV
95 MemoryRessourceMng global_default_data_memory_ressource_mng;
98 bool global_has_color_console =
false;
107 return global_symbolizer_service;
117 global_symbolizer_service = service;
127 return global_online_debugger_service;
137 global_online_debugger_service = service;
147 return global_profiling_service;
157 global_profiling_service = service;
167 return global_dynamic_library_loader;
177 global_dynamic_library_loader = idll;
187 return global_processor_affinity_service;
197 global_processor_affinity_service = service;
207 return global_performance_counter_service;
216 auto* old_service = global_performance_counter_service;
217 global_performance_counter_service = service;
227 return global_accelerator_host_memory_allocator;
237 global_accelerator_host_memory_allocator = a;
258 global_data_memory_ressource_mng = mng;
270 return &global_default_data_memory_ressource_mng;
280 return Arccore::Concurrency::getThreadImplementation();
289 return Arccore::Concurrency::setThreadImplementation(service);
299 struct itimerval time_val;
300 struct itimerval otime_val;
301 time_val.it_value.tv_sec = nb_second;
302 time_val.it_value.tv_usec = 0;
303 time_val.it_interval.tv_sec = 0;
304 time_val.it_interval.tv_usec = 0;
308 int r = setitimer(ITIMER_VIRTUAL,&time_val,&otime_val);
310 cout <<
"** ERROR in setitimer r=" << r <<
'\n';
337template<
typename ByteType>
bool
341 long unsigned int file_length = platform::getFileLength(filename);
342 if (file_length == 0) {
347 ios::openmode mode = ios::in;
355 out_bytes.
resize(file_length);
356 ifile.read((
char*)(out_bytes.
data()), file_length);
365 size_t nb_read = ifile.gcount();
366 out_bytes.
resize(nb_read);
378 return _readAllFile(filename,is_binary,out_bytes);
387 return _readAllFile(filename,is_binary,out_bytes);
393static bool global_has_dotnet_runtime =
false;
397 return global_has_dotnet_runtime;
403 global_has_dotnet_runtime = v;
413#if defined(ARCANE_OS_LINUX)
414 char* buf = ::realpath(
"/proc/self/exe",
nullptr);
419#elif defined(ARCANE_OS_WIN32)
421 int r = GetModuleFileNameA(NULL,buf,2000);
426#error "platform::getExeFullPath() not implemented for this platform"
440#if defined(ARCANE_OS_LINUX)
442 std::ifstream ifile(
"/proc/self/maps");
444 String true_name =
"lib" + dll_name +
".so";
445 while (ifile.good()){
448 if (vb.
size()>0 && vb[0]==
'/'){
449 if (v.endsWith(true_name)){
457#elif defined(ARCANE_OS_WIN32)
458 HMODULE hModule = GetModuleHandleA(dll_name.
localstr());
461 TCHAR dllPath[_MAX_PATH];
462 GetModuleFileName(hModule, dllPath, _MAX_PATH);
478#if defined(ARCANE_OS_LINUX)
480 const int BUFSIZE = 1024;
481 char buffer[BUFSIZE + 1];
487 const char* filename =
"/proc/self/cmdline";
488 int fd = open(filename, O_RDONLY);
493 while ((nb_read = read(fd, buffer, BUFSIZE)) > 0) {
494 buffer[BUFSIZE] =
'\0';
500 int size = bytes.
size();
501 const char* ptr = bytes.
data();
502 const char* end = ptr + size;
505 while (*ptr++ && ptr < end)
518 auto x = std::chrono::high_resolution_clock::now();
520 auto y = std::chrono::time_point_cast<std::chrono::nanoseconds>(x);
522 return static_cast<Int64
>(y.time_since_epoch().count());
531#if defined(ARCCORE_OS_WIN32)
534 return si.dwPageSize;
535#elif defined(ARCANE_OS_LINUX)
536 return ::sysconf(_SC_PAGESIZE);
538#warning "getPageSize() not implemented for your platform. Default is 4096"
539 Int64 page_size = 4096;
549 String _getDebuggerStack(
const char* command)
552 long pid = (long)getpid();
553 sprintf(filename,
"errlog.%ld", pid);
554 int ret_value = system(command);
555 if (ret_value != 0) {
568#if defined(ARCANE_OS_LINUX)
569 const size_t cmd_size = 4096;
570 char cmd[cmd_size + 1];
573 long pid = (long)getpid();
574 snprintf(cmd, cmd_size,
"gdb --ex 'set debuginfod enabled off' --ex 'attach %ld' --ex 'info threads' --ex 'thread apply all bt full' --batch", pid);
575 result = _getDebuggerStack(cmd);
587#if defined(ARCANE_OS_LINUX)
588 const size_t cmd_size = 4096;
589 char cmd[cmd_size + 1];
590 long pid = (long)getpid();
593 snprintf(cmd, cmd_size,
"lldb -p %ld -o 'bt' -o 'bt all' -o 'clrthreads' -o 'clrstack' -o 'dumpstack' --batch", pid);
594 result = _getDebuggerStack(cmd);
604void (*global_garbage_collector_delegate)() =
nullptr;
607extern "C" ARCANE_UTILS_EXPORT
void
608_ArcaneSetCallGarbageCollectorDelegate(
void(*f)())
610 global_garbage_collector_delegate = f;
616 if (global_garbage_collector_delegate)
617 (*global_garbage_collector_delegate)();
#define ARCANE_CHECK_POINTER(ptr)
Macro retournant le pointeur ptr s'il est non nul ou lancant une exception s'il est nul.
void clear()
Supprime tous les éléments de la collection.
Gestion des ressources mémoire pour les CPU et accélérateurs.
virtual IMemoryAllocator * getAllocator(eMemoryRessource r)=0
Allocateur mémoire pour la ressource r.
Interface d'un service de récupération des symboles du code source.
Integer size() const
Nombre d'éléments du vecteur.
Classe de base des vecteurs 1D de données.
const T * data() const
Accès à la racine du tableau hors toute protection.
void reserve(Int64 new_capacity)
Réserve le mémoire pour new_capacity éléments.
void resize(Int64 s)
Change le nombre d'éléments du tableau à s.
void addRange(ConstReferenceType val, Int64 n)
Ajoute n élément de valeur val à la fin du tableau.
Interface d'un allocateur pour la mémoire.
Interface d'un service implémentant le support des threads.
constexpr __host__ __device__ SizeType size() const noexcept
Retourne la taille du tableau.
Vue d'un tableau d'éléments de type T.
Vue sur une chaîne de caractères UTF-8.
std::string_view toStdStringView() const ARCCORE_NOEXCEPT
Retourne une vue de la STL de la vue actuelle.
Chaîne de caractères unicode.
const char * localstr() const
Retourne la conversion de l'instance dans l'encodage UTF-8.
bool null() const
Retourne true si la chaîne est nulle.
Vecteur 1D de données avec sémantique par valeur (style STL).
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
@ UnifiedMemory
Alloue en utilisant la mémoire unifiée.