mirror of
https://github.com/vlang/v.git
synced 2025-09-08 06:41:58 -04:00
runtime: add used_memory implementation for OpenBSD (#24918)
This commit is contained in:
parent
c3dfe62d7b
commit
54e8ed5ec5
@ -1,8 +1,8 @@
|
|||||||
module runtime
|
module runtime
|
||||||
|
|
||||||
// used_memory retrieves the current physical memory usage of the process.
|
// used_memory retrieves the current physical memory usage of the process.
|
||||||
// Note: implementation available only on FreeBSD, macOS, Linux and Windows. Otherwise,
|
// Note: implementation available only on FreeBSD, macOS, Linux, OpenBSD and
|
||||||
// returns 'used_memory: not implemented'.
|
// Windows. Otherwise, returns 'used_memory: not implemented'.
|
||||||
pub fn used_memory() !u64 {
|
pub fn used_memory() !u64 {
|
||||||
return error('used_memory: not implemented')
|
return error('used_memory: not implemented')
|
||||||
}
|
}
|
||||||
|
26
vlib/runtime/used_memory_openbsd.c.v
Normal file
26
vlib/runtime/used_memory_openbsd.c.v
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
module runtime
|
||||||
|
|
||||||
|
#include <sys/resource.h>
|
||||||
|
|
||||||
|
struct C.rusage {
|
||||||
|
ru_maxrss int
|
||||||
|
}
|
||||||
|
|
||||||
|
fn C.getrusage(who int, usage &C.rusage) int
|
||||||
|
|
||||||
|
// used_memory retrieves the current physical memory usage of the process.
|
||||||
|
pub fn used_memory() !u64 {
|
||||||
|
page_size := usize(C.sysconf(C._SC_PAGESIZE))
|
||||||
|
c_errno_1 := C.errno
|
||||||
|
if page_size == usize(-1) {
|
||||||
|
return error('used_memory: C.sysconf() return error code = ${c_errno_1}')
|
||||||
|
}
|
||||||
|
|
||||||
|
mut usage := C.rusage{}
|
||||||
|
ret := C.getrusage(C.RUSAGE_SELF, &usage)
|
||||||
|
if ret == -1 {
|
||||||
|
c_errno_2 := C.errno
|
||||||
|
return error('used_memory: C.getrusage() return error code = ${c_errno_2}')
|
||||||
|
}
|
||||||
|
return u64(int_max(1, usage.ru_maxrss)) * 1024
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user