X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/de32c37c06ee447d5d7d3505725c100da2c03c75..b1ee7da75a4191bf1785f598c158b191104fdc38:/src/slowlog.c diff --git a/src/slowlog.c b/src/slowlog.c index 17edf615..53c44a01 100644 --- a/src/slowlog.c +++ b/src/slowlog.c @@ -16,16 +16,40 @@ * this function. */ slowlogEntry *slowlogCreateEntry(robj **argv, int argc, long long duration) { slowlogEntry *se = zmalloc(sizeof(*se)); - int j; + int j, slargc = argc; + + if (slargc > SLOWLOG_ENTRY_MAX_ARGC) slargc = SLOWLOG_ENTRY_MAX_ARGC; + se->argc = slargc; + se->argv = zmalloc(sizeof(robj*)*slargc); + for (j = 0; j < slargc; j++) { + /* Logging too many arguments is a useless memory waste, so we stop + * at SLOWLOG_ENTRY_MAX_ARGC, but use the last argument to specify + * how many remaining arguments there were in the original command. */ + if (slargc != argc && j == slargc-1) { + se->argv[j] = createObject(REDIS_STRING, + sdscatprintf(sdsempty(),"... (%d more arguments)", + argc-slargc+1)); + } else { + /* Trim too long strings as well... */ + if (argv[j]->type == REDIS_STRING && + argv[j]->encoding == REDIS_ENCODING_RAW && + sdslen(argv[j]->ptr) > SLOWLOG_ENTRY_MAX_STRING) + { + sds s = sdsnewlen(argv[j]->ptr, SLOWLOG_ENTRY_MAX_STRING); - se->argc = argc; - se->argv = zmalloc(sizeof(robj*)*argc); - for (j = 0; j < argc; j++) { - se->argv[j] = argv[j]; - incrRefCount(argv[j]); + s = sdscatprintf(s,"... (%lu more bytes)", + (unsigned long) + sdslen(argv[j]->ptr) - SLOWLOG_ENTRY_MAX_STRING); + se->argv[j] = createObject(REDIS_STRING,s); + } else { + se->argv[j] = argv[j]; + incrRefCount(argv[j]); + } + } } se->time = time(NULL); se->duration = duration; + se->id = server.slowlog_entry_id++; return se; } @@ -47,6 +71,7 @@ void slowlogFreeEntry(void *septr) { * at server startup. */ void slowlogInit(void) { server.slowlog = listCreate(); + server.slowlog_entry_id = 0; listSetFreeMethod(server.slowlog,slowlogFreeEntry); } @@ -96,7 +121,8 @@ void slowlogCommand(redisClient *c) { int j; se = ln->value; - addReplyMultiBulkLen(c,3); + addReplyMultiBulkLen(c,4); + addReplyLongLong(c,se->id); addReplyLongLong(c,se->time); addReplyLongLong(c,se->duration); addReplyMultiBulkLen(c,se->argc);