avoid potentially expensive mallinfo() call if result won't be used

This commit is contained in:
Vern Paxson 2024-03-10 12:40:30 -07:00 committed by Tim Wojtulewicz
parent 5402f22d48
commit f88862f6ce

View file

@ -2182,13 +2182,14 @@ void get_memory_usage(uint64_t* total, uint64_t* malloced) {
uint64_t ret_total;
#if defined(HAVE_MALLINFO2) || defined(HAVE_MALLINFO)
if ( malloced ) {
#ifdef HAVE_MALLINFO2
struct mallinfo2 mi = mallinfo2();
struct mallinfo2 mi = mallinfo2();
#else
struct mallinfo mi = mallinfo();
struct mallinfo mi = mallinfo();
#endif
if ( malloced )
*malloced = mi.uordblks;
}
#endif
#ifdef HAVE_DARWIN
@ -2207,6 +2208,8 @@ void get_memory_usage(uint64_t* total, uint64_t* malloced) {
ret_total = r.ru_maxrss * 1024;
if ( malloced )
// This will overwrite any mallinfo[2] value from above, should
// be restructured to avoid unnecessary work.
*malloced = r.ru_ixrss * 1024;
#endif