parseCgroupSummary parses each line of the /proc/cgroup file Line format is `subsys_name hierarchy num_cgroups enabled`.
(cgroupSummaryStr string)
| 41 | // parseCgroupSummary parses each line of the /proc/cgroup file |
| 42 | // Line format is `subsys_name hierarchy num_cgroups enabled`. |
| 43 | func parseCgroupSummaryString(cgroupSummaryStr string) (*CgroupSummary, error) { |
| 44 | var err error |
| 45 | |
| 46 | fields := strings.Fields(cgroupSummaryStr) |
| 47 | // require at least 4 fields |
| 48 | if len(fields) < 4 { |
| 49 | return nil, fmt.Errorf("%w: 4+ fields required, found %d fields in cgroup info string: %s", ErrFileParse, len(fields), cgroupSummaryStr) |
| 50 | } |
| 51 | |
| 52 | CgroupSummary := &CgroupSummary{ |
| 53 | SubsysName: fields[0], |
| 54 | } |
| 55 | CgroupSummary.Hierarchy, err = strconv.Atoi(fields[1]) |
| 56 | if err != nil { |
| 57 | return nil, fmt.Errorf("%w: Unable to parse hierarchy ID from %q", ErrFileParse, fields[1]) |
| 58 | } |
| 59 | CgroupSummary.Cgroups, err = strconv.Atoi(fields[2]) |
| 60 | if err != nil { |
| 61 | return nil, fmt.Errorf("%w: Unable to parse Cgroup Num from %q", ErrFileParse, fields[2]) |
| 62 | } |
| 63 | CgroupSummary.Enabled, err = strconv.Atoi(fields[3]) |
| 64 | if err != nil { |
| 65 | return nil, fmt.Errorf("%w: Unable to parse Enabled from %q", ErrFileParse, fields[3]) |
| 66 | } |
| 67 | return CgroupSummary, nil |
| 68 | } |
| 69 | |
| 70 | // parseCgroupSummary reads each line of the /proc/cgroup file. |
| 71 | func parseCgroupSummary(data []byte) ([]CgroupSummary, error) { |
no outgoing calls