mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 23:58:20 +00:00
Fix memory usage collection on Mac OS X.
- getrusage is broken on Mac OS X, but there is a Mach API available which can collect the same memory usage information.
This commit is contained in:
parent
2b0a28686a
commit
88517230b6
2 changed files with 21 additions and 0 deletions
|
@ -14,6 +14,9 @@
|
||||||
/* We are on a Linux system */
|
/* We are on a Linux system */
|
||||||
#cmakedefine HAVE_LINUX
|
#cmakedefine HAVE_LINUX
|
||||||
|
|
||||||
|
/* We are on a Mac OS X (Darwin) system */
|
||||||
|
#cmakedefine HAVE_DARWIN
|
||||||
|
|
||||||
/* Define if you have the `mallinfo' function. */
|
/* Define if you have the `mallinfo' function. */
|
||||||
#cmakedefine HAVE_MALLINFO
|
#cmakedefine HAVE_MALLINFO
|
||||||
|
|
||||||
|
|
18
src/util.cc
18
src/util.cc
|
@ -14,6 +14,11 @@
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_DARWIN
|
||||||
|
#include <mach/task.h>
|
||||||
|
#include <mach/mach_init.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -1662,11 +1667,24 @@ void get_memory_usage(unsigned int* total, unsigned int* malloced)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_DARWIN
|
||||||
|
struct task_basic_info t_info;
|
||||||
|
mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;
|
||||||
|
|
||||||
|
if ( KERN_SUCCESS != task_info(mach_task_self(),
|
||||||
|
TASK_BASIC_INFO,
|
||||||
|
(task_info_t)&t_info,
|
||||||
|
&t_info_count) )
|
||||||
|
ret_total = 0;
|
||||||
|
else
|
||||||
|
ret_total = t_info.resident_size;
|
||||||
|
#else
|
||||||
struct rusage r;
|
struct rusage r;
|
||||||
getrusage(RUSAGE_SELF, &r);
|
getrusage(RUSAGE_SELF, &r);
|
||||||
|
|
||||||
// In KB.
|
// In KB.
|
||||||
ret_total = r.ru_maxrss * 1024;
|
ret_total = r.ru_maxrss * 1024;
|
||||||
|
#endif
|
||||||
|
|
||||||
if ( total )
|
if ( total )
|
||||||
*total = ret_total;
|
*total = ret_total;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue