summaryrefslogtreecommitdiffstats
path: root/src/Root.cpp
diff options
context:
space:
mode:
authorMorritz <tomeks33@gmail.com>2021-04-30 15:23:31 +0200
committerGitHub <noreply@github.com>2021-04-30 15:23:31 +0200
commita4eba7639e29c0dae1a97d56bb3628686dc9bcac (patch)
tree61e0866434b94b10ae3e578a4ca56f6c9818bb01 /src/Root.cpp
parentAdded functionality: mobs now enter boats and minecarts (#5214) (diff)
downloadcuberite-a4eba7639e29c0dae1a97d56bb3628686dc9bcac.tar
cuberite-a4eba7639e29c0dae1a97d56bb3628686dc9bcac.tar.gz
cuberite-a4eba7639e29c0dae1a97d56bb3628686dc9bcac.tar.bz2
cuberite-a4eba7639e29c0dae1a97d56bb3628686dc9bcac.tar.lz
cuberite-a4eba7639e29c0dae1a97d56bb3628686dc9bcac.tar.xz
cuberite-a4eba7639e29c0dae1a97d56bb3628686dc9bcac.tar.zst
cuberite-a4eba7639e29c0dae1a97d56bb3628686dc9bcac.zip
Diffstat (limited to 'src/Root.cpp')
-rw-r--r--src/Root.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/Root.cpp b/src/Root.cpp
index 62d50c28c..f100a242a 100644
--- a/src/Root.cpp
+++ b/src/Root.cpp
@@ -20,6 +20,11 @@
#endif
#elif defined(__APPLE__)
#include <mach/mach.h>
+ #elif defined(__FreeBSD__)
+ #include <kvm.h>
+ #include <fcntl.h>
+ #include <sys/sysctl.h>
+ #include <sys/user.h>
#endif
#endif
@@ -885,6 +890,37 @@ int cRoot::GetPhysicalRAMUsage(void)
return static_cast<int>(t_info.resident_size / 1024);
}
return -1;
+ #elif defined (__FreeBSD__)
+ /*
+ struct rusage self_usage;
+ int status = getrusage(RUSAGE_SELF, &self_usage);
+ if (!status)
+ {
+ return static_cast<int>(self_usage.ru_maxrss);
+ }
+ return -1;
+ */
+ // Good to watch: https://www.youtube.com/watch?v=Os5cK0H8EOA - getrusage.
+ // Unfortunately, it only gives peak memory usage a.k.a max resident set size
+ // So it is better to use FreeBSD kvm function to get the size of resident pages.
+
+ static kvm_t* kd = NULL;
+
+ if (kd == NULL)
+ {
+ kd = kvm_open(NULL, "/dev/null", NULL, O_RDONLY, "kvm_open"); // returns a descriptor used to access kernel virtual memory
+ }
+ if (kd != NULL)
+ {
+ int pc = 0; // number of processes found
+ struct kinfo_proc* kp;
+ kp = kvm_getprocs(kd, KERN_PROC_PID, getpid(), &pc);
+ if ((kp != NULL) && (pc >= 1))
+ {
+ return static_cast<int>(kp->ki_rssize * getpagesize() / 1024);
+ }
+ }
+ return -1;
#else
LOGINFO("%s: Unknown platform, cannot query memory usage", __FUNCTION__);
return -1;