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 "arccore/common/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
107 bool global_has_color_console =
false;
116 return global_symbolizer_service;
126 global_symbolizer_service = service;
136 return global_online_debugger_service;
146 global_online_debugger_service = service;
156 return global_profiling_service;
166 global_profiling_service = service;
176 return global_processor_affinity_service;
186 global_processor_affinity_service = service;
196 return global_performance_counter_service;
205 auto* old_service = global_performance_counter_service;
206 global_performance_counter_service = service;
240extern "C++" ARCANE_UTILS_EXPORT IMemoryRessourceMng*
platform::
261 return Arccore::Concurrency::getThreadImplementation();
270 return Arccore::Concurrency::setThreadImplementation(service);
280 struct itimerval time_val;
281 struct itimerval otime_val;
282 time_val.it_value.tv_sec = nb_second;
283 time_val.it_value.tv_usec = 0;
284 time_val.it_interval.tv_sec = 0;
285 time_val.it_interval.tv_usec = 0;
289 int r = setitimer(ITIMER_VIRTUAL,&time_val,&otime_val);
291 cout <<
"** ERROR in setitimer r=" << r <<
'\n';
318template<
typename ByteType>
bool
323 if (file_length == 0) {
328 ios::openmode mode = ios::in;
336 out_bytes.
resize(file_length);
337 ifile.read((
char*)(out_bytes.
data()), file_length);
346 size_t nb_read = ifile.gcount();
347 out_bytes.
resize(nb_read);
359 return _readAllFile(filename,is_binary,out_bytes);
368 return _readAllFile(filename,is_binary,out_bytes);
374static bool global_has_dotnet_runtime =
false;
378 return global_has_dotnet_runtime;
384 global_has_dotnet_runtime = v;
394#if defined(ARCANE_OS_LINUX)
395 char* buf = ::realpath(
"/proc/self/exe",
nullptr);
400#elif defined(ARCANE_OS_WIN32)
402 int r = GetModuleFileNameA(NULL,buf,2000);
406#elif defined(ARCANE_OS_MACOS)
408 uint32_t bufSize = 2000;
409 int r = _NSGetExecutablePath(buf, &bufSize);
414#error "platform::getExeFullPath() not implemented for this platform"
426#if defined(ARCANE_OS_LINUX)
428 const int BUFSIZE = 1024;
429 char buffer[BUFSIZE + 1];
435 const char* filename =
"/proc/self/cmdline";
436 int fd = open(filename, O_RDONLY);
441 while ((nb_read = read(fd, buffer, BUFSIZE)) > 0) {
442 buffer[BUFSIZE] =
'\0';
448 int size = bytes.
size();
449 const char* ptr = bytes.
data();
450 const char* end = ptr + size;
453 while (*ptr++ && ptr < end)
456#elif defined(ARCANE_OS_WIN32)
457 LPWSTR* w_arg_list =
nullptr;
460 w_arg_list = ::CommandLineToArgvW(GetCommandLineW(), &nb_arg);
462 ARCANE_FATAL(
"Can not get arguments from command line");
464 for (
int i = 0; i < nb_arg; i++) {
465 std::wstring_view wstr_view(w_arg_list[i]);
470 ::LocalFree(w_arg_list);
471#elif defined(ARCANE_OS_MACOS)
472 int argc = *_NSGetArgc();
473 char** argv = *_NSGetArgv();
474 for (
int i = 0; i < argc; i++) {
487 String _getDebuggerStack(
const char* command)
490 long pid = (long)getpid();
491 sprintf(filename,
"errlog.%ld", pid);
492 int ret_value = system(command);
493 if (ret_value != 0) {
506#if defined(ARCANE_OS_LINUX)
507 const size_t cmd_size = 4096;
508 char cmd[cmd_size + 1];
511 long pid = (long)getpid();
512 snprintf(cmd, cmd_size,
"gdb --ex 'set debuginfod enabled off' --ex 'attach %ld' --ex 'info threads' --ex 'thread apply all bt full' --batch", pid);
513 result = _getDebuggerStack(cmd);
525#if defined(ARCANE_OS_LINUX)
526 const size_t cmd_size = 4096;
527 char cmd[cmd_size + 1];
528 long pid = (long)getpid();
531 snprintf(cmd, cmd_size,
"lldb -p %ld -o 'bt' -o 'bt all' -o 'clrthreads' -o 'clrstack' -o 'dumpstack' --batch", pid);
532 result = _getDebuggerStack(cmd);
542void (*global_garbage_collector_delegate)() =
nullptr;
545extern "C" ARCANE_UTILS_EXPORT
void
546_ArcaneSetCallGarbageCollectorDelegate(
void(*f)())
548 global_garbage_collector_delegate = f;
554 if (global_garbage_collector_delegate)
555 (*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 utilitaires sur les chaînes de caractères.
ARCCORE_BASE_EXPORT String convertToArcaneString(const std::wstring_view &wstr)
Convertie wstr en une String.
Fonctions de gestion mémoire et des allocateurs.
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'un allocateur pour la mémoire.
Interface d'un service de debugger hybrid.
Interface d'un service de gestion de l'affinité des coeurs CPU.
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.
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.
Vecteur 1D de données avec sémantique par valeur (style STL).
ARCCORE_COMMON_EXPORT IMemoryRessourceMng * setDataMemoryResourceMng(IMemoryRessourceMng *mng)
Positionne le gestionnaire de ressource mémoire pour les données.
ARCCORE_COMMON_EXPORT IMemoryRessourceMng * getDataMemoryResourceMng()
Gestionnaire de ressource mémoire pour les données.
ARCCORE_COMMON_EXPORT IMemoryAllocator * setAcceleratorHostMemoryAllocator(IMemoryAllocator *a)
Positionne l'allocateur spécifique pour les accélérateurs.
ARCCORE_COMMON_EXPORT IMemoryAllocator * getDefaultDataAllocator()
Allocateur par défaut pour les données.
ARCCORE_COMMON_EXPORT IMemoryAllocator * getAcceleratorHostMemoryAllocator()
Allocateur spécifique pour les accélérateurs.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
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.