used_memory_human added to INFO output. Human readable amount of memory used.

This commit is contained in:
antirez 2010-01-08 10:38:48 -05:00
parent ace065423e
commit ec6c7a1d78
2 changed files with 27 additions and 4 deletions

4
TODO
View File

@ -13,11 +13,9 @@ VERSION 1.4 TODO (Hash type)
Virtual Memory sub-TODO:
* Check if the page selection algorithm is working well.
* Fix support for large files
* Divide swappability of objects by refcount
* While loading DB from snapshot or AOF, swap objects as needed if maxmemory
is reached, calling swapOneObject().
* vm-swap-file <filename>. The swap file should go where the user wants, and if it's already there and of the right size we can avoid to create it again.
* it should be possible to give the vm-max-memory option in megabyte, gigabyte, ..., just using 2GB, 100MB, and so forth.
VERSION 1.6 TODO (Virtual memory)
=================================

27
redis.c
View File

@ -5407,6 +5407,27 @@ static void sortCommand(redisClient *c) {
zfree(vector);
}
/* Convert an amount of bytes into a human readable string in the form
* of 100B, 2G, 100M, 4K, and so forth. */
static void bytesToHuman(char *s, unsigned long long n) {
double d;
if (n < 1024) {
/* Bytes */
sprintf(s,"%lluB",n);
return;
} else if (n < (1024*1024)) {
d = (double)n/(1024);
sprintf(s,"%.2fK",d);
} else if (n < (1024LL*1024*1024)) {
d = (double)n/(1024*1024);
sprintf(s,"%.2fM",d);
} else if (n < (1024LL*1024*1024*1024)) {
d = (double)n/(1024LL*1024*1024);
sprintf(s,"%.2fM",d);
}
}
/* Create the string returned by the INFO command. This is decoupled
* by the INFO command itself as we need to report the same information
* on memory corruption problems. */
@ -5414,7 +5435,9 @@ static sds genRedisInfoString(void) {
sds info;
time_t uptime = time(NULL)-server.stat_starttime;
int j;
char hmem[64];
bytesToHuman(hmem,server.usedmemory);
info = sdscatprintf(sdsempty(),
"redis_version:%s\r\n"
"arch_bits:%s\r\n"
@ -5426,6 +5449,7 @@ static sds genRedisInfoString(void) {
"connected_slaves:%d\r\n"
"blocked_clients:%d\r\n"
"used_memory:%zu\r\n"
"used_memory_human:%s\r\n"
"changes_since_last_save:%lld\r\n"
"bgsave_in_progress:%d\r\n"
"last_save_time:%ld\r\n"
@ -5444,6 +5468,7 @@ static sds genRedisInfoString(void) {
listLength(server.slaves),
server.blockedclients,
server.usedmemory,
hmem,
server.dirty,
server.bgsavechildpid != -1,
server.lastsave,