diff --git a/daemon/remote.c b/daemon/remote.c index b7de708fc..a54644c66 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -1048,6 +1048,14 @@ do_flush_type(SSL* ssl, struct worker* worker, char* arg) send_ok(ssl); } +/** flush statistics */ +static void +do_flush_stats(SSL* ssl, struct worker* worker) +{ + worker_stats_clear(worker); + send_ok(ssl); +} + /** * Local info for deletion functions */ @@ -1391,6 +1399,12 @@ execute_cmd(struct daemon_remote* rc, SSL* ssl, char* cmd, } else if(strncmp(p, "load_cache", 10) == 0) { if(load_cache(ssl, worker)) send_ok(ssl); return; + } else if(strncmp(p, "flush_stats", 11) == 0) { + /* must always distribute this cmd */ + if(rc) + distribute_cmd(rc, ssl, cmd); + do_flush_stats(ssl, worker); + return; } else if(strncmp(p, "lookup", 6) == 0) { do_lookup(ssl, worker, skipwhite(p+6)); return; diff --git a/daemon/stats.c b/daemon/stats.c index 5d88ec9fc..465a57acf 100644 --- a/daemon/stats.c +++ b/daemon/stats.c @@ -144,9 +144,7 @@ server_stats_compile(struct worker* worker, struct stats_info* s) s->svr.rrset_bogus = get_rrset_bogus(worker); if(!worker->env.cfg->stat_cumulative) { - server_stats_init(&worker->stats, worker->env.cfg); - mesh_stats_clear(worker->env.mesh); - worker->back->unwanted_replies = 0; + worker_stats_clear(worker); } } diff --git a/daemon/worker.c b/daemon/worker.c index 553809c04..e87943f49 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -344,12 +344,10 @@ worker_handle_control_cmd(struct tube* ATTR_UNUSED(tube), uint8_t* msg, verbose(VERB_ALGO, "got control cmd stats"); server_stats_reply(worker); break; -#ifdef THREADS_DISABLED case worker_cmd_remote: verbose(VERB_ALGO, "got control cmd remote"); daemon_remote_exec(worker); break; -#endif default: log_err("bad command %d", (int)cmd); break; @@ -964,9 +962,7 @@ void worker_stat_timer_cb(void* arg) mesh_stats(worker->env.mesh, "mesh has"); worker_mem_report(worker, NULL); if(!worker->daemon->cfg->stat_cumulative) { - server_stats_init(&worker->stats, worker->env.cfg); - mesh_stats_clear(worker->env.mesh); - worker->back->unwanted_replies = 0; + worker_stats_clear(worker); } /* start next timer */ worker_restart_timer(worker); @@ -1221,6 +1217,13 @@ worker_alloc_cleanup(void* arg) slabhash_clear(worker->env.msg_cache); } +void worker_stats_clear(struct worker* worker) +{ + server_stats_init(&worker->stats, worker->env.cfg); + mesh_stats_clear(worker->env.mesh); + worker->back->unwanted_replies = 0; +} + /* --- fake callbacks for fptr_wlist to work --- */ int libworker_send_packet(ldns_buffer* ATTR_UNUSED(pkt), struct sockaddr_storage* ATTR_UNUSED(addr), diff --git a/daemon/worker.h b/daemon/worker.h index 84b43980b..14c2abcb7 100644 --- a/daemon/worker.h +++ b/daemon/worker.h @@ -228,6 +228,12 @@ int worker_handle_service_reply(struct comm_point* c, void* arg, int error, /** cleanup the cache to remove all rrset IDs from it, arg is worker */ void worker_alloc_cleanup(void* arg); +/** + * Init worker stats - includes server_stats_init, outside network and mesh. + * @param worker: the worker to init + */ +void worker_stats_clear(struct worker* worker); + /** statistics timer callback handler */ void worker_stat_timer_cb(void* arg); diff --git a/doc/Changelog b/doc/Changelog index 849551f0e..16dd3d0fe 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,5 +1,7 @@ 12 February 2009: Wouter - call setusercontext if available (on BSD). + - small refactor of stats clearing. + - #227: flush_stats feature for unbound-control. 10 February 2009: Wouter - keys with rfc5011 REVOKE flag are skipped and not considered when diff --git a/doc/TODO b/doc/TODO index 2729d7298..adb4c722f 100644 --- a/doc/TODO +++ b/doc/TODO @@ -59,8 +59,6 @@ o local-zone directive with authority service, full authority server o remote control read ssl information while priviledged. o infra and lame cache: easier size config (in Mb), show usage in graphs. -o #226: unbound_control dump_requestlist -o #227: unbound_control flush_stats o unbound_control get_stats_noreset o unbound_control forward [addr {addr}] | [off] o config entry to denote that a zone is to be treated as unsigned (even if diff --git a/doc/unbound-control.8.in b/doc/unbound-control.8.in index 578312b4e..6c69a14f7 100644 --- a/doc/unbound-control.8.in +++ b/doc/unbound-control.8.in @@ -116,6 +116,9 @@ Remove all information at or below the name from the cache. The rrsets and key entries are removed so that new lookups will be performed. This needs to walk and inspect the entire cache, and is a slow operation. .TP +.B flush_stats +Reset statistics to zero. +.TP .B dump_requestlist Show what is worked on. Prints all queries that the server is currently working on. Prints the time that users have been waiting. For internal diff --git a/smallapp/unbound-control.c b/smallapp/unbound-control.c index ea18903e1..fe11743bc 100644 --- a/smallapp/unbound-control.c +++ b/smallapp/unbound-control.c @@ -78,6 +78,7 @@ usage() printf(" flush_type [name] [type] flush name, type from cache\n"); printf(" flush_zone [name] flush everything at or under name\n"); printf(" from rr and dnssec caches\n"); + printf(" flush_stats flush statistics, make zero\n"); printf(" dump_requestlist show what is worked on\n"); printf("Version %s\n", PACKAGE_VERSION); printf("BSD licensed, see LICENSE in source package for details.\n");