diff options
author | antirez <antirez@gmail.com> | 2016-09-16 10:26:23 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2016-09-16 10:26:23 +0200 |
commit | 78f35f8d2cff306d943366a5c05df9e75b0f028f (patch) | |
tree | c8d45948eae41e273860a01cbe928357ad4f850c | |
parent | 123891dbbf34026c51f1298f7fd6c69a4a3fd8d0 (diff) | |
download | redis-78f35f8d2cff306d943366a5c05df9e75b0f028f.tar.gz |
Memory related subcommands of DEBUG moved to MEMORY.
-rw-r--r-- | src/debug.c | 36 | ||||
-rw-r--r-- | src/object.c | 43 | ||||
-rw-r--r-- | src/redis-cli.c | 5 |
3 files changed, 43 insertions, 41 deletions
diff --git a/src/debug.c b/src/debug.c index 6f0b5e702..bceae8b3b 100644 --- a/src/debug.c +++ b/src/debug.c @@ -252,14 +252,6 @@ void computeDatasetDigest(unsigned char *final) { } } -#if defined(USE_JEMALLOC) -void inputCatSds(void *result, const char *str) { - /* result is actually a (sds *), so re-cast it here */ - sds *info = (sds *)result; - *info = sdscat(*info, str); -} -#endif - void debugCommand(client *c) { if (c->argc == 1) { addReplyError(c,"You must specify a subcommand for DEBUG. Try DEBUG HELP for info."); @@ -303,10 +295,6 @@ void debugCommand(client *c) { "structsize -- Return the size of different Redis core C structures."); blen++; addReplyStatus(c, "htstats <dbid> -- Return hash table statistics of the specified Redis database."); - blen++; addReplyStatus(c, - "jemalloc info -- Show internal jemalloc statistics."); - blen++; addReplyStatus(c, - "jemalloc purge -- Force jemalloc to release unused memory."); setDeferredMultiBulkLength(c,blenp,blen); } else if (!strcasecmp(c->argv[1]->ptr,"segfault")) { *((char*)-1) = 'x'; @@ -520,30 +508,6 @@ void debugCommand(client *c) { stats = sdscat(stats,buf); addReplyBulkSds(c,stats); - } else if (!strcasecmp(c->argv[1]->ptr,"jemalloc") && c->argc == 3) { -#if defined(USE_JEMALLOC) - if (!strcasecmp(c->argv[2]->ptr, "info")) { - sds info = sdsempty(); - je_malloc_stats_print(inputCatSds, &info, NULL); - addReplyBulkSds(c, info); - } else if (!strcasecmp(c->argv[2]->ptr, "purge")) { - char tmp[32]; - unsigned narenas = 0; - size_t sz = sizeof(unsigned); - if (!je_mallctl("arenas.narenas", &narenas, &sz, NULL, 0)) { - sprintf(tmp, "arena.%d.purge", narenas); - if (!je_mallctl(tmp, NULL, 0, NULL, 0)) { - addReply(c, shared.ok); - return; - } - } - addReplyError(c, "Error purging dirty pages"); - } else { - addReplyErrorFormat(c, "Valid jemalloc debug fields: info, purge"); - } -#else - addReplyErrorFormat(c, "jemalloc support not available"); -#endif } else { addReplyErrorFormat(c, "Unknown DEBUG subcommand or wrong number of arguments for '%s'", (char*)c->argv[1]->ptr); diff --git a/src/object.c b/src/object.c index 401e88126..bb1a3eb55 100644 --- a/src/object.c +++ b/src/object.c @@ -893,6 +893,14 @@ struct redisMemOverhead *getMemoryOverheadData(void) { return mh; } +/* Helper for "MEMORY allocator-stats", used as a callback for the jemalloc + * stats output. */ +void inputCatSds(void *result, const char *str) { + /* result is actually a (sds *), so re-cast it here */ + sds *info = (sds *)result; + *info = sdscat(*info, str); +} + /* ======================= The OBJECT and MEMORY commands =================== */ /* This is a helper function for the OBJECT command. We need to lookup keys @@ -1023,12 +1031,41 @@ void memoryCommand(client *c) { addReplyDouble(c,mh->dataset_perc); freeMemoryOverheadData(mh); + } else if (!strcasecmp(c->argv[1]->ptr,"allocator-stats") && c->argc == 2) { +#if defined(USE_JEMALLOC) + sds info = sdsempty(); + je_malloc_stats_print(inputCatSds, &info, NULL); + addReplyBulkSds(c, info); +#else + addReplyBulkCString(c,"Stats not supported for the current allocator"); +#endif + } else if (!strcasecmp(c->argv[1]->ptr,"purge") && c->argc == 2) { +#if defined(USE_JEMALLOC) + char tmp[32]; + unsigned narenas = 0; + size_t sz = sizeof(unsigned); + if (!je_mallctl("arenas.narenas", &narenas, &sz, NULL, 0)) { + sprintf(tmp, "arena.%d.purge", narenas); + if (!je_mallctl(tmp, NULL, 0, NULL, 0)) { + addReply(c, shared.ok); + return; + } + } + addReplyError(c, "Error purging dirty pages"); +#else + addReply(c, shared.ok); + /* Nothing to do for other allocators. */ +#endif } else if (!strcasecmp(c->argv[1]->ptr,"help") && c->argc == 2) { - addReplyMultiBulkLen(c,2); + addReplyMultiBulkLen(c,4); + addReplyBulkCString(c, +"MEMORY USAGE <key> [SAMPLES <count>] - Estimate memory usage of key"); + addReplyBulkCString(c, +"MEMORY OVERHEAD - Show memory usage details"); addReplyBulkCString(c, - "MEMORY USAGE <key> [SAMPLES <count>] - Estimate memory usage of key"); +"MEMORY PURGE - Ask the allocator to release memory"); addReplyBulkCString(c, - "MEMORY OVERHEAD - Show memory usage details"); +"MEMORY ALLOCATOR-STATS - Show allocator internal stats"); } else { addReplyError(c,"Syntax error. Try MEMORY HELP"); } diff --git a/src/redis-cli.c b/src/redis-cli.c index d1735d638..2036e7f46 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -843,8 +843,9 @@ static int cliSendCommand(int argc, char **argv, int repeat) { output_raw = 0; if (!strcasecmp(command,"info") || (argc >= 2 && !strcasecmp(command,"debug") && - ((!strcasecmp(argv[1],"jemalloc") && !strcasecmp(argv[2],"info")) || - !strcasecmp(argv[1],"htstats"))) || + !strcasecmp(argv[1],"htstats")) || + (argc >= 2 && !strcasecmp(command,"memory") && + !strcasecmp(argv[1],"allocator-stats")) || (argc == 2 && !strcasecmp(command,"cluster") && (!strcasecmp(argv[1],"nodes") || !strcasecmp(argv[1],"info"))) || |