diff --git a/src/debug.c b/src/debug.c index caf95ec58..c464644cd 100644 --- a/src/debug.c +++ b/src/debug.c @@ -252,6 +252,12 @@ void computeDatasetDigest(unsigned char *final) { } } +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); +} + void debugCommand(redisClient *c) { if (!strcasecmp(c->argv[1]->ptr,"segfault")) { *((char*)-1) = 'x'; @@ -379,6 +385,18 @@ void debugCommand(redisClient *c) { errstr = sdsmapchars(errstr,"\n\r"," ",2); /* no newlines in errors. */ errstr = sdscatlen(errstr,"\r\n",2); addReplySds(c,errstr); + } 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 { + addReplyErrorFormat(c, "Valid jemalloc debug fields: info"); + } +#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/redis-cli.c b/src/redis-cli.c index 2a703ad7f..3c1458742 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -629,6 +629,9 @@ static int cliSendCommand(int argc, char **argv, int repeat) { output_raw = 0; if (!strcasecmp(command,"info") || + (argc == 3 && !strcasecmp(command,"debug") && + (!strcasecmp(argv[1],"jemalloc") && + !strcasecmp(argv[2],"info"))) || (argc == 2 && !strcasecmp(command,"cluster") && (!strcasecmp(argv[1],"nodes") || !strcasecmp(argv[1],"info"))) ||