MCPcopy Index your code
hub / github.com/google/cadvisor / parseCapacity

Function parseCapacity

lib/machine/machine.go:269–281  ·  view source on GitHub ↗

parseCapacity matches a Regexp in a []byte, returning the resulting value in bytes. Assumes that the value matched by the Regexp is in KB.

(b []byte, r *regexp.Regexp)

Source from the content-addressed store, hash-verified

267// parseCapacity matches a Regexp in a []byte, returning the resulting value in bytes.
268// Assumes that the value matched by the Regexp is in KB.
269func parseCapacity(b []byte, r *regexp.Regexp) (uint64, error) {
270 matches := r.FindSubmatch(b)
271 if len(matches) != 2 {
272 return 0, fmt.Errorf("failed to match regexp in output: %q", string(b))
273 }
274 m, err := strconv.ParseUint(string(matches[1]), 10, 64)
275 if err != nil {
276 return 0, err
277 }
278
279 // Convert to bytes.
280 return m * 1024, err
281}
282
283// getUniqueMatchesCount returns number of unique matches in given argument using provided regular expression
284func getUniqueMatchesCount(s string, r *regexp.Regexp) int {

Callers 2

GetMachineMemoryCapacityFunction · 0.85
GetMachineSwapCapacityFunction · 0.85

Calls 1

ErrorfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…