Skip to content

Commit

Permalink
fix(procmeminfo): new way of calculating value in mem and proc info
Browse files Browse the repository at this point in the history
  • Loading branch information
MateuszKepczynskiSauce committed Nov 28, 2024
1 parent d59d5d8 commit 9a3d2c6
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion procmeminfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package bt

import (
"bufio"
"fmt"
"io"
"log"
"os"
"strconv"
"strings"
)

Expand Down Expand Up @@ -78,8 +80,29 @@ func readFile(path string) {
values := strings.Split(string(l), ":")
if len(values) == 2 {
if attr, exists := mapper[values[0]]; exists {
Options.Attributes[attr] = strings.TrimSuffix(strings.TrimSpace(values[1]), " kB")
value, err := getValue(values[1])
if err != nil {
continue
}
Options.Attributes[attr] = value
}
}
}
}

func getValue(value string) (string, error) {
value = strings.TrimSpace(value)
if strings.HasSuffix(value, "kB") {
value = strings.TrimSuffix(value, " kB")

atoi, err := strconv.ParseInt(value, 10, 64)
if err != nil && Options.DebugBacktrace {
log.Printf("readFile err: %v", err)
return "", err
}
atoi *= 1024
return fmt.Sprintf("%d", atoi), err
}

return value, nil
}

0 comments on commit 9a3d2c6

Please sign in to comment.