If I have a cgroup like
user.slice and have
CPUAccounting=true set up, I'm wondering how one would calculate the CPU Usage of that particular cgroup over a period of time (such as 1s), using either
cpuacct.stat. I know
cpuacct.usage provides the CPU time (in nanoseconds), which could be used to calculate the CPU percentage by subtracting two snapshots of it during a period of time and dividing it by the total CPU time of the system over the same period of time (correct me if I'm wrong), but I'm unsure how to get the total CPU time over a period of time.
Is there a way I can get the total CPU time over a period of time or use a different formula/cgroup feature to calculate the CPU Usage? Thanks in advance :)
Note: I am aware of
systemd-cgtop, which provides some of this information, however I want to calculate the CPU Usage programatically without having to parse