MCPcopy Create free account
hub / github.com/koding/kite / memoryStats

Function memoryStats

systeminfo/systeminfo_openbsd.go:25–78  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23}
24
25func memoryStats() (*memory, error) {
26 m := new(memory)
27
28 // get page size
29 pgsz_mib := []uint32{
30 6, // CTL_HW
31 7, // HW_PAGESIZE
32 }
33
34 pgsz := uintptr(0)
35
36 sz := uintptr(unsafe.Sizeof(pgsz))
37
38 _, _, err := syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(unsafe.Pointer(&pgsz_mib[0])), 2, uintptr(unsafe.Pointer(&pgsz)), uintptr(unsafe.Pointer(&sz)), 0, 0)
39 if err != 0 {
40 return nil, err
41 }
42
43 // get memory stats
44 vm_mib := []uint32{
45 2, // CTL_VM
46 1, // VM_METER
47 }
48
49 // from OpenBSD /usr/include/sys/vmmeter.h
50 var vmtotal struct {
51 t_rq uint16 /* length of the run queue */
52 t_dw uint16 /* jobs in ``disk wait'' (neg priority) */
53 t_pw uint16 /* jobs in page wait */
54 t_sl uint16 /* jobs sleeping in core */
55 t_sw uint16 /* swapped out runnable/short block jobs */
56 t_vm uint32 /* total virtual memory */
57 t_avm uint32 /* active virtual memory */
58 t_rm uint32 /* total real memory in use */
59 t_arm uint32 /* active real memory */
60 t_vmshr uint32 /* shared virtual memory */
61 t_avmshr uint32 /* active shared virtual memory */
62 t_rmshr uint32 /* shared real memory */
63 t_armshr uint32 /* active shared real memory */
64 t_free uint32 /* free memory pages */
65 }
66
67 sz = uintptr(unsafe.Sizeof(vmtotal))
68
69 _, _, err = syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(unsafe.Pointer(&vm_mib[0])), 2, uintptr(unsafe.Pointer(&vmtotal)), uintptr(unsafe.Pointer(&sz)), 0, 0)
70 if err != 0 {
71 return nil, err
72 }
73
74 m.Total = uint64(vmtotal.t_avm+vmtotal.t_free) * uint64(pgsz)
75 m.Usage = uint64(vmtotal.t_avm) * uint64(pgsz)
76
77 return m, nil
78}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected