From 819a661be5efcb045be4d34d7269ab35dc0fcb88 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 15 Sep 2019 14:05:00 +0100 Subject: [PATCH] Getting region date per process in Darwin --- src/zmalloc.c | 12 ++++++++++++ src/zmalloc.h | 1 + 2 files changed, 13 insertions(+) diff --git a/src/zmalloc.c b/src/zmalloc.c index fd8bb6938..48f4b1e99 100644 --- a/src/zmalloc.c +++ b/src/zmalloc.c @@ -396,6 +396,18 @@ size_t zmalloc_get_smap_bytes_by_field(char *field, long pid) { } #else size_t zmalloc_get_smap_bytes_by_field(char *field, long pid) { +#if defined(__APPLE__) + struct proc_regioninfo pri; + if (proc_pidinfo(pid, PROC_PIDREGIONINFO, 0, &pri, PROC_PIDREGIONINFO_SIZE) == + PROC_PIDREGIONINFO_SIZE) { + if (!strcmp(field, "Private_Dirty")) { + return (size_t)pri.pri_pages_dirtied * 4096; + } else if (!strcmp(field, "Rss")) { + return (size_t)pri.pri_pages_resident * 4096; + } + } + return 0; +#endif ((void) field); ((void) pid); return 0; diff --git a/src/zmalloc.h b/src/zmalloc.h index 6fb19b046..4aa33509d 100644 --- a/src/zmalloc.h +++ b/src/zmalloc.h @@ -57,6 +57,7 @@ #elif defined(__APPLE__) #include +#include #define HAVE_MALLOC_SIZE 1 #define zmalloc_size(p) malloc_size(p) #endif