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#if !defined(ARCANE_OS_CYGWIN) && !defined(ARCANE_OS_WIN32)
58#define ARCANE_HAS_I386_FPU_CONTROL_H
59#include <fpu_control.h>
63#ifndef ARCANE_OS_WIN32
74#if defined(ARCANE_OS_LINUX) && defined(__USE_GNU)
76# define ARCANE_GLIBC_FENV
96 bool global_has_color_console =
false;
105 return global_symbolizer_service;
115 global_symbolizer_service = service;
125 return global_online_debugger_service;
135 global_online_debugger_service = service;
145 return global_profiling_service;
155 global_profiling_service = service;
165 return global_dynamic_library_loader;
175 global_dynamic_library_loader = idll;
185 return global_processor_affinity_service;
195 global_processor_affinity_service = service;
205 return global_performance_counter_service;
214 auto* old_service = global_performance_counter_service;
215 global_performance_counter_service = service;
234 return MemoryUtils::setAcceleratorHostMemoryAllocator(a);
249extern "C++" ARCANE_UTILS_EXPORT IMemoryRessourceMng*
platform::
252 return MemoryUtils::setDataMemoryResourceMng(mng);
261 return MemoryUtils::getDataMemoryResourceMng();
270 return Arccore::Concurrency::getThreadImplementation();
279 return Arccore::Concurrency::setThreadImplementation(service);
289 struct itimerval time_val;
290 struct itimerval otime_val;
291 time_val.it_value.tv_sec = nb_second;
292 time_val.it_value.tv_usec = 0;
293 time_val.it_interval.tv_sec = 0;
294 time_val.it_interval.tv_usec = 0;
298 int r = setitimer(ITIMER_VIRTUAL,&time_val,&otime_val);
300 cout <<
"** ERROR in setitimer r=" << r <<
'\n';
327template<
typename ByteType>
bool
332 if (file_length == 0) {
337 ios::openmode mode = ios::in;
345 out_bytes.
resize(file_length);
346 ifile.read((
char*)(out_bytes.
data()), file_length);
355 size_t nb_read = ifile.gcount();
356 out_bytes.
resize(nb_read);
368 return _readAllFile(filename,is_binary,out_bytes);
377 return _readAllFile(filename,is_binary,out_bytes);
383static bool global_has_dotnet_runtime =
false;
387 return global_has_dotnet_runtime;
393 global_has_dotnet_runtime = v;
403#if defined(ARCANE_OS_LINUX)
404 char* buf = ::realpath(
"/proc/self/exe",
nullptr);
409#elif defined(ARCANE_OS_WIN32)
411 int r = GetModuleFileNameA(NULL,buf,2000);
416#error "platform::getExeFullPath() not implemented for this platform"
430#if defined(ARCANE_OS_LINUX)
432 std::ifstream ifile(
"/proc/self/maps");
434 String true_name =
"lib" + dll_name +
".so";
435 while (ifile.good()){
438 if (vb.
size()>0 && vb[0]==
'/'){
439 if (v.endsWith(true_name)){
447#elif defined(ARCANE_OS_WIN32)
448 HMODULE hModule = GetModuleHandleA(dll_name.
localstr());
451 TCHAR dllPath[_MAX_PATH];
452 GetModuleFileName(hModule, dllPath, _MAX_PATH);
468#if defined(ARCANE_OS_LINUX)
470 const int BUFSIZE = 1024;
471 char buffer[BUFSIZE + 1];
477 const char* filename =
"/proc/self/cmdline";
478 int fd = open(filename, O_RDONLY);
483 while ((nb_read = read(fd, buffer, BUFSIZE)) > 0) {
484 buffer[BUFSIZE] =
'\0';
490 int size = bytes.
size();
491 const char* ptr = bytes.
data();
492 const char* end = ptr + size;
495 while (*ptr++ && ptr < end)
508 auto x = std::chrono::high_resolution_clock::now();
510 auto y = std::chrono::time_point_cast<std::chrono::nanoseconds>(x);
512 return static_cast<Int64>(y.time_since_epoch().count());
521#if defined(ARCCORE_OS_WIN32)
524 return si.dwPageSize;
525#elif defined(ARCANE_OS_LINUX)
526 return ::sysconf(_SC_PAGESIZE);
528#warning "getPageSize() not implemented for your platform. Default is 4096"
529 Int64 page_size = 4096;
539 String _getDebuggerStack(
const char* command)
542 long pid = (long)getpid();
543 sprintf(filename,
"errlog.%ld", pid);
544 int ret_value = system(command);
545 if (ret_value != 0) {
558#if defined(ARCANE_OS_LINUX)
559 const size_t cmd_size = 4096;
560 char cmd[cmd_size + 1];
563 long pid = (long)getpid();
564 snprintf(cmd, cmd_size,
"gdb --ex 'set debuginfod enabled off' --ex 'attach %ld' --ex 'info threads' --ex 'thread apply all bt full' --batch", pid);
565 result = _getDebuggerStack(cmd);
577#if defined(ARCANE_OS_LINUX)
578 const size_t cmd_size = 4096;
579 char cmd[cmd_size + 1];
580 long pid = (long)getpid();
583 snprintf(cmd, cmd_size,
"lldb -p %ld -o 'bt' -o 'bt all' -o 'clrthreads' -o 'clrstack' -o 'dumpstack' --batch", pid);
584 result = _getDebuggerStack(cmd);
594void (*global_garbage_collector_delegate)() =
nullptr;
597extern "C" ARCANE_UTILS_EXPORT
void
598_ArcaneSetCallGarbageCollectorDelegate(
void(*f)())
600 global_garbage_collector_delegate = f;
606 if (global_garbage_collector_delegate)
607 (*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.
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.