6#include <bitcoin-build-config.h>
24#ifdef HAVE_MALLOPT_ARENA_MAX
41 std::string escaped = arg;
43 return "'" + escaped +
"'";
48void runCommand(
const std::string& strCommand)
50 if (strCommand.empty())
return;
51 int nErr = ::system(strCommand.c_str());
53 LogWarning(
"runCommand error: system(%s) returned %d", strCommand, nErr);
60#ifdef HAVE_MALLOPT_ARENA_MAX
66 if (
sizeof(
void*) == 4) {
67 mallopt(M_ARENA_MAX, 1);
72#if !defined(WIN32) && !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
75 }
catch (
const std::runtime_error&) {
76 setenv(
"LC_ALL",
"C.UTF-8", 1);
79 assert(GetACP() == CP_UTF8);
81 SetConsoleCP(CP_UTF8);
82 SetConsoleOutputCP(CP_UTF8);
86 constexpr mode_t private_umask = 0077;
96 int ret = WSAStartup(MAKEWORD(2,2), &wsadata);
97 if (
ret != NO_ERROR || LOBYTE(wsadata.wVersion ) != 2 || HIBYTE(wsadata.wVersion) != 2)
105 return std::thread::hardware_concurrency();
110 static const auto total_ram{[]() -> std::optional<uint64_t> {
112 if (MEMORYSTATUSEX
m{}; (
m.dwLength =
sizeof(
m), GlobalMemoryStatusEx(&
m)))
return m.ullTotalPhys;
113#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__illumos__) || defined(__linux__)
114 if (
long p{sysconf(_SC_PHYS_PAGES)},
s{sysconf(_SC_PAGESIZE)}; p > 0 &&
s > 0)
return 1ULL * p *
s;
122 const auto g_startup_time{SteadyClock::now()};
125SteadyClock::duration
GetUptime() {
return SteadyClock::now() - g_startup_time; }
SteadyClock::duration GetUptime()
Monotonic uptime (not affected by system time changes).
std::optional< uint64_t > TryGetTotalRam()
Return the total RAM available on the current system, if detectable.
int GetNumCores()
Return the number of cores available on the current system.
std::string ShellEscape(const std::string &arg)
void ReplaceAll(std::string &in_out, const std::string &search, const std::string &substitute)