Skip to content

Commit

Permalink
use strings.Cut
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcacheux committed Jun 26, 2023
1 parent 547c54e commit ca87d80
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions process/process_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,18 +380,19 @@ func (p *Process) ConnectionsMaxWithContext(ctx context.Context, max int) ([]net

// function of parsing a block
func readBlock(line string, m *MemoryMapsStat) error {
field := strings.Split(line, ":")
if len(field) < 2 {
name, value, found := strings.Cut(line, ":")
if !found {
return nil
}
v := strings.Trim(field[1], "kB") // remove last "kB"

v := strings.Trim(value, "kB") // remove last "kB"
v = strings.TrimSpace(v)
t, err := strconv.ParseUint(v, 10, 64)
if err != nil {
return err
}

switch field[0] {
switch name {
case "Size":
m.Size = t
case "Rss":
Expand Down

0 comments on commit ca87d80

Please sign in to comment.