diff --git a/configure.ac b/configure.ac index a5b49d9a1..676aa42ca 100644 --- a/configure.ac +++ b/configure.ac @@ -223,6 +223,10 @@ AC_CHECK_HEADERS([execinfo.h]) if test "$my_htop_platform" = darwin; then AC_CHECK_HEADERS([mach/mach_time.h]) AC_CHECK_TYPES([thread_extended_info_data_t], [], [], [[#include ]]) + AC_CHECK_MEMBERS([struct vm_statistics64.compressor_page_count], [], [], [[#include ]]) + AC_CHECK_MEMBERS([struct vm_statistics64.external_page_count], [], [], [[#include ]]) + + AC_CHECK_DECLS([kIOMainPortDefault], [], [], [[#include ]]) fi # ---------------------------------------------------------------------- diff --git a/darwin/DarwinMachine.c b/darwin/DarwinMachine.c index 4937be105..df50f2303 100644 --- a/darwin/DarwinMachine.c +++ b/darwin/DarwinMachine.c @@ -16,6 +16,7 @@ in the source distribution for its full text. #include #include #include +#include #include "CRT.h" #include "Machine.h" @@ -24,6 +25,10 @@ in the source distribution for its full text. #include "generic/openzfs_sysctl.h" #include "zfs/ZfsArcStats.h" +// Compatibility for older SDKs. +#if defined(HAVE_DECL_KIOMAINPORTDEFAULT) && !HAVE_DECL_KIOMAINPORTDEFAULT +#define kIOMainPortDefault kIOMasterPortDefault +#endif static void DarwinMachine_getHostInfo(host_basic_info_data_t* p) { mach_msg_type_number_t info_size = HOST_BASIC_INFO_COUNT; diff --git a/darwin/Platform.c b/darwin/Platform.c index 72d262590..b871fc5aa 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -15,11 +15,11 @@ in the source distribution for its full text. #include #include #include -#include #include #include #include #include +#include // After `sys/socket.h` for struct `sockaddr` (for iOS6 SDK) #include #include @@ -404,15 +404,26 @@ void Platform_setMemoryValues(Meter* mtr) { mtr->total = dhost->host_info.max_mem / 1024; #ifdef HAVE_STRUCT_VM_STATISTICS64 natural_t used = vm->active_count + vm->inactive_count + - vm->speculative_count + vm->wire_count + - vm->compressor_page_count - vm->purgeable_count - vm->external_page_count; + vm->speculative_count + vm->wire_count - vm->purgeable_count; +#ifdef HAVE_STRUCT_VM_STATISTICS64_EXTERNAL_PAGE_COUNT + used -= vm->external_page_count; +#endif +#ifdef HAVE_STRUCT_VM_STATISTICS64_COMPRESSOR_PAGE_COUNT + used += vm->compressor_page_count; mtr->values[MEMORY_METER_USED] = (double)(used - vm->compressor_page_count) * page_K; +#else + mtr->values[MEMORY_METER_USED] = (double)used * page_K; +#endif #else mtr->values[MEMORY_METER_USED] = (double)(vm->active_count + vm->wire_count) * page_K; #endif // mtr->values[MEMORY_METER_SHARED] = "shared memory, like tmpfs and shm" #ifdef HAVE_STRUCT_VM_STATISTICS64 +#ifdef HAVE_STRUCT_VM_STATISTICS64_COMPRESSOR_PAGE_COUNT mtr->values[MEMORY_METER_COMPRESSED] = (double)vm->compressor_page_count * page_K; +#else + // mtr->values[MEMORY_METER_COMPRESSED] = "compressed memory not available" +#endif #else // mtr->values[MEMORY_METER_COMPRESSED] = "compressed memory, like zswap on linux" #endif