libct/cgroups/fs.GetStats: drop PathExists check

Half of controllers' GetStats just return nil, and most of the others
ignore ENOENT on files, so it will be cheaper to not check that the
path exists in the main GetStats method, offloading that to the
controllers.

Drop PathExists check from GetStats, add it to those controllers'
GetStats where it was missing.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin 2020-07-03 12:35:31 -07:00
parent 11fb94965c
commit 2e22579946
4 changed files with 10 additions and 1 deletions

View File

@ -54,6 +54,9 @@ func (s *CpuacctGroup) Set(path string, cgroup *configs.Cgroup) error {
}
func (s *CpuacctGroup) GetStats(path string, stats *cgroups.Stats) error {
if !cgroups.PathExists(path) {
return nil
}
userModeUsage, kernelModeUsage, err := getCpuUsageBreakdown(path)
if err != nil {
return err

View File

@ -250,7 +250,7 @@ func (m *manager) GetStats() (*cgroups.Stats, error) {
stats := cgroups.NewStats()
for name, path := range m.paths {
sys, err := m.getSubsystems().Get(name)
if err == errSubsystemDoesNotExist || !cgroups.PathExists(path) {
if err == errSubsystemDoesNotExist {
continue
}
if err := sys.GetStats(path, stats); err != nil {

View File

@ -39,6 +39,9 @@ func (s *HugetlbGroup) Set(path string, cgroup *configs.Cgroup) error {
func (s *HugetlbGroup) GetStats(path string, stats *cgroups.Stats) error {
hugetlbStats := cgroups.HugetlbStats{}
if !cgroups.PathExists(path) {
return nil
}
for _, pageSize := range HugePageSizes {
usage := strings.Join([]string{"hugetlb", pageSize, "usage_in_bytes"}, ".")
value, err := fscommon.GetCgroupParamUint(path, usage)

View File

@ -45,6 +45,9 @@ func (s *PidsGroup) Set(path string, cgroup *configs.Cgroup) error {
}
func (s *PidsGroup) GetStats(path string, stats *cgroups.Stats) error {
if !cgroups.PathExists(path) {
return nil
}
current, err := fscommon.GetCgroupParamUint(path, "pids.current")
if err != nil {
return fmt.Errorf("failed to parse pids.current - %s", err)