36#if !defined(__APPLE__)
38double ProcStatusBytes(
const std::string& key) {
39 std::ifstream status(
"/proc/self/status");
41 while (status >> word) {
71 mach_task_basic_info_data_t info;
72 mach_msg_type_number_t count = MACH_TASK_BASIC_INFO_COUNT;
73 if (task_info(mach_task_self(), MACH_TASK_BASIC_INFO,
74 reinterpret_cast<task_info_t
>(&info), &count) == KERN_SUCCESS) {
75 return double(info.resident_size);
79 return ProcStatusBytes(
"VmRSS:");
85 mach_task_basic_info_data_t info;
86 mach_msg_type_number_t count = MACH_TASK_BASIC_INFO_COUNT;
87 if (task_info(mach_task_self(), MACH_TASK_BASIC_INFO,
88 reinterpret_cast<task_info_t
>(&info), &count) == KERN_SUCCESS) {
89 return double(info.resident_size_max);
93 return ProcStatusBytes(
"VmHWM:");
102 std::ostringstream out;
104 out <<
"memory in use " << resident * 1
e-9 <<
" GB";
107 out <<
", peak " << peak * 1
e-9 <<
" GB";
118 const double margin = std::max(1e9, 0.05 * share);
123 std::ostringstream out;
127 <<
" GB for optional buffers";
136 if (resident >= 0.0) {
137 out <<
", " << resident * 1
e-9 <<
" GB in use";
static std::string Usage()
static double PeakResidentBytes()
Peak resident memory of the process so far (-1 if unknown).
static std::string Describe()
e.g. "budget 400 GB, 46.1 GB in use" or "no --memory given"
static void SetConcurrentJobs(Index concurrent_jobs)
static double DefaultAllowanceBytes()
static Index concurrent_jobs_
static void Set(double total_gb, Index concurrent_jobs=1)
total_gb <= 0: no budget given
static double ResidentBytes()
Resident memory of the process (-1 if unknown on this platform).
static double AvailableBytes()
static double total_bytes_
static double JobBudgetBytes()
The share of the budget of one job (0 without a budget).
Charge transport classes.
Provides a means for comparing floating point numbers.