omni::extras::getDockerCpuLimit

Defined in omni/extras/ContainerHelper.h

inline int omni::extras::getDockerCpuLimit() noexcept

Attempts to read the current effective CPU usage quota for processes in a container.

Remark

This reads and calculates the effective CPU usage quota for processes in a container. If a limit has been imposed, the result is the number of logical cores that can be used. Note that this does not actually guarantee that the processes will not be able to run on some cores, but rather that the CPU scheduler will only give a certain percentage of its time to processes in the container thereby effectively making their performance similar to running on a system with the returned number of cores.

Note

This will still return a valid result outside of a container if a CPU usage limit has been imposed on the system. By default, Linux systems allow unlimited CPU usage.

Returns

The effective number of logical cores that processes in the container will have access to if a limit has been imposed. If no limit has been imposed when running the container, -1 will be returned.