diff options
author | Salvatore Sanfilippo <antirez@gmail.com> | 2019-12-02 09:02:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-02 09:02:08 +0100 |
commit | e5b5f9a2f6245be8496192c80a809a47f2f235ef (patch) | |
tree | 7278d1759fec9947b7694b1fb36123763dd6519f | |
parent | ce7ec725e34a65d607b155a557a0485e3fd230af (diff) | |
parent | 5a8a0050269382d94d88016ba04272eef658bc97 (diff) | |
download | redis-e5b5f9a2f6245be8496192c80a809a47f2f235ef.tar.gz |
Merge pull request #6384 from devnexen/apple_smaps_impl
Getting region date per process in Darwin
-rw-r--r-- | src/zmalloc.c | 21 | ||||
-rw-r--r-- | src/zmalloc.h | 1 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/zmalloc.c b/src/zmalloc.c index e02267fc9..ec7fcc030 100644 --- a/src/zmalloc.c +++ b/src/zmalloc.c @@ -427,7 +427,28 @@ size_t zmalloc_get_smap_bytes_by_field(char *field, long pid) { return bytes; } #else +/* Get sum of the specified field from libproc api call. + * As there are per page value basis we need to convert + * them accordingly. + * + * Note that AnonHugePages is a no-op as THP feature + * is not supported in this platform + */ 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; + } else if (!strcmp(field, "AnonHugePages:")) { + return 0; + } + } + return 0; +#endif ((void) field); ((void) pid); return 0; diff --git a/src/zmalloc.h b/src/zmalloc.h index b136a910d..d32698e62 100644 --- a/src/zmalloc.h +++ b/src/zmalloc.h @@ -57,6 +57,7 @@ #elif defined(__APPLE__) #include <malloc/malloc.h> +#include <libproc.h> #define HAVE_MALLOC_SIZE 1 #define zmalloc_size(p) malloc_size(p) #endif |