summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2010-01-08 10:38:48 -0500
committerantirez <antirez@gmail.com>2010-01-08 10:38:48 -0500
commitec6c7a1d78d4f42f78d5e006d7b1e804388088a1 (patch)
treebb0b1827028e33b5334bbd77997bc1827454b2ae
parentace065423e275013f334ac8c40a96cb173c6897e (diff)
downloadredis-ec6c7a1d78d4f42f78d5e006d7b1e804388088a1.tar.gz
used_memory_human added to INFO output. Human readable amount of memory used.
-rw-r--r--TODO4
-rw-r--r--redis.c27
2 files changed, 27 insertions, 4 deletions
diff --git a/TODO b/TODO
index 70e12672c..ca8e6ddc2 100644
--- a/TODO
+++ b/TODO
@@ -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)
=================================
diff --git a/redis.c b/redis.c
index 7caa81039..35e11fa54 100644
--- a/redis.c
+++ b/redis.c
@@ -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,