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
106 bool global_has_color_console =
false;
115 return global_online_debugger_service;
125 global_online_debugger_service = service;
135 return global_profiling_service;
145 global_profiling_service = service;
155 return global_processor_affinity_service;
165 global_processor_affinity_service = service;
175 return global_performance_counter_service;
184 auto* old_service = global_performance_counter_service;
185 global_performance_counter_service = service;
219extern "C++" ARCANE_UTILS_EXPORT IMemoryRessourceMng*
platform::
240 return Arccore::Concurrency::getThreadImplementation();
249 return Arccore::Concurrency::setThreadImplementation(service);
259 struct itimerval time_val;
260 struct itimerval otime_val;
261 time_val.it_value.tv_sec = nb_second;
262 time_val.it_value.tv_usec = 0;
263 time_val.it_interval.tv_sec = 0;
264 time_val.it_interval.tv_usec = 0;
268 int r = setitimer(ITIMER_VIRTUAL,&time_val,&otime_val);
270 cout <<
"** ERROR in setitimer r=" << r <<
'\n';
297template<
typename ByteType>
bool
302 if (file_length == 0) {
307 ios::openmode mode = ios::in;
315 out_bytes.
resize(file_length);
316 ifile.read((
char*)(out_bytes.
data()), file_length);
325 size_t nb_read = ifile.gcount();
326 out_bytes.
resize(nb_read);
338 return _readAllFile(filename,is_binary,out_bytes);
347 return _readAllFile(filename,is_binary,out_bytes);
353static bool global_has_dotnet_runtime =
false;
357 return global_has_dotnet_runtime;
363 global_has_dotnet_runtime = v;
373#if defined(ARCANE_OS_LINUX)
374 char* buf = ::realpath(
"/proc/self/exe",
nullptr);
379#elif defined(ARCANE_OS_WIN32)
381 int r = GetModuleFileNameA(NULL,buf,2000);
385#elif defined(ARCANE_OS_MACOS)
387 uint32_t bufSize = 2000;
388 int r = _NSGetExecutablePath(buf, &bufSize);
393#error "platform::getExeFullPath() not implemented for this platform"
405#if defined(ARCANE_OS_LINUX)
407 const int BUFSIZE = 1024;
408 char buffer[BUFSIZE + 1];
414 const char* filename =
"/proc/self/cmdline";
415 int fd = open(filename, O_RDONLY);
420 while ((nb_read = read(fd, buffer, BUFSIZE)) > 0) {
421 buffer[BUFSIZE] =
'\0';
427 int size = bytes.
size();
428 const char* ptr = bytes.
data();
429 const char* end = ptr + size;
432 while (*ptr++ && ptr < end)
435#elif defined(ARCANE_OS_WIN32)
436 LPWSTR* w_arg_list =
nullptr;
439 w_arg_list = ::CommandLineToArgvW(GetCommandLineW(), &nb_arg);
441 ARCANE_FATAL(
"Can not get arguments from command line");
443 for (
int i = 0; i < nb_arg; i++) {
444 std::wstring_view wstr_view(w_arg_list[i]);
449 ::LocalFree(w_arg_list);
450#elif defined(ARCANE_OS_MACOS)
451 int argc = *_NSGetArgc();
452 char** argv = *_NSGetArgv();
453 for (
int i = 0; i < argc; i++) {
466 String _getDebuggerStack(
const char* command)
469 long pid = (long)getpid();
470 sprintf(filename,
"errlog.%ld", pid);
471 int ret_value = system(command);
472 if (ret_value != 0) {
485#if defined(ARCANE_OS_LINUX)
486 const size_t cmd_size = 4096;
487 char cmd[cmd_size + 1];
490 long pid = (long)getpid();
491 snprintf(cmd, cmd_size,
"gdb --ex 'set debuginfod enabled off' --ex 'attach %ld' --ex 'info threads' --ex 'thread apply all bt full' --batch", pid);
492 result = _getDebuggerStack(cmd);
504#if defined(ARCANE_OS_LINUX)
505 const size_t cmd_size = 4096;
506 char cmd[cmd_size + 1];
507 long pid = (long)getpid();
510 snprintf(cmd, cmd_size,
"lldb -p %ld -o 'bt' -o 'bt all' -o 'clrthreads' -o 'clrstack' -o 'dumpstack' --batch", pid);
511 result = _getDebuggerStack(cmd);
521void (*global_garbage_collector_delegate)() =
nullptr;
524extern "C" ARCANE_UTILS_EXPORT
void
525_ArcaneSetCallGarbageCollectorDelegate(
void(*f)())
527 global_garbage_collector_delegate = f;
533 if (global_garbage_collector_delegate)
534 (*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 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.