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"
26#include "arcane/utils/internal/MemoryUtilsInternal.h"
30#ifndef ARCANE_OS_WIN32
46#include <sys/resource.h>
56#include <mach-o/dyld.h>
62#if !defined(ARCANE_OS_CYGWIN) && !defined(ARCANE_OS_WIN32)
64#define ARCANE_HAS_I386_FPU_CONTROL_H
65#include <fpu_control.h>
69#ifndef ARCANE_OS_WIN32
80#if defined(ARCANE_OS_LINUX) && defined(__USE_GNU)
82# define ARCANE_GLIBC_FENV
102 bool global_has_color_console =
false;
111 return global_symbolizer_service;
121 global_symbolizer_service = service;
131 return global_online_debugger_service;
141 global_online_debugger_service = service;
151 return global_profiling_service;
161 global_profiling_service = service;
171 return global_dynamic_library_loader;
181 global_dynamic_library_loader = idll;
191 return global_processor_affinity_service;
201 global_processor_affinity_service = service;
211 return global_performance_counter_service;
220 auto* old_service = global_performance_counter_service;
221 global_performance_counter_service = service;
240 return MemoryUtils::setAcceleratorHostMemoryAllocator(a);
255extern "C++" ARCANE_UTILS_EXPORT IMemoryRessourceMng*
platform::
258 return MemoryUtils::setDataMemoryResourceMng(mng);
255extern "C++" ARCANE_UTILS_EXPORT IMemoryRessourceMng*
platform:: {
…}
267 return MemoryUtils::getDataMemoryResourceMng();
276 return Arccore::Concurrency::getThreadImplementation();
285 return Arccore::Concurrency::setThreadImplementation(service);
295 struct itimerval time_val;
296 struct itimerval otime_val;
297 time_val.it_value.tv_sec = nb_second;
298 time_val.it_value.tv_usec = 0;
299 time_val.it_interval.tv_sec = 0;
300 time_val.it_interval.tv_usec = 0;
304 int r = setitimer(ITIMER_VIRTUAL,&time_val,&otime_val);
306 cout <<
"** ERROR in setitimer r=" << r <<
'\n';
333template<
typename ByteType>
bool
338 if (file_length == 0) {
343 ios::openmode mode = ios::in;
351 out_bytes.
resize(file_length);
352 ifile.read((
char*)(out_bytes.
data()), file_length);
361 size_t nb_read = ifile.gcount();
362 out_bytes.
resize(nb_read);
374 return _readAllFile(filename,is_binary,out_bytes);
383 return _readAllFile(filename,is_binary,out_bytes);
389static bool global_has_dotnet_runtime =
false;
393 return global_has_dotnet_runtime;
399 global_has_dotnet_runtime = v;
409#if defined(ARCANE_OS_LINUX)
410 char* buf = ::realpath(
"/proc/self/exe",
nullptr);
415#elif defined(ARCANE_OS_WIN32)
417 int r = GetModuleFileNameA(NULL,buf,2000);
421#elif defined(ARCANE_OS_MACOS)
423 uint32_t bufSize = 2000;
424 int r = _NSGetExecutablePath(buf, &bufSize);
429#error "platform::getExeFullPath() not implemented for this platform"
443#if defined(ARCANE_OS_LINUX)
445 std::ifstream ifile(
"/proc/self/maps");
447 String true_name =
"lib" + dll_name +
".so";
448 while (ifile.good()){
451 if (vb.
size()>0 && vb[0]==
'/'){
452 if (v.endsWith(true_name)){
460#elif defined(ARCANE_OS_WIN32)
461 HMODULE hModule = GetModuleHandleA(dll_name.
localstr());
464 TCHAR dllPath[_MAX_PATH];
465 GetModuleFileName(hModule, dllPath, _MAX_PATH);
467#elif defined(ARCANE_OS_MACOS)
469 String true_name =
"lib" + dll_name +
".dylib";
470 uint32_t count = _dyld_image_count();
471 for (uint32_t i = 0; i < count; i++) {
472 const char* image_name = _dyld_get_image_name(i);
474 String image_path(image_name);
475 if (image_path.
endsWith(true_name)) {
476 full_path = image_path;
496#if defined(ARCANE_OS_LINUX)
498 const int BUFSIZE = 1024;
499 char buffer[BUFSIZE + 1];
505 const char* filename =
"/proc/self/cmdline";
506 int fd = open(filename, O_RDONLY);
511 while ((nb_read = read(fd, buffer, BUFSIZE)) > 0) {
512 buffer[BUFSIZE] =
'\0';
518 int size = bytes.
size();
519 const char* ptr = bytes.
data();
520 const char* end = ptr + size;
523 while (*ptr++ && ptr < end)
536 auto x = std::chrono::high_resolution_clock::now();
538 auto y = std::chrono::time_point_cast<std::chrono::nanoseconds>(x);
540 return static_cast<Int64>(y.time_since_epoch().count());
549#if defined(ARCCORE_OS_WIN32)
552 return si.dwPageSize;
553#elif defined(ARCANE_OS_LINUX)
554 return ::sysconf(_SC_PAGESIZE);
556#warning "getPageSize() not implemented for your platform. Default is 4096"
557 Int64 page_size = 4096;
567 String _getDebuggerStack(
const char* command)
570 long pid = (long)getpid();
571 sprintf(filename,
"errlog.%ld", pid);
572 int ret_value = system(command);
573 if (ret_value != 0) {
586#if defined(ARCANE_OS_LINUX)
587 const size_t cmd_size = 4096;
588 char cmd[cmd_size + 1];
591 long pid = (long)getpid();
592 snprintf(cmd, cmd_size,
"gdb --ex 'set debuginfod enabled off' --ex 'attach %ld' --ex 'info threads' --ex 'thread apply all bt full' --batch", pid);
593 result = _getDebuggerStack(cmd);
605#if defined(ARCANE_OS_LINUX)
606 const size_t cmd_size = 4096;
607 char cmd[cmd_size + 1];
608 long pid = (long)getpid();
611 snprintf(cmd, cmd_size,
"lldb -p %ld -o 'bt' -o 'bt all' -o 'clrthreads' -o 'clrstack' -o 'dumpstack' --batch", pid);
612 result = _getDebuggerStack(cmd);
622void (*global_garbage_collector_delegate)() =
nullptr;
625extern "C" ARCANE_UTILS_EXPORT
void
626_ArcaneSetCallGarbageCollectorDelegate(
void(*f)())
628 global_garbage_collector_delegate = f;
634 if (global_garbage_collector_delegate)
635 (*global_garbage_collector_delegate)();
Fonctions de gestion mémoire et des allocateurs.
Integer size() const
Nombre d'éléments du vecteur.
Classe de base des vecteurs 1D de données.
void addRange(ConstReferenceType val, Int64 n)
Ajoute n élément de valeur val à la fin du tableau.
void resize(Int64 s)
Change le nombre d'éléments du tableau à s.
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 clear()
Supprime tous les éléments de la collection.
Interface d'un allocateur pour la mémoire.
Interface d'un service de récupération des symboles du code source.
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.
bool null() const
Retourne true si la chaîne est nulle.
const char * localstr() const
Retourne la conversion de l'instance dans l'encodage UTF-8.
bool endsWith(const String &s) const
Indique si la chaîne se termine par les caractères de s.
Vecteur 1D de données avec sémantique par valeur (style STL).
IMemoryAllocator * getDefaultDataAllocator()
Allocateur par défaut pour les données.
IMemoryAllocator * getAcceleratorHostMemoryAllocator()
Allocateur spécifique pour les accélérateurs.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
std::int64_t Int64
Type entier signé sur 64 bits.
Int32 Integer
Type représentant un entier.
Array< Byte > ByteArray
Tableau dynamique à une dimension de caractères.
List< String > StringList
Tableau de chaînes de caractères unicode.