summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorItamar Haber <itamar@redislabs.com>2017-04-13 17:03:46 +0300
committerItamar Haber <itamar@redislabs.com>2017-04-13 17:03:46 +0300
commitb8286d1fc9c1b8c2e17a9e884d94492ba039c53c (patch)
treed14c680aaae8f90df5488461c931ce828c36bca2
parent1210af380429f2f96324f4c46a6aef7e4ddb7a3e (diff)
downloadredis-b8286d1fc9c1b8c2e17a9e884d94492ba039c53c.tar.gz
Changes command stats iteration to being dict-based
With the addition of modules, looping over the redisCommandTable misses any added commands. By moving to dictionary iteration this is resolved.
-rw-r--r--src/server.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/server.c b/src/server.c
index db853b836..e0a96c7ca 100644
--- a/src/server.c
+++ b/src/server.c
@@ -1951,15 +1951,18 @@ void populateCommandTable(void) {
}
void resetCommandTableStats(void) {
- int numcommands = sizeof(redisCommandTable)/sizeof(struct redisCommand);
- int j;
-
- for (j = 0; j < numcommands; j++) {
- struct redisCommand *c = redisCommandTable+j;
+ struct redisCommand *c;
+ dictEntry *de;
+ dictIterator *di;
+ di = dictGetSafeIterator(server.commands);
+ while((de = dictNext(di)) != NULL) {
+ c = (struct redisCommand *) dictGetVal(de);
c->microseconds = 0;
c->calls = 0;
}
+ dictReleaseIterator(di);
+
}
/* ========================== Redis OP Array API ============================ */
@@ -2758,7 +2761,7 @@ void bytesToHuman(char *s, unsigned long long n) {
sds genRedisInfoString(char *section) {
sds info = sdsempty();
time_t uptime = server.unixtime-server.stat_starttime;
- int j, numcommands;
+ int j;
struct rusage self_ru, c_ru;
unsigned long lol, bib;
int allsections = 0, defsections = 0;
@@ -3215,20 +3218,24 @@ sds genRedisInfoString(char *section) {
(float)c_ru.ru_utime.tv_sec+(float)c_ru.ru_utime.tv_usec/1000000);
}
- /* cmdtime */
+ /* Command statistics */
if (allsections || !strcasecmp(section,"commandstats")) {
if (sections++) info = sdscat(info,"\r\n");
info = sdscatprintf(info, "# Commandstats\r\n");
- numcommands = sizeof(redisCommandTable)/sizeof(struct redisCommand);
- for (j = 0; j < numcommands; j++) {
- struct redisCommand *c = redisCommandTable+j;
+ struct redisCommand *c;
+ dictEntry *de;
+ dictIterator *di;
+ di = dictGetSafeIterator(server.commands);
+ while((de = dictNext(di)) != NULL) {
+ c = (struct redisCommand *) dictGetVal(de);
if (!c->calls) continue;
info = sdscatprintf(info,
"cmdstat_%s:calls=%lld,usec=%lld,usec_per_call=%.2f\r\n",
c->name, c->calls, c->microseconds,
(c->calls == 0) ? 0 : ((float)c->microseconds/c->calls));
}
+ dictReleaseIterator(di);
}
/* Cluster */