mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-02 19:51:13 +00:00
Added a minimal system helper to query total physical RAM on [Linux/macOS/Windows](https://stackoverflow.com/a/2513561) (on other platforms we just return an empty optional). The added test checks if the value is roughly correct by checking if the CI platforms are returning any value and if the value is at least 1 GiB and not more than 10 TiB. The max value is only validated on 64 bits, since it's not unreasonable for 32 bits to have max memory, but on 64 bits it's likely an error. https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-memorystatusex > ullTotalPhys The amount of actual physical memory, in bytes. https://man7.org/linux/man-pages/man3/sysconf.3.html: > _SC_PHYS_PAGES The number of pages of physical memory. Note that it is possible for the product of this value and the value of _SC_PAGESIZE to overflow. > _SC_PAGESIZE Size of a page in bytes. Must not be less than 1. See https://godbolt.org/z/ec81Tjvrj for further details
39 lines
1.0 KiB
C++
39 lines
1.0 KiB
C++
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
|
// Copyright (c) 2009-present The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#ifndef BITCOIN_COMMON_SYSTEM_H
|
|
#define BITCOIN_COMMON_SYSTEM_H
|
|
|
|
#include <bitcoin-build-config.h> // IWYU pragma: keep
|
|
|
|
#include <cstdint>
|
|
#include <optional>
|
|
#include <string>
|
|
|
|
// Application startup time (used for uptime calculation)
|
|
int64_t GetStartupTime();
|
|
|
|
void SetupEnvironment();
|
|
[[nodiscard]] bool SetupNetworking();
|
|
#ifndef WIN32
|
|
std::string ShellEscape(const std::string& arg);
|
|
#endif
|
|
#if HAVE_SYSTEM
|
|
void runCommand(const std::string& strCommand);
|
|
#endif
|
|
|
|
/**
|
|
* Return the number of cores available on the current system.
|
|
* @note This does count virtual cores, such as those provided by HyperThreading.
|
|
*/
|
|
int GetNumCores();
|
|
|
|
/**
|
|
* Return the total RAM available on the current system, if detectable.
|
|
*/
|
|
std::optional<size_t> GetTotalRAM();
|
|
|
|
#endif // BITCOIN_COMMON_SYSTEM_H
|