mirror of
https://github.com/shirou/gopsutil.git
synced 2025-04-28 13:48:49 +08:00
Use Go's built in syscall.Getpagesize()
This commit is contained in:
parent
13e00c76e4
commit
a6cd6f803b
@ -10,27 +10,14 @@ import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"github.com/shirou/gopsutil/internal/common"
|
||||
)
|
||||
|
||||
func getPageSize() (uint64, error) {
|
||||
out, err := exec.Command("pagesize").Output()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
o := strings.TrimSpace(string(out))
|
||||
p, err := strconv.ParseUint(o, 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// VirtualMemory returns VirtualmemoryStat.
|
||||
func VirtualMemory() (*VirtualMemoryStat, error) {
|
||||
count := C.mach_msg_type_number_t(C.HOST_VM_INFO_COUNT)
|
||||
@ -55,7 +42,7 @@ func VirtualMemory() (*VirtualMemoryStat, error) {
|
||||
|
||||
usedCount := totalCount - vmstat.free_count
|
||||
|
||||
pageSize := uint64(C.getpagesize())
|
||||
pageSize := uint64(syscall.Getpagesize())
|
||||
return &VirtualMemoryStat{
|
||||
Total: pageSize * uint64(totalCount),
|
||||
Available: pageSize * uint64(availableCount),
|
||||
|
Loading…
x
Reference in New Issue
Block a user