summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorruki <[email protected]>2022-07-28 22:51:45 +0800
committerruki <[email protected]>2022-07-28 22:51:45 +0800
commitfcb297222208ce01ded75110600498b48f41076c (patch)
tree3d8c0ff14633b70895d2e5af0e6265226ffb95d0 /core
parent4f7685a8d9df681dd2e47abc6095d896e29a06c3 (diff)
add meminfo for bsd
Diffstat (limited to 'core')
-rw-r--r--core/src/xmake/os/meminfo.c32
1 files changed, 13 insertions, 19 deletions
diff --git a/core/src/xmake/os/meminfo.c b/core/src/xmake/os/meminfo.c
index 48797e4d2..d6634b93f 100644
--- a/core/src/xmake/os/meminfo.c
+++ b/core/src/xmake/os/meminfo.c
@@ -42,9 +42,6 @@
#elif defined(TB_CONFIG_OS_BSD)
# include <sys/types.h>
# include <sys/sysctl.h>
-# include <sys/vmmeter.h>
-# include <sys/limits.h>
-# include <vm/vm_param.h>
#endif
/* //////////////////////////////////////////////////////////////////////////////////////
@@ -138,22 +135,19 @@ static tb_bool_t xm_os_meminfo_stats(tb_int_t* ptotalsize, tb_int_t* pavailsize)
return tb_true;
}
#elif defined(TB_CONFIG_OS_BSD)
- struct vmtotal vm_info;
- int mib[2];
- mib[0] = CTL_VM;
- mib[1] = VM_TOTAL;
- size_t len = sizeof(vm_info);
- if (sysctl(mib, 2, &vm_info, &len, tb_null, 0) == 0)
- {
- tb_trace_i("Total VM Memory: %d\n",vm_info.t_vm);
- tb_trace_i("Total Real Memory: %d\n",vm_info.t_rm);
- tb_trace_i("shared real memory: %d\n",vm_info.t_rmshr);
- tb_trace_i("active shared real memory: %d\n",vm_info.t_armshr);
- tb_trace_i("Total Free Memory pages: %d\n",vm_info.t_free);
- *ptotalsize = (tb_int_t)(vm_info.t_vm / (1024 * 1024));
- *pavailsize = (tb_int_t)(vm_info.t_free / (1024 * 1024));
- return tb_true;
- }
+ unsigned long totalsize;
+ size_t size = sizeof(totalsize);
+ if (sysctlbyname("hw.physmem", &totalsize, &size, tb_null, 0) != 0)
+ return tb_false;
+
+ tb_uint32_t availsize;
+ size = sizeof(availsize);
+ if (sysctlbyname("vm.stats.vm.v_free_count", &availsize, &size, tb_null, 0) != 0)
+ return tb_false;
+
+ *ptotalsize = (tb_int_t)(totalsize / (1024 * 1024));
+ *pavailsize = (tb_int_t)(((tb_int64_t)availsize * tb_page_size()) / (1024 * 1024));
+ return tb_true;
#endif
return tb_false;
}