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/NotImplementedException.h"
24#include "arcane/utils/FatalErrorException.h"
25#include "arcane/utils/Array.h"
26#include "arcane/utils/StringList.h"
28#include "arcane/utils/CheckedConvert.h"
29#include "arcane/utils/internal/MemoryUtilsInternal.h"
35#ifndef ARCANE_OS_WIN32
51#include <sys/resource.h>
61#include <mach-o/dyld.h>
62#include <crt_externs.h>
68#if !defined(ARCANE_OS_CYGWIN) && !defined(ARCANE_OS_WIN32)
70#define ARCANE_HAS_I386_FPU_CONTROL_H
71#include <fpu_control.h>
75#ifndef ARCANE_OS_WIN32
86#if defined(ARCANE_OS_LINUX) && defined(__USE_GNU)
88# define ARCANE_GLIBC_FENV
108 bool global_has_color_console =
false;
117 return global_symbolizer_service;
127 global_symbolizer_service = service;
137 return global_online_debugger_service;
147 global_online_debugger_service = service;
157 return global_profiling_service;
167 global_profiling_service = service;
177 return global_dynamic_library_loader;
187 global_dynamic_library_loader = idll;
197 return global_processor_affinity_service;
207 global_processor_affinity_service = service;
217 return global_performance_counter_service;
226 auto* old_service = global_performance_counter_service;
227 global_performance_counter_service = service;
261extern "C++" ARCANE_UTILS_EXPORT IMemoryRessourceMng*
platform::
282 return Arccore::Concurrency::getThreadImplementation();
291 return Arccore::Concurrency::setThreadImplementation(service);
301 struct itimerval time_val;
302 struct itimerval otime_val;
303 time_val.it_value.tv_sec = nb_second;
304 time_val.it_value.tv_usec = 0;
305 time_val.it_interval.tv_sec = 0;
306 time_val.it_interval.tv_usec = 0;
310 int r = setitimer(ITIMER_VIRTUAL,&time_val,&otime_val);
312 cout <<
"** ERROR in setitimer r=" << r <<
'\n';
339template<
typename ByteType>
bool
344 if (file_length == 0) {
349 ios::openmode mode = ios::in;
357 out_bytes.
resize(file_length);
358 ifile.read((
char*)(out_bytes.
data()), file_length);
367 size_t nb_read = ifile.gcount();
368 out_bytes.
resize(nb_read);
380 return _readAllFile(filename,is_binary,out_bytes);
389 return _readAllFile(filename,is_binary,out_bytes);
395static bool global_has_dotnet_runtime =
false;
399 return global_has_dotnet_runtime;
405 global_has_dotnet_runtime = v;
415#if defined(ARCANE_OS_LINUX)
416 char* buf = ::realpath(
"/proc/self/exe",
nullptr);
421#elif defined(ARCANE_OS_WIN32)
423 int r = GetModuleFileNameA(NULL,buf,2000);
427#elif defined(ARCANE_OS_MACOS)
429 uint32_t bufSize = 2000;
430 int r = _NSGetExecutablePath(buf, &bufSize);
435#error "platform::getExeFullPath() not implemented for this platform"
449#if defined(ARCANE_OS_LINUX)
451 std::ifstream ifile(
"/proc/self/maps");
453 String true_name =
"lib" + dll_name +
".so";
454 while (ifile.good()){
457 if (vb.
size()>0 && vb[0]==
'/'){
458 if (v.endsWith(true_name)){
466#elif defined(ARCANE_OS_WIN32)
467 HMODULE hModule = GetModuleHandleA(dll_name.
localstr());
470 TCHAR dllPath[_MAX_PATH];
471 GetModuleFileName(hModule, dllPath, _MAX_PATH);
473#elif defined(ARCANE_OS_MACOS)
475 String true_name =
"lib" + dll_name +
".dylib";
476 uint32_t count = _dyld_image_count();
477 for (uint32_t i = 0; i < count; i++) {
478 const char* image_name = _dyld_get_image_name(i);
480 String image_path(image_name);
481 if (image_path.
endsWith(true_name)) {
482 full_path = image_path;
502#if defined(ARCANE_OS_LINUX)
504 const int BUFSIZE = 1024;
505 char buffer[BUFSIZE + 1];
511 const char* filename =
"/proc/self/cmdline";
512 int fd = open(filename, O_RDONLY);
517 while ((nb_read = read(fd, buffer, BUFSIZE)) > 0) {
518 buffer[BUFSIZE] =
'\0';
524 int size = bytes.
size();
525 const char* ptr = bytes.
data();
526 const char* end = ptr + size;
529 while (*ptr++ && ptr < end)
532#elif defined(ARCANE_OS_WIN32)
533 LPWSTR* w_arg_list =
nullptr;
536 w_arg_list = ::CommandLineToArgvW(GetCommandLineW(), &nb_arg);
538 ARCANE_FATAL(
"Can not get arguments from command line");
540 for (
int i = 0; i < nb_arg; i++) {
541 std::wstring_view wstr_view(w_arg_list[i]);
546 ::LocalFree(w_arg_list);
547#elif defined(ARCANE_OS_MACOS)
548 int argc = *_NSGetArgc();
549 char** argv = *_NSGetArgv();
550 for (
int i = 0; i < argc; i++) {
565 auto x = std::chrono::high_resolution_clock::now();
567 auto y = std::chrono::time_point_cast<std::chrono::nanoseconds>(x);
569 return static_cast<Int64>(y.time_since_epoch().count());
578#if defined(ARCCORE_OS_WIN32)
581 return si.dwPageSize;
582#elif defined(ARCANE_OS_LINUX)
583 return ::sysconf(_SC_PAGESIZE);
585#warning "getPageSize() not implemented for your platform. Default is 4096"
586 Int64 page_size = 4096;
596 String _getDebuggerStack(
const char* command)
599 long pid = (long)getpid();
600 sprintf(filename,
"errlog.%ld", pid);
601 int ret_value = system(command);
602 if (ret_value != 0) {
615#if defined(ARCANE_OS_LINUX)
616 const size_t cmd_size = 4096;
617 char cmd[cmd_size + 1];
620 long pid = (long)getpid();
621 snprintf(cmd, cmd_size,
"gdb --ex 'set debuginfod enabled off' --ex 'attach %ld' --ex 'info threads' --ex 'thread apply all bt full' --batch", pid);
622 result = _getDebuggerStack(cmd);
634#if defined(ARCANE_OS_LINUX)
635 const size_t cmd_size = 4096;
636 char cmd[cmd_size + 1];
637 long pid = (long)getpid();
640 snprintf(cmd, cmd_size,
"lldb -p %ld -o 'bt' -o 'bt all' -o 'clrthreads' -o 'clrstack' -o 'dumpstack' --batch", pid);
641 result = _getDebuggerStack(cmd);
651void (*global_garbage_collector_delegate)() =
nullptr;
654extern "C" ARCANE_UTILS_EXPORT
void
655_ArcaneSetCallGarbageCollectorDelegate(
void(*f)())
657 global_garbage_collector_delegate = f;
663 if (global_garbage_collector_delegate)
664 (*global_garbage_collector_delegate)();
#define ARCANE_THROW(exception_class,...)
Macro pour envoyer une exception avec formattage.
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Fonctions de gestion mémoire et des allocateurs.
Fonctions utilitaires sur les chaînes de caractères.
ARCCORE_BASE_EXPORT String convertToArcaneString(const std::wstring_view &wstr)
Convertie wstr en une String.
Integer size() const
Nombre d'éléments du vecteur.
Tableau d'items de types quelconques.
void resize(Int64 s)
Change le nombre d'éléments du tableau à s.
void reserve(Int64 new_capacity)
Réserve le mémoire pour new_capacity éléments.
const T * data() const
Accès à la racine du tableau hors toute protection.
void addRange(ConstReferenceType val, Int64 n)
Ajoute n élément de valeur val à la fin du tableau.
void clear()
Supprime tous les éléments de la collection.
Interface d'une chargeur dynamique de bibliothèque.
Interface d'un allocateur pour la mémoire.
Interface d'un service de debugger hybrid.
Interface d'un service de de trace des appels de fonctions.
Interface d'un service de profiling.
Interface d'un service de récupération des symboles du code source.
Interface d'un service implémentant le support des threads.
Exception lorsqu'une fonction n'est pas implémentée.
Exception lorsqu'une opération n'est pas supportée.
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).
IMemoryRessourceMng * setDataMemoryResourceMng(IMemoryRessourceMng *mng)
Positionne le gestionnaire de ressource mémoire pour les données.
IMemoryRessourceMng * getDataMemoryResourceMng()
Gestionnaire de ressource mémoire pour les données.
IMemoryAllocator * setAcceleratorHostMemoryAllocator(IMemoryAllocator *a)
Positionne l'allocateur spécifique pour les accélérateurs.
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.