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

Function parseProcMap

proc_maps.go:139–185  ·  view source on GitHub ↗

parseProcMap will attempt to parse a single line within a proc/[pid]/maps buffer.

(text string)

Source from the content-addressed store, hash-verified

137// parseProcMap will attempt to parse a single line within a proc/[pid]/maps
138// buffer.
139func parseProcMap(text string) (*ProcMap, error) {
140 fields := strings.Fields(text)
141 if len(fields) < 5 {
142 return nil, fmt.Errorf("%w: truncated procmap entry", ErrFileParse)
143 }
144
145 saddr, eaddr, err := parseAddresses(fields[0])
146 if err != nil {
147 return nil, err
148 }
149
150 perms, err := parsePermissions(fields[1])
151 if err != nil {
152 return nil, err
153 }
154
155 offset, err := strconv.ParseInt(fields[2], 16, 0)
156 if err != nil {
157 return nil, err
158 }
159
160 device, err := parseDevice(fields[3])
161 if err != nil {
162 return nil, err
163 }
164
165 inode, err := strconv.ParseUint(fields[4], 10, 0)
166 if err != nil {
167 return nil, err
168 }
169
170 pathname := ""
171
172 if len(fields) >= 5 {
173 pathname = strings.Join(fields[5:], " ")
174 }
175
176 return &ProcMap{
177 StartAddr: saddr,
178 EndAddr: eaddr,
179 Perms: perms,
180 Offset: offset,
181 Dev: device,
182 Inode: inode,
183 Pathname: pathname,
184 }, nil
185}
186
187// ProcMaps reads from /proc/[pid]/maps to get the memory-mappings of the
188// process.

Callers 1

ProcMapsMethod · 0.85

Calls 3

parseAddressesFunction · 0.85
parsePermissionsFunction · 0.85
parseDeviceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…