From 64a995aad46cf998a5701563940bfca3786a5d45 Mon Sep 17 00:00:00 2001 From: mingrammer Date: Sat, 23 Mar 2019 21:57:24 +0900 Subject: [PATCH] Refactor with gofmt --- mem/mem_linux.go | 14 +++++++------- process/process_test.go | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/mem/mem_linux.go b/mem/mem_linux.go index 0fe6209..f5df35b 100644 --- a/mem/mem_linux.go +++ b/mem/mem_linux.go @@ -14,8 +14,8 @@ import ( ) type VirtualMemoryExStat struct { - ActiveFile uint64 `json:"activefile"` - InactiveFile uint64 `json:"inactivefile"` + ActiveFile uint64 `json:"activefile"` + InactiveFile uint64 `json:"inactivefile"` } 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+) memavail := false - activeFile := false // "Active(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 + activeFile := false // "Active(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 ret := &VirtualMemoryStat{} retEx := &VirtualMemoryExStat{} @@ -123,7 +123,7 @@ func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) { ret.Cached += ret.SReclaimable if !memavail { - if (activeFile && inactiveFile && sReclaimable) { + if activeFile && inactiveFile && sReclaimable { ret.Available = calcuateAvailVmem(ret, retEx) } else { ret.Available = ret.Cached + ret.Free @@ -192,7 +192,7 @@ func calcuateAvailVmem(ret *VirtualMemoryStat, retEx *VirtualMemoryExStat) uint6 lines, err := common.ReadLines(fn) 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()) diff --git a/process/process_test.go b/process/process_test.go index 5dcc6be..226f956 100644 --- a/process/process_test.go +++ b/process/process_test.go @@ -109,9 +109,9 @@ func Test_Process_memory_maps(t *testing.T) { if len(*mmaps) != 1 { t.Errorf("grouped memory maps length (%v) is not equal to 1", len(*mmaps)) } - if (*mmaps)[0] == empty { - t.Errorf("memory map is empty") - } + if (*mmaps)[0] == empty { + t.Errorf("memory map is empty") + } } func Test_Process_MemoryInfo(t *testing.T) { p := testGetProcess()