@@ -64,7 +64,7 @@ size_t get_current_rss() {
64
64
--------------------------------------------------- */
65
65
#else
66
66
/* ----------------------------------------------------
67
- Linux/OSX version for get_peak_rss and get_current_rss
67
+ Linux/FreeBSD/ OSX version for get_peak_rss and get_current_rss
68
68
--------------------------------------------------- */
69
69
#include < unistd.h>
70
70
#include < sys/resource.h>
@@ -73,6 +73,20 @@ size_t get_current_rss() {
73
73
#include < mach/mach.h>
74
74
#endif
75
75
76
+ #if defined(__FreeBSD__)
77
+ // for getpagesize
78
+ #include < unistd.h>
79
+ // for procstat_*
80
+ #include < sys/param.h>
81
+ #include < sys/queue.h>
82
+ #include < sys/socket.h>
83
+ #include < libprocstat.h>
84
+ // for struct kinfo_proc
85
+ #include < sys/user.h>
86
+ // for KERN_PROC_PID
87
+ #include < sys/sysctl.h>
88
+ #endif
89
+
76
90
namespace lean {
77
91
size_t get_peak_rss () {
78
92
struct rusage rusage ;
@@ -91,6 +105,28 @@ size_t get_current_rss() {
91
105
if (task_info (mach_task_self (), MACH_TASK_BASIC_INFO, reinterpret_cast <task_info_t >(&info), &infoCount) != KERN_SUCCESS)
92
106
return static_cast <size_t >(0 );
93
107
return static_cast <size_t >(info.resident_size );
108
+ #elif defined(__FreeBSD__)
109
+ // initialize
110
+ unsigned int count = 0 ;
111
+
112
+ struct procstat *pstat = procstat_open_sysctl ();
113
+ if (!pstat)
114
+ return static_cast <size_t >(0 );
115
+
116
+ struct kinfo_proc *kp = procstat_getprocs (pstat, KERN_PROC_PID, getpid (), &count);
117
+ if (!kp) {
118
+ procstat_close (pstat);
119
+ return static_cast <size_t >(0 );
120
+ }
121
+
122
+ // compute
123
+ size_t rss_size = kp->ki_rssize *getpagesize ();
124
+
125
+ // cleanup
126
+ procstat_freeprocs (pstat, kp);
127
+ procstat_close (pstat);
128
+
129
+ return rss_size;
94
130
#else
95
131
long rss = 0 ;
96
132
FILE * fp = nullptr ;
0 commit comments