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

Function parseSwapString

swaps.go:61–89  ·  view source on GitHub ↗
(swapString string)

Source from the content-addressed store, hash-verified

59}
60
61func parseSwapString(swapString string) (*Swap, error) {
62 var err error
63
64 swapFields := strings.Fields(swapString)
65 swapLength := len(swapFields)
66 if swapLength < 5 {
67 return nil, fmt.Errorf("%w: too few fields in swap string: %s", ErrFileParse, swapString)
68 }
69
70 swap := &Swap{
71 Filename: swapFields[0],
72 Type: swapFields[1],
73 }
74
75 swap.Size, err = strconv.Atoi(swapFields[2])
76 if err != nil {
77 return nil, fmt.Errorf("%w: invalid swap size: %s: %w", ErrFileParse, swapFields[2], err)
78 }
79 swap.Used, err = strconv.Atoi(swapFields[3])
80 if err != nil {
81 return nil, fmt.Errorf("%w: invalid swap used: %s: %w", ErrFileParse, swapFields[3], err)
82 }
83 swap.Priority, err = strconv.Atoi(swapFields[4])
84 if err != nil {
85 return nil, fmt.Errorf("%w: invalid swap priority: %s: %w", ErrFileParse, swapFields[4], err)
86 }
87
88 return swap, nil
89}

Callers 2

parseSwapsFunction · 0.85
TestParseSwapStringFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestParseSwapStringFunction · 0.68