Memory related subcommands of DEBUG moved to MEMORY.

This commit is contained in:
antirez 2016-09-16 10:26:23 +02:00
parent 123891dbbf
commit 78f35f8d2c
3 changed files with 43 additions and 41 deletions

View File

@ -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) { void debugCommand(client *c) {
if (c->argc == 1) { if (c->argc == 1) {
addReplyError(c,"You must specify a subcommand for DEBUG. Try DEBUG HELP for info."); 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."); "structsize -- Return the size of different Redis core C structures.");
blen++; addReplyStatus(c, blen++; addReplyStatus(c,
"htstats <dbid> -- Return hash table statistics of the specified Redis database."); "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); setDeferredMultiBulkLength(c,blenp,blen);
} else if (!strcasecmp(c->argv[1]->ptr,"segfault")) { } else if (!strcasecmp(c->argv[1]->ptr,"segfault")) {
*((char*)-1) = 'x'; *((char*)-1) = 'x';
@ -520,30 +508,6 @@ void debugCommand(client *c) {
stats = sdscat(stats,buf); stats = sdscat(stats,buf);
addReplyBulkSds(c,stats); 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 { } else {
addReplyErrorFormat(c, "Unknown DEBUG subcommand or wrong number of arguments for '%s'", addReplyErrorFormat(c, "Unknown DEBUG subcommand or wrong number of arguments for '%s'",
(char*)c->argv[1]->ptr); (char*)c->argv[1]->ptr);

View File

@ -893,6 +893,14 @@ struct redisMemOverhead *getMemoryOverheadData(void) {
return mh; 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 =================== */ /* ======================= The OBJECT and MEMORY commands =================== */
/* This is a helper function for the OBJECT command. We need to lookup keys /* 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); addReplyDouble(c,mh->dataset_perc);
freeMemoryOverheadData(mh); 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) { } else if (!strcasecmp(c->argv[1]->ptr,"help") && c->argc == 2) {
addReplyMultiBulkLen(c,2); addReplyMultiBulkLen(c,4);
addReplyBulkCString(c, addReplyBulkCString(c,
"MEMORY USAGE <key> [SAMPLES <count>] - Estimate memory usage of key"); "MEMORY USAGE <key> [SAMPLES <count>] - Estimate memory usage of key");
addReplyBulkCString(c, addReplyBulkCString(c,
"MEMORY OVERHEAD - Show memory usage details"); "MEMORY OVERHEAD - Show memory usage details");
addReplyBulkCString(c,
"MEMORY PURGE - Ask the allocator to release memory");
addReplyBulkCString(c,
"MEMORY ALLOCATOR-STATS - Show allocator internal stats");
} else { } else {
addReplyError(c,"Syntax error. Try MEMORY HELP"); addReplyError(c,"Syntax error. Try MEMORY HELP");
} }

View File

@ -843,8 +843,9 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
output_raw = 0; output_raw = 0;
if (!strcasecmp(command,"info") || if (!strcasecmp(command,"info") ||
(argc >= 2 && !strcasecmp(command,"debug") && (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") && (argc == 2 && !strcasecmp(command,"cluster") &&
(!strcasecmp(argv[1],"nodes") || (!strcasecmp(argv[1],"nodes") ||
!strcasecmp(argv[1],"info"))) || !strcasecmp(argv[1],"info"))) ||