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:
parent
11fb94965c
commit
2e22579946
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue