MEMORY command: HELP + dataset percentage (like in INFO).

This commit is contained in:
antirez 2016-09-15 17:33:11 +02:00
parent 5443726d4d
commit e9629e148b
3 changed files with 20 additions and 8 deletions

View File

@ -936,6 +936,12 @@ struct redisMemOverhead *getMemoryOverheadData(void) {
mh->overhead_total = mem_total; mh->overhead_total = mem_total;
mh->dataset = zmalloc_used - 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; return mh;
} }
@ -974,7 +980,7 @@ void memoryCommand(client *c) {
} else if (!strcasecmp(c->argv[1]->ptr,"overhead") && c->argc == 2) { } else if (!strcasecmp(c->argv[1]->ptr,"overhead") && c->argc == 2) {
struct redisMemOverhead *mh = getMemoryOverheadData(); struct redisMemOverhead *mh = getMemoryOverheadData();
addReplyMultiBulkLen(c,(8+mh->num_dbs)*2); addReplyMultiBulkLen(c,(9+mh->num_dbs)*2);
addReplyBulkCString(c,"total.allocated"); addReplyBulkCString(c,"total.allocated");
addReplyLongLong(c,mh->total_allocated); addReplyLongLong(c,mh->total_allocated);
@ -1010,11 +1016,20 @@ void memoryCommand(client *c) {
addReplyBulkCString(c,"overhead.total"); addReplyBulkCString(c,"overhead.total");
addReplyLongLong(c,mh->overhead_total); addReplyLongLong(c,mh->overhead_total);
addReplyBulkCString(c,"dataset"); addReplyBulkCString(c,"dataset.bytes");
addReplyLongLong(c,mh->dataset); addReplyLongLong(c,mh->dataset);
addReplyBulkCString(c,"dataset.percentage");
addReplyDouble(c,mh->dataset_perc);
freeMemoryOverheadData(mh); freeMemoryOverheadData(mh);
} else if (!strcasecmp(c->argv[1]->ptr,"help") && c->argc == 2) {
addReplyMultiBulkLen(c,2);
addReplyBulkCString(c,
"MEMORY USAGE <key> [SAMPLES <count>] - Estimate memory usage of key");
addReplyBulkCString(c,
"MEMORY OVERHEAD - Show memory usage details");
} else { } else {
addReplyError(c,"Syntax error. Try MEMORY [usage <key>] | [overhead]"); addReplyError(c,"Syntax error. Try MEMORY HELP");
} }
} }

View File

@ -2828,10 +2828,6 @@ sds genRedisInfoString(char *section) {
bytesToHuman(used_memory_rss_hmem,server.resident_set_size); bytesToHuman(used_memory_rss_hmem,server.resident_set_size);
bytesToHuman(maxmemory_hmem,server.maxmemory); 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"); if (sections++) info = sdscat(info,"\r\n");
info = sdscatprintf(info, info = sdscatprintf(info,
"# Memory\r\n" "# Memory\r\n"
@ -2864,7 +2860,7 @@ sds genRedisInfoString(char *section) {
mh->overhead_total, mh->overhead_total,
mh->startup_allocated, mh->startup_allocated,
mh->dataset, mh->dataset,
(float)mh->dataset*100/net_usage, mh->dataset_perc,
(unsigned long)total_system_mem, (unsigned long)total_system_mem,
total_system_hmem, total_system_hmem,
memory_lua, memory_lua,

View File

@ -780,6 +780,7 @@ struct redisMemOverhead {
size_t aof_buffer; size_t aof_buffer;
size_t overhead_total; size_t overhead_total;
size_t dataset; size_t dataset;
float dataset_perc;
size_t num_dbs; size_t num_dbs;
struct { struct {
size_t dbid; size_t dbid;