-// Find the cgroup stats file in /sys/fs corresponding to the target
-// cgroup.
-//
-// TODO: Instead of trying all options, choose a process in the
-// container, and read /proc/PID/cgroup to determine the appropriate
-// cgroup root for the given statgroup. (This will avoid falling back
-// to host-level stats during container setup and teardown.)
-func FindStat(stderr chan<- string, cgroup Cgroup, statgroup string, stat string) string {
- if reportedStatFile == nil {
- reportedStatFile = make(map[string]bool)
- reportedNoStatFile = make(map[string]bool)
- }
-
- var path string
- path = fmt.Sprintf("%s/%s/%s/%s/%s", cgroup.root, statgroup, cgroup.parent, cgroup.cid, stat)
- if _, err := os.Stat(path); err != nil {
- path = fmt.Sprintf("%s/%s/%s/%s", cgroup.root, cgroup.parent, cgroup.cid, stat)
- }
- if _, err := os.Stat(path); err != nil {
- path = fmt.Sprintf("%s/%s/%s", cgroup.root, statgroup, stat)
- }
- if _, err := os.Stat(path); err != nil {
- path = fmt.Sprintf("%s/%s", cgroup.root, stat)
- }
- if _, err := os.Stat(path); err != nil {
- if _, ok := reportedNoStatFile[stat]; !ok {
- stderr <- fmt.Sprintf("crunchstat: did not find stats file (root %s, parent %s, cid %s, statgroup %s, stat %s)", cgroup.root, cgroup.parent, cgroup.cid, statgroup, stat)
- reportedNoStatFile[stat] = true
- }
- return ""
- }
- if _, ok := reportedStatFile[path]; !ok {
- stderr <- fmt.Sprintf("crunchstat: reading stats from %s", path)
- reportedStatFile[path] = true
- }
- return path
-}