mirror of
https://github.com/zeek/zeek.git
synced 2025-10-13 12:08:20 +00:00
avoid potentially expensive mallinfo() call if result won't be used
This commit is contained in:
parent
5402f22d48
commit
f88862f6ce
1 changed files with 6 additions and 3 deletions
|
@ -2182,13 +2182,14 @@ void get_memory_usage(uint64_t* total, uint64_t* malloced) {
|
||||||
uint64_t ret_total;
|
uint64_t ret_total;
|
||||||
|
|
||||||
#if defined(HAVE_MALLINFO2) || defined(HAVE_MALLINFO)
|
#if defined(HAVE_MALLINFO2) || defined(HAVE_MALLINFO)
|
||||||
|
if ( malloced ) {
|
||||||
#ifdef HAVE_MALLINFO2
|
#ifdef HAVE_MALLINFO2
|
||||||
struct mallinfo2 mi = mallinfo2();
|
struct mallinfo2 mi = mallinfo2();
|
||||||
#else
|
#else
|
||||||
struct mallinfo mi = mallinfo();
|
struct mallinfo mi = mallinfo();
|
||||||
#endif
|
#endif
|
||||||
if ( malloced )
|
|
||||||
*malloced = mi.uordblks;
|
*malloced = mi.uordblks;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_DARWIN
|
#ifdef HAVE_DARWIN
|
||||||
|
@ -2207,6 +2208,8 @@ void get_memory_usage(uint64_t* total, uint64_t* malloced) {
|
||||||
ret_total = r.ru_maxrss * 1024;
|
ret_total = r.ru_maxrss * 1024;
|
||||||
|
|
||||||
if ( malloced )
|
if ( malloced )
|
||||||
|
// This will overwrite any mallinfo[2] value from above, should
|
||||||
|
// be restructured to avoid unnecessary work.
|
||||||
*malloced = r.ru_ixrss * 1024;
|
*malloced = r.ru_ixrss * 1024;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue