diff options
author | antirez <antirez@gmail.com> | 2014-11-12 10:43:32 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2014-11-12 10:43:32 +0100 |
commit | 3ef0876b95a6ff342bc348f5603ae282265f0ca1 (patch) | |
tree | ad38f64bfecc6f4ede1fb48a24b4c16ab37e1640 /src/zmalloc.c | |
parent | bb7fea0d5ca7b3a53532338e8654e409014c1194 (diff) | |
download | redis-3ef0876b95a6ff342bc348f5603ae282265f0ca1.tar.gz |
THP detection / reporting functions added.
Diffstat (limited to 'src/zmalloc.c')
-rw-r--r-- | src/zmalloc.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/zmalloc.c b/src/zmalloc.c index 11616e5ad..e58353725 100644 --- a/src/zmalloc.c +++ b/src/zmalloc.c @@ -328,27 +328,39 @@ float zmalloc_get_fragmentation_ratio(size_t rss) { return (float)rss/zmalloc_used_memory(); } +/* Get the sum of the specified field (converted form kb to bytes) in + * /proc/self/smaps. The field must be specified with trailing ":" as it + * apperas in the smaps output. + * + * Example: zmalloc_get_smap_bytes_by_field("Rss:"); + */ #if defined(HAVE_PROC_SMAPS) -size_t zmalloc_get_private_dirty(void) { +size_t zmalloc_get_smap_bytes_by_field(char *field) { char line[1024]; - size_t pd = 0; + size_t bytes = 0; FILE *fp = fopen("/proc/self/smaps","r"); + int flen = strlen(field); if (!fp) return 0; while(fgets(line,sizeof(line),fp) != NULL) { - if (strncmp(line,"Private_Dirty:",14) == 0) { + if (strncmp(line,field,flen) == 0) { char *p = strchr(line,'k'); if (p) { *p = '\0'; - pd += strtol(line+14,NULL,10) * 1024; + bytes += strtol(line+flen,NULL,10) * 1024; } } } fclose(fp); - return pd; + return bytes; } #else -size_t zmalloc_get_private_dirty(void) { +size_t zmalloc_get_smap_bytes_by_field(char *field) { + REDIS_NOTUSED(field); return 0; } #endif + +size_t zmalloc_get_private_dirty(void) { + return zmalloc_get_smap_bytes_by_field("Private_Dirty:"); +} |