Issue 65: weed-fs 0.51 does not compile under windows

This commit is contained in:
Chris Lu 2014-03-28 12:18:01 -07:00
parent 59f6a13609
commit 25a3c47def
8 changed files with 58 additions and 71 deletions

View file

@ -1,10 +1,6 @@
// +build !windows
package stats package stats
import ( import ()
"syscall"
)
type DiskStatus struct { type DiskStatus struct {
Dir string Dir string
@ -15,13 +11,6 @@ type DiskStatus struct {
func NewDiskStatus(path string) (disk *DiskStatus) { func NewDiskStatus(path string) (disk *DiskStatus) {
disk = &DiskStatus{Dir: path} disk = &DiskStatus{Dir: path}
fs := syscall.Statfs_t{} disk.fillInStatus()
err := syscall.Statfs(path, &fs)
if err != nil {
return
}
disk.All = fs.Blocks * uint64(fs.Bsize)
disk.Free = fs.Bfree * uint64(fs.Bsize)
disk.Used = disk.All - disk.Free
return return
} }

View file

@ -0,0 +1,9 @@
// +build windows openbsd netbsd plan9
package stats
import ()
func (disk *DiskStatus) fillInStatus() {
return
}

View file

@ -0,0 +1,19 @@
// +build !windows,!openbsd,!netbsd,!plan9
package stats
import (
"syscall"
)
func (disk *DiskStatus) fillInStatus() {
fs := syscall.Statfs_t{}
err := syscall.Statfs(disk.Dir, &fs)
if err != nil {
return
}
disk.All = fs.Blocks * uint64(fs.Bsize)
disk.Free = fs.Bfree * uint64(fs.Bsize)
disk.Used = disk.All - disk.Free
return
}

View file

@ -1,18 +0,0 @@
// +build windows
package stats
import (
"syscall"
)
type DiskStatus struct {
Dir string
All uint64
Used uint64
Free uint64
}
func NewDiskStatus(path string) (disk *DiskStatus) {
return
}

View file

@ -1,10 +1,7 @@
// +build !windows
package stats package stats
import ( import (
"runtime" "runtime"
"syscall"
) )
type MemStatus struct { type MemStatus struct {
@ -26,13 +23,6 @@ func MemStat() MemStatus {
mem.Heap = memStat.HeapAlloc mem.Heap = memStat.HeapAlloc
mem.Stack = memStat.StackInuse mem.Stack = memStat.StackInuse
//system memory usage mem.fillInStatus()
sysInfo := new(syscall.Sysinfo_t)
err := syscall.Sysinfo(sysInfo)
if err == nil {
mem.All = sysInfo.Totalram //* uint64(syscall.Getpagesize())
mem.Free = sysInfo.Freeram //* uint64(syscall.Getpagesize())
mem.Used = mem.All - mem.Free
}
return mem return mem
} }

View file

@ -0,0 +1,9 @@
// +build !linux
package stats
import ()
func (mem *MemStatus) fillInStatus() {
return
}

View file

@ -0,0 +1,18 @@
// +build linux
package stats
import (
"syscall"
)
func (mem *MemStatus) fillInStatus() {
//system memory usage
sysInfo := new(syscall.Sysinfo_t)
err := syscall.Sysinfo(sysInfo)
if err == nil {
mem.All = uint64(sysInfo.Totalram) //* uint64(syscall.Getpagesize())
mem.Free = uint64(sysInfo.Freeram) //* uint64(syscall.Getpagesize())
mem.Used = mem.All - mem.Free
}
}

View file

@ -1,29 +0,0 @@
// +build windows
package stats
import (
"runtime"
)
type MemStatus struct {
Goroutines uint32
All uint32
Used uint32
Free uint32
Self uint64
Heap uint64
Stack uint64
}
func MemStat() MemStatus {
memStat := new(runtime.MemStats)
mem.Goroutines = runtime.NumGoroutine()
runtime.ReadMemStats(memStat)
mem := MemStatus{}
mem.Self = memStat.Alloc
mem.Heap = memStat.HeapAlloc
mem.Stack = memStat.StackInuse
return mem
}