MCPcopy Create free account
hub / github.com/catboost/catboost / CgroupV2Cpus

Function CgroupV2Cpus

util/system/info.cpp:86–100  ·  view source on GitHub ↗

In cgroups v2 there isn't a dedicated "cpu" directory under /sys/fs/cgroup, so the approximation of the number of CPUs may use the cpu.max file. The format is the following: $MAX $PERIOD Which indicates that the group may consume up to $MAX in each $PERIOD duration. The "max" value could be either the string "max" or a number. In the first case our approximation doesn't work so we can bail out e

Source from the content-addressed store, hash-verified

84our approximation doesn't work so we can bail out earlier.
85*/
86static inline double CgroupV2Cpus(const TString& cpuMaxPath) {
87 try {
88 TVector<TString> cgroupCpuMax = StringSplitter(TFileInput(cpuMaxPath).ReadAll()).Split(' ').Take(2);
89 double max = FromString<int32_t>(StripString(cgroupCpuMax[0]));
90 double period = FromString<int32_t>(StripString(cgroupCpuMax[1]));
91
92 if (max <= 0 || period <= 0) {
93 return 0;
94 }
95
96 return max / period;
97 } catch (...) {
98 return 0;
99 }
100}
101
102static inline double CgroupCpus() {
103 static const TString cpuMaxPath("/sys/fs/cgroup/cpu.max");

Callers 1

CgroupCpusFunction · 0.85

Calls 6

StringSplitterFunction · 0.85
StripStringFunction · 0.85
ReadAllMethod · 0.80
TFileInputClass · 0.50
TakeMethod · 0.45
SplitMethod · 0.45

Tested by

no test coverage detected