Allow "dundi flush" to flush statistics too
authorMark Spencer <markster@digium.com>
Sun, 24 Oct 2004 06:04:48 +0000 (06:04 +0000)
committerMark Spencer <markster@digium.com>
Sun, 24 Oct 2004 06:04:48 +0000 (06:04 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@4077 65c4cc65-6c06-0410-ace0-fbb531ad65f3

pbx/pbx_dundi.c

index 43f673d..407d969 100755 (executable)
@@ -1972,10 +1972,36 @@ static int dundi_do_store_history(int fd, int argc, char *argv[])
 
 static int dundi_flush(int fd, int argc, char *argv[])
 {
-       if (argc != 2)
+       int stats=0;
+       if ((argc < 2) || (argc > 3))
                return RESULT_SHOWUSAGE;
-       ast_db_deltree("dundi/cache", NULL);
-       ast_cli(fd, "DUNDi Cache Flushed\n");
+       if (argc > 2) {
+               if (!strcasecmp(argv[2], "stats"))
+                       stats = 1;
+               else
+                       return RESULT_SHOWUSAGE;
+       }
+       if (stats) {
+               /* Flush statistics */
+               struct dundi_peer *p;
+               int x;
+               ast_mutex_lock(&peerlock);
+               p = peers;
+               while(p) {
+                       for (x=0;x<DUNDI_TIMING_HISTORY;x++) {
+                               if (p->lookups[x])
+                                       free(p->lookups[x]);
+                               p->lookups[x] = NULL;
+                               p->lookuptimes[x] = 0;
+                       }
+                       p->avgms = 0;
+                       p = p->next;
+               }
+               ast_mutex_unlock(&peerlock);
+       } else {
+               ast_db_deltree("dundi/cache", NULL);
+               ast_cli(fd, "DUNDi Cache Flushed\n");
+       }
        return RESULT_SUCCESS;
 }
 
@@ -2410,8 +2436,10 @@ static char query_usage[] =
 "e164 if none is specified).\n";
 
 static char flush_usage[] =
-"Usage: dundi flush\n"
-"       Flushes DUNDi answer cache, used primarily for debug.\n";
+"Usage: dundi flush [stats]\n"
+"       Flushes DUNDi answer cache, used primarily for debug.  If\n"
+"'stats' is present, clears timer statistics instead of normal\n"
+"operation.\n";
 
 static struct ast_cli_entry  cli_debug =
        { { "dundi", "debug", NULL }, dundi_do_debug, "Enable DUNDi debugging", debug_usage };