MCPcopy Create free account
hub / github.com/prometheus/procfs / parseCgroupString

Function parseCgroupString

proc_cgroup.go:49–70  ·  view source on GitHub ↗

parseCgroupString parses each line of the /proc/[pid]/cgroup file Line format is hierarchyID:[controller1,controller2]:path.

(cgroupStr string)

Source from the content-addressed store, hash-verified

47// parseCgroupString parses each line of the /proc/[pid]/cgroup file
48// Line format is hierarchyID:[controller1,controller2]:path.
49func parseCgroupString(cgroupStr string) (*Cgroup, error) {
50 var err error
51
52 fields := strings.SplitN(cgroupStr, ":", 3)
53 if len(fields) < 3 {
54 return nil, fmt.Errorf("%w: 3+ fields required, found %d fields in cgroup string: %s", ErrFileParse, len(fields), cgroupStr)
55 }
56
57 cgroup := &Cgroup{
58 Path: fields[2],
59 Controllers: nil,
60 }
61 cgroup.HierarchyID, err = strconv.Atoi(fields[0])
62 if err != nil {
63 return nil, fmt.Errorf("%w: hierarchy ID: %q", ErrFileParse, fields[0])
64 }
65 if fields[1] != "" {
66 ssNames := strings.Split(fields[1], ",")
67 cgroup.Controllers = append(cgroup.Controllers, ssNames...)
68 }
69 return cgroup, nil
70}
71
72// parseCgroups reads each line of the /proc/[pid]/cgroup file.
73func parseCgroups(data []byte) ([]Cgroup, error) {

Callers 2

parseCgroupsFunction · 0.85
TestParseCgroupStringFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestParseCgroupStringFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…