Skip to content

Commit

Permalink
mem: infoprint basics
Browse files Browse the repository at this point in the history
  • Loading branch information
bioe007 committed Feb 26, 2024
1 parent 6824ced commit d22a8c2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package memory

import (
"encoding/csv"
"fmt"
"io"
"log"
"os"
Expand Down Expand Up @@ -134,8 +135,20 @@ const (
MEMDirectMap1G
)

func Getmeminfo() (*Meminfo, error) {
func (m *Meminfo) InfoPrint() {
// free/total cache buff
scale := 1024
s := fmt.Sprintf(
"MEM:%d/%d %d/%d",
m.MemFree/scale,
m.MemTotal/scale,
m.Buffers/scale,
m.Cached/scale,
)
fmt.Println(s)
}

func Getmeminfo() (*Meminfo, error) {
memfile, err := os.Open("/proc/meminfo")
// memfile, err := os.Open("./meminfo_test.txt")
if err != nil {
Expand Down Expand Up @@ -453,5 +466,4 @@ func Getmeminfo() (*Meminfo, error) {
}

return m, nil

}
2 changes: 1 addition & 1 deletion synopsys.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
fmt.Printf("MEMORY %+v\n", m)
m.InfoPrint()

ld, err := load.LoadAvg()
if err != nil {
Expand Down

0 comments on commit d22a8c2

Please sign in to comment.