]> git.saurik.com Git - redis.git/commitdiff
INFO commandstats section reset with config resetstat, a new microseconds per call...
authorantirez <antirez@gmail.com>
Mon, 24 Jan 2011 09:56:06 +0000 (10:56 +0100)
committerantirez <antirez@gmail.com>
Mon, 24 Jan 2011 09:56:06 +0000 (10:56 +0100)
src/config.c
src/redis.c
src/redis.h

index 219c99ca0936a35c34bb5209aa3b43a9b58ec85b..5d2c316b1a0c741d6a7281e5e2a51c0b6dd9b948 100644 (file)
@@ -555,6 +555,7 @@ void configCommand(redisClient *c) {
         server.stat_numcommands = 0;
         server.stat_numconnections = 0;
         server.stat_expiredkeys = 0;
+        resetCommandTableStats();
         addReply(c,shared.ok);
     } else {
         addReplyError(c,
index f299dcab6ffe492d75295ba060768187f998e577..367c667df6e22d015e5067233f71fdbf30eb97b8 100644 (file)
@@ -68,7 +68,7 @@ double R_Zero, R_PosInf, R_NegInf, R_Nan;
 /* Global vars */
 struct redisServer server; /* server global state */
 struct redisCommand *commandTable;
-struct redisCommand readonlyCommandTable[] = {
+struct redisCommand redisCommandTable[] = {
     {"get",getCommand,2,0,NULL,1,1,1,0,0},
     {"set",setCommand,3,REDIS_CMD_DENYOOM,NULL,0,0,0,0,0},
     {"setnx",setnxCommand,3,REDIS_CMD_DENYOOM,NULL,0,0,0,0,0},
@@ -936,10 +936,10 @@ void initServer() {
  * we have on top of redis.c file. */
 void populateCommandTable(void) {
     int j;
-    int numcommands = sizeof(readonlyCommandTable)/sizeof(struct redisCommand);
+    int numcommands = sizeof(redisCommandTable)/sizeof(struct redisCommand);
 
     for (j = 0; j < numcommands; j++) {
-        struct redisCommand *c = readonlyCommandTable+j;
+        struct redisCommand *c = redisCommandTable+j;
         int retval;
 
         retval = dictAdd(server.commands, sdsnew(c->name), c);
@@ -947,6 +947,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;
+
+        c->microseconds = 0;
+        c->calls = 0;
+    }
+}
+
 /* ====================== Commands lookup and execution ===================== */
 
 struct redisCommand *lookupCommand(sds name) {
@@ -1405,13 +1417,15 @@ sds genRedisInfoString(char *section) {
     if (allsections || !strcasecmp(section,"commandstats")) {
         if (sections++) info = sdscat(info,"\r\n");
         info = sdscatprintf(info, "# Commandstats\r\n");
-        numcommands = sizeof(readonlyCommandTable)/sizeof(struct redisCommand);
+        numcommands = sizeof(redisCommandTable)/sizeof(struct redisCommand);
         for (j = 0; j < numcommands; j++) {
-            struct redisCommand *c = readonlyCommandTable+j;
+            struct redisCommand *c = redisCommandTable+j;
 
-            if (!c->microseconds) continue;
-            info = sdscatprintf(info,"cmdstat_%s:calls=%lld,usec=%lld\r\n",
-                c->name, c->calls, c->microseconds);
+            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));
         }
     }
 
index 8b92dd28b79a5014c13738fe56794428c86107dc..5ae9cc1c14e009125220de47674ec2afdf811118 100644 (file)
@@ -800,6 +800,7 @@ void updateDictResizePolicy(void);
 int htNeedsResize(dict *dict);
 void oom(const char *msg);
 void populateCommandTable(void);
+void resetCommandTableStats(void);
 
 /* Disk store */
 int dsOpen(void);