Refactor with gofmt

pull/659/head
mingrammer 6 years ago
parent 68c6fbd367
commit 64a995aad4

@ -14,8 +14,8 @@ import (
) )
type VirtualMemoryExStat struct { type VirtualMemoryExStat struct {
ActiveFile uint64 `json:"activefile"` ActiveFile uint64 `json:"activefile"`
InactiveFile uint64 `json:"inactivefile"` InactiveFile uint64 `json:"inactivefile"`
} }
func VirtualMemory() (*VirtualMemoryStat, error) { func VirtualMemory() (*VirtualMemoryStat, error) {
@ -28,9 +28,9 @@ func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) {
// flag if MemAvailable is in /proc/meminfo (kernel 3.14+) // flag if MemAvailable is in /proc/meminfo (kernel 3.14+)
memavail := false memavail := false
activeFile := false // "Active(file)" not available: 2.6.28 / Dec 2008 activeFile := false // "Active(file)" not available: 2.6.28 / Dec 2008
inactiveFile := false // "Inactive(file)" not available: 2.6.28 / Dec 2008 inactiveFile := false // "Inactive(file)" not available: 2.6.28 / Dec 2008
sReclaimable := false // "SReclaimable:" not available: 2.6.19 / Nov 2006 sReclaimable := false // "SReclaimable:" not available: 2.6.19 / Nov 2006
ret := &VirtualMemoryStat{} ret := &VirtualMemoryStat{}
retEx := &VirtualMemoryExStat{} retEx := &VirtualMemoryExStat{}
@ -123,7 +123,7 @@ func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) {
ret.Cached += ret.SReclaimable ret.Cached += ret.SReclaimable
if !memavail { if !memavail {
if (activeFile && inactiveFile && sReclaimable) { if activeFile && inactiveFile && sReclaimable {
ret.Available = calcuateAvailVmem(ret, retEx) ret.Available = calcuateAvailVmem(ret, retEx)
} else { } else {
ret.Available = ret.Cached + ret.Free ret.Available = ret.Cached + ret.Free
@ -192,7 +192,7 @@ func calcuateAvailVmem(ret *VirtualMemoryStat, retEx *VirtualMemoryExStat) uint6
lines, err := common.ReadLines(fn) lines, err := common.ReadLines(fn)
if err != nil { if err != nil {
return ret.Free + ret.Cached // fallback under kernel 2.6.13 return ret.Free + ret.Cached // fallback under kernel 2.6.13
} }
pagesize := uint64(os.Getpagesize()) pagesize := uint64(os.Getpagesize())

@ -109,9 +109,9 @@ func Test_Process_memory_maps(t *testing.T) {
if len(*mmaps) != 1 { if len(*mmaps) != 1 {
t.Errorf("grouped memory maps length (%v) is not equal to 1", len(*mmaps)) t.Errorf("grouped memory maps length (%v) is not equal to 1", len(*mmaps))
} }
if (*mmaps)[0] == empty { if (*mmaps)[0] == empty {
t.Errorf("memory map is empty") t.Errorf("memory map is empty")
} }
} }
func Test_Process_MemoryInfo(t *testing.T) { func Test_Process_MemoryInfo(t *testing.T) {
p := testGetProcess() p := testGetProcess()

Loading…
Cancel
Save