Browse Source

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

pull/2/head
Chris Lu 11 years ago
parent
commit
25a3c47def
  1. 15
      go/stats/disk.go
  2. 9
      go/stats/disk_notsupported.go
  3. 19
      go/stats/disk_supported.go
  4. 18
      go/stats/disk_windows.go
  5. 12
      go/stats/memory.go
  6. 9
      go/stats/memory_notsupported.go
  7. 18
      go/stats/memory_supported.go
  8. 29
      go/stats/memory_windows.go

15
go/stats/disk.go

@ -1,10 +1,6 @@
// +build !windows
package stats
import (
"syscall"
)
import ()
type DiskStatus struct {
Dir string
@ -15,13 +11,6 @@ type DiskStatus struct {
func NewDiskStatus(path string) (disk *DiskStatus) {
disk = &DiskStatus{Dir: path}
fs := syscall.Statfs_t{}
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
disk.fillInStatus()
return
}

9
go/stats/disk_notsupported.go

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

19
go/stats/disk_supported.go

@ -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
}

18
go/stats/disk_windows.go

@ -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
}

12
go/stats/memory.go

@ -1,10 +1,7 @@
// +build !windows
package stats
import (
"runtime"
"syscall"
)
type MemStatus struct {
@ -26,13 +23,6 @@ func MemStat() MemStatus {
mem.Heap = memStat.HeapAlloc
mem.Stack = memStat.StackInuse
//system memory usage
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
}
mem.fillInStatus()
return mem
}

9
go/stats/memory_notsupported.go

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

18
go/stats/memory_supported.go

@ -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
}
}

29
go/stats/memory_windows.go

@ -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
}
Loading…
Cancel
Save