Merge pull request #6384 from devnexen/apple_smaps_impl

Getting region date per process in Darwin
This commit is contained in:
Salvatore Sanfilippo 2019-12-02 09:02:08 +01:00 committed by GitHub
commit e5b5f9a2f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -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;

View File

@ -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