mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 08:08:53 -05:00
MEMORY command: HELP + dataset percentage (like in INFO).
This commit is contained in:
parent
5443726d4d
commit
e9629e148b
21
src/object.c
21
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 <key> [SAMPLES <count>] - Estimate memory usage of key");
|
||||
addReplyBulkCString(c,
|
||||
"MEMORY OVERHEAD - Show memory usage details");
|
||||
} else {
|
||||
addReplyError(c,"Syntax error. Try MEMORY [usage <key>] | [overhead]");
|
||||
addReplyError(c,"Syntax error. Try MEMORY HELP");
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user