From e9629e148bb445474e172134c1bc0d248adf2454 Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 15 Sep 2016 17:33:11 +0200 Subject: [PATCH] MEMORY command: HELP + dataset percentage (like in INFO). --- src/object.c | 21 ++++++++++++++++++--- src/server.c | 6 +----- src/server.h | 1 + 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/object.c b/src/object.c index e47d663e0..02d023248 100644 --- a/src/object.c +++ b/src/object.c @@ -936,6 +936,12 @@ struct redisMemOverhead *getMemoryOverheadData(void) { mh->overhead_total = mem_total; mh->dataset = zmalloc_used - mem_total; + + size_t net_usage = 1; + if (zmalloc_used > mh->startup_allocated) + net_usage = zmalloc_used - mh->startup_allocated; + mh->dataset_perc = (float)mh->dataset*100/net_usage; + return mh; } @@ -974,7 +980,7 @@ void memoryCommand(client *c) { } else if (!strcasecmp(c->argv[1]->ptr,"overhead") && c->argc == 2) { struct redisMemOverhead *mh = getMemoryOverheadData(); - addReplyMultiBulkLen(c,(8+mh->num_dbs)*2); + addReplyMultiBulkLen(c,(9+mh->num_dbs)*2); addReplyBulkCString(c,"total.allocated"); addReplyLongLong(c,mh->total_allocated); @@ -1010,11 +1016,20 @@ void memoryCommand(client *c) { addReplyBulkCString(c,"overhead.total"); addReplyLongLong(c,mh->overhead_total); - addReplyBulkCString(c,"dataset"); + addReplyBulkCString(c,"dataset.bytes"); addReplyLongLong(c,mh->dataset); + addReplyBulkCString(c,"dataset.percentage"); + addReplyDouble(c,mh->dataset_perc); + freeMemoryOverheadData(mh); + } else if (!strcasecmp(c->argv[1]->ptr,"help") && c->argc == 2) { + addReplyMultiBulkLen(c,2); + addReplyBulkCString(c, + "MEMORY USAGE [SAMPLES ] - Estimate memory usage of key"); + addReplyBulkCString(c, + "MEMORY OVERHEAD - Show memory usage details"); } else { - addReplyError(c,"Syntax error. Try MEMORY [usage ] | [overhead]"); + addReplyError(c,"Syntax error. Try MEMORY HELP"); } } diff --git a/src/server.c b/src/server.c index fbc2b0a4d..556ea965b 100644 --- a/src/server.c +++ b/src/server.c @@ -2828,10 +2828,6 @@ sds genRedisInfoString(char *section) { bytesToHuman(used_memory_rss_hmem,server.resident_set_size); bytesToHuman(maxmemory_hmem,server.maxmemory); - size_t net_usage = 1; - if (zmalloc_used > mh->startup_allocated) - net_usage = zmalloc_used - mh->startup_allocated; - if (sections++) info = sdscat(info,"\r\n"); info = sdscatprintf(info, "# Memory\r\n" @@ -2864,7 +2860,7 @@ sds genRedisInfoString(char *section) { mh->overhead_total, mh->startup_allocated, mh->dataset, - (float)mh->dataset*100/net_usage, + mh->dataset_perc, (unsigned long)total_system_mem, total_system_hmem, memory_lua, diff --git a/src/server.h b/src/server.h index fb094507b..3f2028f83 100644 --- a/src/server.h +++ b/src/server.h @@ -780,6 +780,7 @@ struct redisMemOverhead { size_t aof_buffer; size_t overhead_total; size_t dataset; + float dataset_perc; size_t num_dbs; struct { size_t dbid;