diff --git a/CHANGES b/CHANGES index 9a44debdfa..c71a070831 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +2537. [func] Added more statistics counters including those on socket + I/O events and query RTT histograms. [RT #18802] + 2536. [cleanup] Silence some warnings when -Werror=format-security is specified. [RT #19083] diff --git a/bin/named/bind9.xsl b/bin/named/bind9.xsl index b6562b8e39..f6577f3629 100644 --- a/bin/named/bind9.xsl +++ b/bin/named/bind9.xsl @@ -15,7 +15,7 @@ - PERFORMANCE OF THIS SOFTWARE. --> - + +
+

Socket I/O Statistics

+ +
+
+
+
+
+
+
+
diff --git a/bin/named/bind9.xsl.h b/bin/named/bind9.xsl.h index d9dc624fb8..024e7811b1 100644 --- a/bin/named/bind9.xsl.h +++ b/bin/named/bind9.xsl.h @@ -1,6 +1,6 @@ /* * Generated by convertxsl.pl 1.14 2008/07/17 23:43:26 jinmei Exp - * From bind9.xsl 1.19 2008/07/17 23:43:26 jinmei Exp + * From bind9.xsl 1.19.50.1 2008/10/30 05:56:18 jinmei Exp */ static char xslmsg[] = "\n" @@ -20,7 +20,7 @@ static char xslmsg[] = " - PERFORMANCE OF THIS SOFTWARE.\n" "-->\n" "\n" - "\n" + "\n" "\n" "\n" "\n" + "
\n" + "

Socket I/O Statistics

\n" + " \n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "\n" "
\n" "\n" " \n" diff --git a/bin/named/client.c b/bin/named/client.c index 32b1127725..71b8c52fb9 100644 --- a/bin/named/client.c +++ b/bin/named/client.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: client.c,v 1.261 2009/01/17 23:47:42 tbox Exp $ */ +/* $Id: client.c,v 1.262 2009/01/27 22:29:58 jinmei Exp $ */ #include @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -1018,23 +1019,22 @@ ns_client_send(ns_client_t *client) { result = client_sendpkg(client, &buffer); /* update statistics (XXXJT: is it okay to access message->xxxkey?) */ - dns_generalstats_increment(ns_g_server->nsstats, - dns_nsstatscounter_response); + isc_stats_increment(ns_g_server->nsstats, dns_nsstatscounter_response); if (opt_included) { - dns_generalstats_increment(ns_g_server->nsstats, - dns_nsstatscounter_edns0out); + isc_stats_increment(ns_g_server->nsstats, + dns_nsstatscounter_edns0out); } if (client->message->tsigkey != NULL) { - dns_generalstats_increment(ns_g_server->nsstats, - dns_nsstatscounter_tsigout); + isc_stats_increment(ns_g_server->nsstats, + dns_nsstatscounter_tsigout); } if (client->message->sig0key != NULL) { - dns_generalstats_increment(ns_g_server->nsstats, - dns_nsstatscounter_sig0out); + isc_stats_increment(ns_g_server->nsstats, + dns_nsstatscounter_sig0out); } if ((client->message->flags & DNS_MESSAGEFLAG_TC) != 0) - dns_generalstats_increment(ns_g_server->nsstats, - dns_nsstatscounter_truncatedresp); + isc_stats_increment(ns_g_server->nsstats, + dns_nsstatscounter_truncatedresp); if (result == ISC_R_SUCCESS) return; @@ -1514,15 +1514,15 @@ client_request(isc_task_t *task, isc_event_t *event) { * Update some statistics counters. Don't count responses. */ if (isc_sockaddr_pf(&client->peeraddr) == PF_INET) { - dns_generalstats_increment(ns_g_server->nsstats, - dns_nsstatscounter_requestv4); + isc_stats_increment(ns_g_server->nsstats, + dns_nsstatscounter_requestv4); } else { - dns_generalstats_increment(ns_g_server->nsstats, - dns_nsstatscounter_requestv6); + isc_stats_increment(ns_g_server->nsstats, + dns_nsstatscounter_requestv6); } if (TCP_CLIENT(client)) - dns_generalstats_increment(ns_g_server->nsstats, - dns_nsstatscounter_tcp); + isc_stats_increment(ns_g_server->nsstats, + dns_nsstatscounter_tcp); /* * It's a request. Parse it. @@ -1586,8 +1586,8 @@ client_request(isc_task_t *task, isc_event_t *event) { */ client->ednsversion = (opt->ttl & 0x00FF0000) >> 16; if (client->ednsversion > 0) { - dns_generalstats_increment(ns_g_server->nsstats, - dns_nsstatscounter_badednsver); + isc_stats_increment(ns_g_server->nsstats, + dns_nsstatscounter_badednsver); result = client_addopt(client); if (result == ISC_R_SUCCESS) result = DNS_R_BADVERS; @@ -1612,8 +1612,8 @@ client_request(isc_task_t *task, isc_event_t *event) { } } - dns_generalstats_increment(ns_g_server->nsstats, - dns_nsstatscounter_edns0in); + isc_stats_increment(ns_g_server->nsstats, + dns_nsstatscounter_edns0in); /* * Create an OPT for our reply. @@ -1762,11 +1762,11 @@ client_request(isc_task_t *task, isc_event_t *event) { if (result != ISC_R_NOTFOUND) { signame = NULL; if (dns_message_gettsig(client->message, &signame) != NULL) { - dns_generalstats_increment(ns_g_server->nsstats, - dns_nsstatscounter_tsigin); + isc_stats_increment(ns_g_server->nsstats, + dns_nsstatscounter_tsigin); } else { - dns_generalstats_increment(ns_g_server->nsstats, - dns_nsstatscounter_sig0in); + isc_stats_increment(ns_g_server->nsstats, + dns_nsstatscounter_sig0in); } } @@ -1790,8 +1790,8 @@ client_request(isc_task_t *task, isc_event_t *event) { isc_result_t tresult; /* There is a signature, but it is bad. */ - dns_generalstats_increment(ns_g_server->nsstats, - dns_nsstatscounter_invalidsig); + isc_stats_increment(ns_g_server->nsstats, + dns_nsstatscounter_invalidsig); signame = NULL; if (dns_message_gettsig(client->message, &signame) != NULL) { char namebuf[DNS_NAME_FORMATSIZE]; diff --git a/bin/named/include/named/server.h b/bin/named/include/named/server.h index 2c5f03379b..4d6a5d741a 100644 --- a/bin/named/include/named/server.h +++ b/bin/named/include/named/server.h @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: server.h,v 1.95 2009/01/09 23:47:45 tbox Exp $ */ +/* $Id: server.h,v 1.96 2009/01/27 22:29:58 jinmei Exp $ */ #ifndef NAMED_SERVER_H #define NAMED_SERVER_H 1 @@ -92,11 +92,12 @@ struct ns_server { isc_boolean_t log_queries; /*%< For BIND 8 compatibility */ ns_cachelist_t cachelist; /*%< Possibly shared caches */ - dns_stats_t * nsstats; /*%< Server statistics */ - dns_stats_t * rcvquerystats; /*% Incoming query statistics */ - dns_stats_t * opcodestats; /*%< Incoming message statistics */ - dns_stats_t * zonestats; /*% Zone management statistics */ - dns_stats_t * resolverstats; /*% Resolver statistics */ + isc_stats_t * nsstats; /*%< Server stats */ + dns_stats_t * rcvquerystats; /*% Incoming query stats */ + dns_stats_t * opcodestats; /*%< Incoming message stats */ + isc_stats_t * zonestats; /*% Zone management stats */ + isc_stats_t * resolverstats; /*% Resolver stats */ + isc_stats_t * sockstats; /*%< Socket stats */ ns_controls_t * controls; /*%< Control channels */ unsigned int dispatchgen; @@ -111,7 +112,7 @@ struct ns_server { #define NS_SERVER_VALID(s) ISC_MAGIC_VALID(s, NS_SERVER_MAGIC) /*% - * Server statistics counters. Used as dns_statscounter_t values. + * Server statistics counters. Used as isc_statscounter_t values. */ enum { dns_nsstatscounter_requestv4 = 0, diff --git a/bin/named/query.c b/bin/named/query.c index 2ff34809f3..80f148d66b 100644 --- a/bin/named/query.c +++ b/bin/named/query.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: query.c,v 1.318 2009/01/17 11:20:13 fdupont Exp $ */ +/* $Id: query.c,v 1.319 2009/01/27 22:29:58 jinmei Exp $ */ /*! \file */ @@ -23,9 +23,10 @@ #include -#include -#include #include +#include +#include +#include #include #include @@ -141,21 +142,21 @@ log_queryerror(ns_client_t *client, isc_result_t result, int line, int level); * Increment query statistics counters. */ static inline void -inc_stats(ns_client_t *client, dns_statscounter_t counter) { +inc_stats(ns_client_t *client, isc_statscounter_t counter) { dns_zone_t *zone = client->query.authzone; - dns_generalstats_increment(ns_g_server->nsstats, counter); + isc_stats_increment(ns_g_server->nsstats, counter); if (zone != NULL) { - dns_stats_t *zonestats = dns_zone_getrequeststats(zone); + isc_stats_t *zonestats = dns_zone_getrequeststats(zone); if (zonestats != NULL) - dns_generalstats_increment(zonestats, counter); + isc_stats_increment(zonestats, counter); } } static void query_send(ns_client_t *client) { - dns_statscounter_t counter; + isc_statscounter_t counter; if ((client->message->flags & DNS_MESSAGEFLAG_AA) == 0) inc_stats(client, dns_nsstatscounter_nonauthans); else diff --git a/bin/named/server.c b/bin/named/server.c index b7072612ae..0f2a5c3723 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: server.c,v 1.525 2009/01/17 11:22:01 fdupont Exp $ */ +/* $Id: server.c,v 1.526 2009/01/27 22:29:58 jinmei Exp $ */ /*! \file */ @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -973,18 +974,18 @@ check_dbtype(dns_zone_t **zonep, unsigned int dbtypec, const char **dbargv, static isc_result_t setquerystats(dns_zone_t *zone, isc_mem_t *mctx, isc_boolean_t on) { isc_result_t result; - dns_stats_t *zoneqrystats; + isc_stats_t *zoneqrystats; zoneqrystats = NULL; if (on) { - result = dns_generalstats_create(mctx, &zoneqrystats, - dns_nsstatscounter_max); + result = isc_stats_create(mctx, &zoneqrystats, + dns_nsstatscounter_max); if (result != ISC_R_SUCCESS) return (result); } dns_zone_setrequeststats(zone, zoneqrystats); if (zoneqrystats != NULL) - dns_stats_detach(&zoneqrystats); + isc_stats_detach(&zoneqrystats); return (ISC_R_SUCCESS); } @@ -1104,7 +1105,7 @@ configure_view(dns_view_t *view, const cfg_obj_t *config, isc_boolean_t rfc1918; isc_boolean_t empty_zones_enable; const cfg_obj_t *disablelist = NULL; - dns_stats_t *resstats = NULL; + isc_stats_t *resstats = NULL; dns_stats_t *resquerystats = NULL; ns_cache_t *nsc; isc_boolean_t zero_no_soattl; @@ -1473,8 +1474,8 @@ configure_view(dns_view_t *view, const cfg_obj_t *config, dispatch4, dispatch6)); if (resstats == NULL) { - CHECK(dns_generalstats_create(mctx, &resstats, - dns_resstatscounter_max)); + CHECK(isc_stats_create(mctx, &resstats, + dns_resstatscounter_max)); } dns_view_setresstats(view, resstats); if (resquerystats == NULL) @@ -2139,7 +2140,7 @@ configure_view(dns_view_t *view, const cfg_obj_t *config, if (dispatch6 != NULL) dns_dispatch_detach(&dispatch6); if (resstats != NULL) - dns_stats_detach(&resstats); + isc_stats_detach(&resstats); if (resquerystats != NULL) dns_stats_detach(&resquerystats); if (order != NULL) @@ -4098,6 +4099,11 @@ ns_server_create(isc_mem_t *mctx, ns_server_t **serverp) { server->opcodestats = NULL; server->zonestats = NULL; server->resolverstats = NULL; + server->sockstats = NULL; + CHECKFATAL(isc_stats_create(server->mctx, &server->sockstats, + isc_sockstatscounter_max), + "isc_stats_create"); + isc_socketmgr_setstats(ns_g_socketmgr, server->sockstats); server->dumpfile = isc_mem_strdup(server->mctx, "named_dump.db"); CHECKFATAL(server->dumpfile == NULL ? ISC_R_NOMEMORY : ISC_R_SUCCESS, @@ -4114,8 +4120,8 @@ ns_server_create(isc_mem_t *mctx, ns_server_t **serverp) { server->server_usehostname = ISC_FALSE; server->server_id = NULL; - CHECKFATAL(dns_generalstats_create(ns_g_mctx, &server->nsstats, - dns_nsstatscounter_max), + CHECKFATAL(isc_stats_create(ns_g_mctx, &server->nsstats, + dns_nsstatscounter_max), "dns_stats_create (server)"); CHECKFATAL(dns_rdatatypestats_create(ns_g_mctx, @@ -4125,12 +4131,12 @@ ns_server_create(isc_mem_t *mctx, ns_server_t **serverp) { CHECKFATAL(dns_opcodestats_create(ns_g_mctx, &server->opcodestats), "dns_stats_create (opcode)"); - CHECKFATAL(dns_generalstats_create(ns_g_mctx, &server->zonestats, - dns_zonestatscounter_max), + CHECKFATAL(isc_stats_create(ns_g_mctx, &server->zonestats, + dns_zonestatscounter_max), "dns_stats_create (zone)"); - CHECKFATAL(dns_generalstats_create(ns_g_mctx, &server->resolverstats, - dns_resstatscounter_max), + CHECKFATAL(isc_stats_create(ns_g_mctx, &server->resolverstats, + dns_resstatscounter_max), "dns_stats_create (resolver)"); server->flushonshutdown = ISC_FALSE; @@ -4157,11 +4163,12 @@ ns_server_destroy(ns_server_t **serverp) { ns_controls_destroy(&server->controls); - dns_stats_detach(&server->nsstats); + isc_stats_detach(&server->nsstats); dns_stats_detach(&server->rcvquerystats); dns_stats_detach(&server->opcodestats); - dns_stats_detach(&server->zonestats); - dns_stats_detach(&server->resolverstats); + isc_stats_detach(&server->zonestats); + isc_stats_detach(&server->resolverstats); + isc_stats_detach(&server->sockstats); isc_mem_free(server->mctx, server->statsfile); isc_mem_free(server->mctx, server->dumpfile); diff --git a/bin/named/statschannel.c b/bin/named/statschannel.c index edf53f5a94..553f66e47e 100644 --- a/bin/named/statschannel.c +++ b/bin/named/statschannel.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: statschannel.c,v 1.18 2009/01/17 11:23:46 fdupont Exp $ */ +/* $Id: statschannel.c,v 1.19 2009/01/27 22:29:58 jinmei Exp $ */ /*! \file */ @@ -26,11 +26,13 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -66,9 +68,9 @@ typedef struct stats_dumparg { statsformat_t type; void *arg; /* type dependent argument */ - const char *category; /* used for general statistics */ - const char **desc; /* used for general statistics */ int ncounters; /* used for general statistics */ + int *counterindices; /* used for general statistics */ + isc_uint64_t *countervalues; /* used for general statistics */ } stats_dumparg_t; static isc_once_t once = ISC_ONCE_INIT; @@ -81,16 +83,29 @@ static isc_once_t once = ISC_ONCE_INIT; static const char *nsstats_desc[dns_nsstatscounter_max]; static const char *resstats_desc[dns_resstatscounter_max]; static const char *zonestats_desc[dns_zonestatscounter_max]; +static const char *sockstats_desc[isc_sockstatscounter_max]; #ifdef HAVE_LIBXML2 static const char *nsstats_xmldesc[dns_nsstatscounter_max]; static const char *resstats_xmldesc[dns_resstatscounter_max]; static const char *zonestats_xmldesc[dns_zonestatscounter_max]; +static const char *sockstats_xmldesc[isc_sockstatscounter_max]; #else #define nsstats_xmldesc NULL #define resstats_xmldesc NULL #define zonestats_xmldesc NULL +#define sockstats_xmldesc NULL #endif /* HAVE_LIBXML2 */ +/*% + * Mapping arrays to represent statistics counters in the order of our + * preference, regardless of the order of counter indices. For example, + * nsstats_desc[nsstats_index[0]] will be the description that is shown first. + */ +static int nsstats_index[dns_nsstatscounter_max]; +static int resstats_index[dns_resstatscounter_max]; +static int zonestats_index[dns_zonestatscounter_max]; +static int sockstats_index[isc_sockstatscounter_max]; + static inline void set_desc(int counter, int maxcounter, const char *fdesc, const char **fdescs, const char *xdesc, const char **xdescs) @@ -121,115 +136,66 @@ init_desc(void) { memset(nsstats_xmldesc, 0, dns_nsstatscounter_max * sizeof(nsstats_xmldesc[0])); #endif - set_desc(dns_nsstatscounter_requestv4, dns_nsstatscounter_max, - "IPv4 requests received", nsstats_desc, - "Requestv4", nsstats_xmldesc); - set_desc(dns_nsstatscounter_requestv6, dns_nsstatscounter_max, - "IPv6 requests received", nsstats_desc, - "Requestv6", nsstats_xmldesc); - set_desc(dns_nsstatscounter_edns0in, dns_nsstatscounter_max, - "requests with EDNS(0) received", nsstats_desc, - "ReqEdns0", nsstats_xmldesc); - set_desc(dns_nsstatscounter_badednsver, dns_nsstatscounter_max, - "requests with unsupported EDNS version received", - nsstats_desc, - "ReqBadEDNSVer", nsstats_xmldesc); - set_desc(dns_nsstatscounter_tsigin, dns_nsstatscounter_max, - "requests with TSIG received", nsstats_desc, - "ReqTSIG", nsstats_xmldesc); - set_desc(dns_nsstatscounter_sig0in, dns_nsstatscounter_max, - "requests with SIG(0) received", nsstats_desc, - "ReqSIG0", nsstats_xmldesc); - set_desc(dns_nsstatscounter_invalidsig, dns_nsstatscounter_max, - "requests with invalid signature", nsstats_desc, - "ReqBadSIG", nsstats_xmldesc); - set_desc(dns_nsstatscounter_tcp, dns_nsstatscounter_max, - "TCP requests received", nsstats_desc, - "ReqTCP", nsstats_xmldesc); - set_desc(dns_nsstatscounter_authrej, dns_nsstatscounter_max, - "auth queries rejected", nsstats_desc, - "AuthQryRej", nsstats_xmldesc); - set_desc(dns_nsstatscounter_recurserej, dns_nsstatscounter_max, - "recursive queries rejected", nsstats_desc, - "RecQryRej", nsstats_xmldesc); - set_desc(dns_nsstatscounter_xfrrej, dns_nsstatscounter_max, - "transfer requests rejected", nsstats_desc, - "XfrRej", nsstats_xmldesc); - set_desc(dns_nsstatscounter_updaterej, dns_nsstatscounter_max, - "update requests rejected", nsstats_desc, - "UpdateRej", nsstats_xmldesc); - set_desc(dns_nsstatscounter_response, dns_nsstatscounter_max, - "responses sent", nsstats_desc, - "Response", nsstats_xmldesc); - set_desc(dns_nsstatscounter_truncatedresp, dns_nsstatscounter_max, - "truncated responses sent", nsstats_desc, - "TruncatedResp", nsstats_xmldesc); - set_desc(dns_nsstatscounter_edns0out, dns_nsstatscounter_max, - "responses with EDNS(0) sent", nsstats_desc, - "RespEDNS0", nsstats_xmldesc); - set_desc(dns_nsstatscounter_tsigout, dns_nsstatscounter_max, - "responses with TSIG sent", nsstats_desc, - "RespTSIG", nsstats_xmldesc); - set_desc(dns_nsstatscounter_sig0out, dns_nsstatscounter_max, - "responses with SIG(0) sent", nsstats_desc, - "RespSIG0", nsstats_xmldesc); - set_desc(dns_nsstatscounter_success, dns_nsstatscounter_max, - "queries resulted in successful answer", nsstats_desc, - "QrySuccess", nsstats_xmldesc); - set_desc(dns_nsstatscounter_authans, dns_nsstatscounter_max, - "queries resulted in authoritative answer", nsstats_desc, - "QryAuthAns", nsstats_xmldesc); - set_desc(dns_nsstatscounter_nonauthans, dns_nsstatscounter_max, - "queries resulted in non authoritative answer", nsstats_desc, - "QryNoauthAns", nsstats_xmldesc); - set_desc(dns_nsstatscounter_referral, dns_nsstatscounter_max, - "queries resulted in referral answer", nsstats_desc, - "QryReferral", nsstats_xmldesc); - set_desc(dns_nsstatscounter_nxrrset, dns_nsstatscounter_max, - "queries resulted in nxrrset", nsstats_desc, - "QryNxrrset", nsstats_xmldesc); - set_desc(dns_nsstatscounter_servfail, dns_nsstatscounter_max, - "queries resulted in SERVFAIL", nsstats_desc, - "QrySERVFAIL", nsstats_xmldesc); - set_desc(dns_nsstatscounter_formerr, dns_nsstatscounter_max, - "queries resulted in FORMERR", nsstats_desc, - "QryFORMERR", nsstats_xmldesc); - set_desc(dns_nsstatscounter_nxdomain, dns_nsstatscounter_max, - "queries resulted in NXDOMAIN", nsstats_desc, - "QryNXDOMAIN", nsstats_xmldesc); - set_desc(dns_nsstatscounter_recursion, dns_nsstatscounter_max, - "queries caused recursion", nsstats_desc, - "QryRecursion", nsstats_xmldesc); - set_desc(dns_nsstatscounter_duplicate, dns_nsstatscounter_max, - "duplicate queries received", nsstats_desc, - "QryDuplicate", nsstats_xmldesc); - set_desc(dns_nsstatscounter_dropped, dns_nsstatscounter_max, - "queries dropped", nsstats_desc, - "QryDropped", nsstats_xmldesc); - set_desc(dns_nsstatscounter_failure, dns_nsstatscounter_max, - "other query failures", nsstats_desc, - "QryFailure", nsstats_xmldesc); - set_desc(dns_nsstatscounter_xfrdone, dns_nsstatscounter_max, - "requested transfers completed", nsstats_desc, - "XfrReqDone", nsstats_xmldesc); - set_desc(dns_nsstatscounter_updatereqfwd, dns_nsstatscounter_max, - "update requests forwarded", nsstats_desc, - "UpdateReqFwd", nsstats_xmldesc); - set_desc(dns_nsstatscounter_updaterespfwd, dns_nsstatscounter_max, - "update responses forwarded", nsstats_desc, - "UpdateRespFwd", nsstats_xmldesc); - set_desc(dns_nsstatscounter_updatefwdfail, dns_nsstatscounter_max, - "update forward failed", nsstats_desc, - "UpdateFwdFail", nsstats_xmldesc); - set_desc(dns_nsstatscounter_updatedone, dns_nsstatscounter_max, - "updates completed", nsstats_desc, - "UpdateDone", nsstats_xmldesc); - set_desc(dns_nsstatscounter_updatefail, dns_nsstatscounter_max, - "updates failed", nsstats_desc, - "UpdateFail", nsstats_xmldesc); - set_desc(dns_nsstatscounter_updatebadprereq, dns_nsstatscounter_max, - "updates rejected due to prerequisite failure", nsstats_desc, - "UpdateBadPrereq", nsstats_xmldesc); + +#define SET_NSSTATDESC(counterid, desc, xmldesc) \ + do { \ + set_desc(dns_nsstatscounter_ ## counterid, \ + dns_nsstatscounter_max, \ + desc, nsstats_desc, xmldesc, nsstats_xmldesc); \ + nsstats_index[i++] = dns_nsstatscounter_ ## counterid; \ + } while (0) + + i = 0; + SET_NSSTATDESC(requestv4, "IPv4 requests received", "Requestv4"); + SET_NSSTATDESC(requestv6, "IPv6 requests received", "Requestv6"); + SET_NSSTATDESC(edns0in, "requests with EDNS(0) received", "ReqEdns0"); + SET_NSSTATDESC(badednsver, + "requests with unsupported EDNS version received", + "ReqBadEDNSVer"); + SET_NSSTATDESC(tsigin, "requests with TSIG received", "ReqTSIG"); + SET_NSSTATDESC(sig0in, "requests with SIG(0) received", "ReqSIG0"); + SET_NSSTATDESC(invalidsig, "requests with invalid signature", + "ReqBadSIG"); + SET_NSSTATDESC(tcp, "TCP requests received", "ReqTCP"); + SET_NSSTATDESC(authrej, "auth queries rejected", "AuthQryRej"); + SET_NSSTATDESC(recurserej, "recursive queries rejected", "RecQryRej"); + SET_NSSTATDESC(xfrrej, "transfer requests rejected", "XfrRej"); + SET_NSSTATDESC(updaterej, "update requests rejected", "UpdateRej"); + SET_NSSTATDESC(response, "responses sent", "Response"); + SET_NSSTATDESC(truncatedresp, "truncated responses sent", + "TruncatedResp"); + SET_NSSTATDESC(edns0out, "responses with EDNS(0) sent", "RespEDNS0"); + SET_NSSTATDESC(tsigout, "responses with TSIG sent", "RespTSIG"); + SET_NSSTATDESC(sig0out, "responses with SIG(0) sent", "RespSIG0"); + SET_NSSTATDESC(success, "queries resulted in successful answer", + "QrySuccess"); + SET_NSSTATDESC(authans, "queries resulted in authoritative answer", + "QryAuthAns"); + SET_NSSTATDESC(nonauthans, + "queries resulted in non authoritative answer", + "QryNoauthAns"); + SET_NSSTATDESC(referral, "queries resulted in referral answer", + "QryReferral"); + SET_NSSTATDESC(nxrrset, "queries resulted in nxrrset", "QryNxrrset"); + SET_NSSTATDESC(servfail, "queries resulted in SERVFAIL", "QrySERVFAIL"); + SET_NSSTATDESC(formerr, "queries resulted in FORMERR", "QryFORMERR"); + SET_NSSTATDESC(nxdomain, "queries resulted in NXDOMAIN", "QryNXDOMAIN"); + SET_NSSTATDESC(recursion, "queries caused recursion","QryRecursion"); + SET_NSSTATDESC(duplicate, "duplicate queries received", "QryDuplicate"); + SET_NSSTATDESC(dropped, "queries dropped", "QryDropped"); + SET_NSSTATDESC(failure, "other query failures", "QryFailure"); + SET_NSSTATDESC(xfrdone, "requested transfers completed", "XfrReqDone"); + SET_NSSTATDESC(updatereqfwd, "update requests forwarded", + "UpdateReqFwd"); + SET_NSSTATDESC(updaterespfwd, "update responses forwarded", + "UpdateRespFwd"); + SET_NSSTATDESC(updatefwdfail, "update forward failed", "UpdateFwdFail"); + SET_NSSTATDESC(updatedone, "updates completed", "UpdateDone"); + SET_NSSTATDESC(updatefail, "updates failed", "UpdateFail"); + SET_NSSTATDESC(updatebadprereq, + "updates rejected due to prerequisite failure", + "UpdateBadPrereq"); + INSIST(i == dns_nsstatscounter_max); /* Initialize resolver statistics */ memset(resstats_desc, 0, @@ -238,70 +204,69 @@ init_desc(void) { memset(resstats_xmldesc, 0, dns_resstatscounter_max * sizeof(resstats_xmldesc[0])); #endif - set_desc(dns_resstatscounter_queryv4, dns_resstatscounter_max, - "IPv4 queries sent", resstats_desc, - "Queryv4", resstats_xmldesc); - set_desc(dns_resstatscounter_queryv6, dns_resstatscounter_max, - "IPv6 queries sent", resstats_desc, - "Queryv6", resstats_xmldesc); - set_desc(dns_resstatscounter_responsev4, dns_resstatscounter_max, - "IPv4 responses received", resstats_desc, - "Responsev4", resstats_xmldesc); - set_desc(dns_resstatscounter_responsev6, dns_resstatscounter_max, - "IPv6 responses received", resstats_desc, - "Responsev6", resstats_xmldesc); - set_desc(dns_resstatscounter_nxdomain, dns_resstatscounter_max, - "NXDOMAIN received", resstats_desc, - "NXDOMAIN", resstats_xmldesc); - set_desc(dns_resstatscounter_servfail, dns_resstatscounter_max, - "SERVFAIL received", resstats_desc, - "SERVFAIL", resstats_xmldesc); - set_desc(dns_resstatscounter_formerr, dns_resstatscounter_max, - "FORMERR received", resstats_desc, - "FORMERR", resstats_xmldesc); - set_desc(dns_resstatscounter_othererror, dns_resstatscounter_max, - "other errors received", resstats_desc, - "OtherError", resstats_xmldesc); - set_desc(dns_resstatscounter_edns0fail, dns_resstatscounter_max, - "EDNS(0) query failures", resstats_desc, - "EDNS0Fail", resstats_xmldesc); - set_desc(dns_resstatscounter_mismatch, dns_resstatscounter_max, - "mismatch responses received", resstats_desc, - "Mismatch", resstats_xmldesc); - set_desc(dns_resstatscounter_truncated, dns_resstatscounter_max, - "truncated responses received", resstats_desc, - "Truncated", resstats_xmldesc); - set_desc(dns_resstatscounter_lame, dns_resstatscounter_max, - "lame delegations received", resstats_desc, - "Lame", resstats_xmldesc); - set_desc(dns_resstatscounter_retry, dns_resstatscounter_max, - "query retries", resstats_desc, - "Retry", resstats_xmldesc); - set_desc(dns_resstatscounter_gluefetchv4, dns_resstatscounter_max, - "IPv4 NS address fetches", resstats_desc, - "GlueFetchv4", resstats_xmldesc); - set_desc(dns_resstatscounter_gluefetchv6, dns_resstatscounter_max, - "IPv6 NS address fetches", resstats_desc, - "GlueFetchv6", resstats_xmldesc); - set_desc(dns_resstatscounter_gluefetchv4fail, dns_resstatscounter_max, - "IPv4 NS address fetch failed", resstats_desc, - "GlueFetchv4Fail", resstats_xmldesc); - set_desc(dns_resstatscounter_gluefetchv6fail, dns_resstatscounter_max, - "IPv6 NS address fetch failed", resstats_desc, - "GlueFetchv6Fail", resstats_xmldesc); - set_desc(dns_resstatscounter_val, dns_resstatscounter_max, - "DNSSEC validation attempted", resstats_desc, - "ValAttempt", resstats_xmldesc); - set_desc(dns_resstatscounter_valsuccess, dns_resstatscounter_max, - "DNSSEC validation succeeded", resstats_desc, - "ValOk", resstats_xmldesc); - set_desc(dns_resstatscounter_valnegsuccess, dns_resstatscounter_max, - "DNSSEC NX validation succeeded", resstats_desc, - "ValNegOk", resstats_xmldesc); - set_desc(dns_resstatscounter_valfail, dns_resstatscounter_max, - "DNSSEC validation failed", resstats_desc, - "ValFail", resstats_xmldesc); +#define SET_RESSTATDESC(counterid, desc, xmldesc) \ + do { \ + set_desc(dns_resstatscounter_ ## counterid, \ + dns_resstatscounter_max, \ + desc, resstats_desc, xmldesc, resstats_xmldesc); \ + resstats_index[i++] = dns_resstatscounter_ ## counterid; \ + } while (0) + + i = 0; + SET_RESSTATDESC(queryv4, "IPv4 queries sent", "Queryv4"); + SET_RESSTATDESC(queryv6, "IPv6 queries sent", "Queryv6"); + SET_RESSTATDESC(responsev4, "IPv4 responses received", "Responsev4"); + SET_RESSTATDESC(responsev6, "IPv6 responses received", "Responsev6"); + SET_RESSTATDESC(nxdomain, "NXDOMAIN received", "NXDOMAIN"); + SET_RESSTATDESC(servfail, "SERVFAIL received", "SERVFAIL"); + SET_RESSTATDESC(formerr, "FORMERR received", "FORMERR"); + SET_RESSTATDESC(othererror, "other errors received", "OtherError"); + SET_RESSTATDESC(edns0fail, "EDNS(0) query failures", "EDNS0Fail"); + SET_RESSTATDESC(mismatch, "mismatch responses received", "Mismatch"); + SET_RESSTATDESC(truncated, "truncated responses received", "Truncated"); + SET_RESSTATDESC(lame, "lame delegations received", "Lame"); + SET_RESSTATDESC(retry, "query retries", "Retry"); + SET_RESSTATDESC(dispabort, "queries aborted due to quota", + "QueryAbort"); + SET_RESSTATDESC(dispsockfail, "failures in opening query sockets", + "QuerySockFail"); + SET_RESSTATDESC(querytimeout, "query timeouts", "QueryTimeout"); + SET_RESSTATDESC(gluefetchv4, "IPv4 NS address fetches", "GlueFetchv4"); + SET_RESSTATDESC(gluefetchv6, "IPv6 NS address fetches", "GlueFetchv6"); + SET_RESSTATDESC(gluefetchv4fail, "IPv4 NS address fetch failed", + "GlueFetchv4Fail"); + SET_RESSTATDESC(gluefetchv6fail, "IPv6 NS address fetch failed", + "GlueFetchv6Fail"); + SET_RESSTATDESC(val, "DNSSEC validation attempted", "ValAttempt"); + SET_RESSTATDESC(valsuccess, "DNSSEC validation succeeded", "ValOk"); + SET_RESSTATDESC(valnegsuccess, "DNSSEC NX validation succeeded", + "ValNegOk"); + SET_RESSTATDESC(valfail, "DNSSEC validation failed", "ValFail"); + SET_RESSTATDESC(queryrtt0, "queries with RTT < " + DNS_RESOLVER_QRYRTTCLASS0STR "ms", + "QryRTT" DNS_RESOLVER_QRYRTTCLASS0STR); + SET_RESSTATDESC(queryrtt1, "queries with RTT " + DNS_RESOLVER_QRYRTTCLASS0STR "-" + DNS_RESOLVER_QRYRTTCLASS1STR "ms", + "QryRTT" DNS_RESOLVER_QRYRTTCLASS1STR); + SET_RESSTATDESC(queryrtt2, "queries with RTT " + DNS_RESOLVER_QRYRTTCLASS1STR "-" + DNS_RESOLVER_QRYRTTCLASS2STR "ms", + "QryRTT" DNS_RESOLVER_QRYRTTCLASS2STR); + SET_RESSTATDESC(queryrtt3, "queries with RTT " + DNS_RESOLVER_QRYRTTCLASS2STR "-" + DNS_RESOLVER_QRYRTTCLASS3STR "ms", + "QryRTT" DNS_RESOLVER_QRYRTTCLASS3STR); + SET_RESSTATDESC(queryrtt4, "queries with RTT " + DNS_RESOLVER_QRYRTTCLASS3STR "-" + DNS_RESOLVER_QRYRTTCLASS4STR "ms", + "QryRTT" DNS_RESOLVER_QRYRTTCLASS4STR); + SET_RESSTATDESC(queryrtt5, "queries with RTT > " + DNS_RESOLVER_QRYRTTCLASS4STR "ms", + "QryRTT" DNS_RESOLVER_QRYRTTCLASS4STR "+"); + INSIST(i == dns_resstatscounter_max); + /* Initialize zone statistics */ memset(zonestats_desc, 0, dns_zonestatscounter_max * sizeof(zonestats_desc[0])); @@ -309,45 +274,137 @@ init_desc(void) { memset(zonestats_xmldesc, 0, dns_zonestatscounter_max * sizeof(zonestats_xmldesc[0])); #endif - set_desc(dns_zonestatscounter_notifyoutv4, dns_zonestatscounter_max, - "IPv4 notifies sent", zonestats_desc, - "NotifyOutv4", zonestats_xmldesc); - set_desc(dns_zonestatscounter_notifyoutv6, dns_zonestatscounter_max, - "IPv6 notifies sent", zonestats_desc, - "NotifyOutv6", zonestats_xmldesc); - set_desc(dns_zonestatscounter_notifyinv4, dns_zonestatscounter_max, - "IPv4 notifies received", zonestats_desc, - "NotifyInv4", zonestats_xmldesc); - set_desc(dns_zonestatscounter_notifyinv6, dns_zonestatscounter_max, - "IPv6 notifies received", zonestats_desc, - "NotifyInv6", zonestats_xmldesc); - set_desc(dns_zonestatscounter_notifyrej, dns_zonestatscounter_max, - "notifies rejected", zonestats_desc, - "NotifyRej", zonestats_xmldesc); - set_desc(dns_zonestatscounter_soaoutv4, dns_zonestatscounter_max, - "IPv4 SOA queries sent", zonestats_desc, - "SOAOutv4", zonestats_xmldesc); - set_desc(dns_zonestatscounter_soaoutv6, dns_zonestatscounter_max, - "IPv6 SOA queries sent", zonestats_desc, - "SOAOutv6", zonestats_xmldesc); - set_desc(dns_zonestatscounter_axfrreqv4, dns_zonestatscounter_max, - "IPv4 AXFR requested", zonestats_desc, - "AXFRReqv4", zonestats_xmldesc); - set_desc(dns_zonestatscounter_axfrreqv6, dns_zonestatscounter_max, - "IPv6 AXFR requested", zonestats_desc, - "AXFRReqv6", zonestats_xmldesc); - set_desc(dns_zonestatscounter_ixfrreqv4, dns_zonestatscounter_max, - "IPv4 IXFR requested", zonestats_desc, - "IXFRReqv4", zonestats_xmldesc); - set_desc(dns_zonestatscounter_ixfrreqv6, dns_zonestatscounter_max, - "IPv6 IXFR requested", zonestats_desc, - "IXFRReqv6", zonestats_xmldesc); - set_desc(dns_zonestatscounter_xfrsuccess, dns_zonestatscounter_max, - "transfer requests succeeded", zonestats_desc, - "XfrSuccess", zonestats_xmldesc); - set_desc(dns_zonestatscounter_xfrfail, dns_zonestatscounter_max, - "transfer requests failed", zonestats_desc, - "XfrFail", zonestats_xmldesc); + +#define SET_ZONESTATDESC(counterid, desc, xmldesc) \ + do { \ + set_desc(dns_zonestatscounter_ ## counterid, \ + dns_zonestatscounter_max, \ + desc, zonestats_desc, xmldesc, zonestats_xmldesc); \ + zonestats_index[i++] = dns_zonestatscounter_ ## counterid; \ + } while (0) + + i = 0; + SET_ZONESTATDESC(notifyoutv4, "IPv4 notifies sent", "NotifyOutv4"); + SET_ZONESTATDESC(notifyoutv6, "IPv6 notifies sent", "NotifyOutv6"); + SET_ZONESTATDESC(notifyinv4, "IPv4 notifies received", "NotifyInv4"); + SET_ZONESTATDESC(notifyinv6, "IPv6 notifies received", "NotifyInv6"); + SET_ZONESTATDESC(notifyrej, "notifies rejected", "NotifyRej"); + SET_ZONESTATDESC(soaoutv4, "IPv4 SOA queries sent", "SOAOutv4"); + SET_ZONESTATDESC(soaoutv6, "IPv6 SOA queries sent", "SOAOutv6"); + SET_ZONESTATDESC(axfrreqv4, "IPv4 AXFR requested", "AXFRReqv4"); + SET_ZONESTATDESC(axfrreqv6, "IPv6 AXFR requested", "AXFRReqv6"); + SET_ZONESTATDESC(ixfrreqv4, "IPv4 IXFR requested", "IXFRReqv4"); + SET_ZONESTATDESC(ixfrreqv6, "IPv6 IXFR requested", "IXFRReqv6"); + SET_ZONESTATDESC(xfrsuccess, "transfer requests succeeded","XfrSuccess"); + SET_ZONESTATDESC(xfrfail, "transfer requests failed", "XfrFail"); + INSIST(i == dns_zonestatscounter_max); + + /* Initialize socket statistics */ + memset(sockstats_desc, 0, + isc_sockstatscounter_max * sizeof(sockstats_desc[0])); +#ifdef HAVE_LIBXML2 + memset(sockstats_xmldesc, 0, + isc_sockstatscounter_max * sizeof(sockstats_xmldesc[0])); +#endif + +#define SET_SOCKSTATDESC(counterid, desc, xmldesc) \ + do { \ + set_desc(isc_sockstatscounter_ ## counterid, \ + isc_sockstatscounter_max, \ + desc, sockstats_desc, xmldesc, sockstats_xmldesc); \ + sockstats_index[i++] = isc_sockstatscounter_ ## counterid; \ + } while (0) + + i = 0; + SET_SOCKSTATDESC(udp4open, "UDP/IPv4 sockets opened", "UDP4Open"); + SET_SOCKSTATDESC(udp6open, "UDP/IPv6 sockets opened", "UDP6Open"); + SET_SOCKSTATDESC(tcp4open, "TCP/IPv4 sockets opened", "TCP4Open"); + SET_SOCKSTATDESC(tcp6open, "TCP/IPv6 sockets opened", "TCP6Open"); + SET_SOCKSTATDESC(unixopen, "Unix domain sockets opened", "UnixOpen"); + SET_SOCKSTATDESC(udp4openfail, "UDP/IPv4 socket open failures", + "UDP4OpenFail"); + SET_SOCKSTATDESC(udp6openfail, "UDP/IPv6 socket open failures", + "UDP6OpenFail"); + SET_SOCKSTATDESC(tcp4openfail, "TCP/IPv4 socket open failures", + "TCP4OpenFail"); + SET_SOCKSTATDESC(tcp6openfail, "TCP/IPv6 socket open failures", + "TCP6OpenFail"); + SET_SOCKSTATDESC(unixopenfail, "Unix domain socket open failures", + "UnixOpenFail"); + SET_SOCKSTATDESC(udp4close, "UDP/IPv4 sockets closed", "UDP4Close"); + SET_SOCKSTATDESC(udp6close, "UDP/IPv6 sockets closed", "UDP6Close"); + SET_SOCKSTATDESC(tcp4close, "TCP/IPv4 sockets closed", "TCP4Close"); + SET_SOCKSTATDESC(tcp6close, "TCP/IPv6 sockets closed", "TCP6Close"); + SET_SOCKSTATDESC(unixclose, "Unix domain sockets closed", "UnixClose"); + SET_SOCKSTATDESC(fdwatchclose, "FDwatch sockets closed", + "FDWatchClose"); + SET_SOCKSTATDESC(udp4bindfail, "UDP/IPv4 socket bind failures", + "UDP4BindFail"); + SET_SOCKSTATDESC(udp6bindfail, "UDP/IPv6 socket bind failures", + "UDP6BindFail"); + SET_SOCKSTATDESC(tcp4bindfail, "TCP/IPv4 socket bind failures", + "TCP4BindFail"); + SET_SOCKSTATDESC(tcp6bindfail, "TCP/IPv6 socket bind failures", + "TCP6BindFail"); + SET_SOCKSTATDESC(unixbindfail, "Unix domain socket bind failures", + "UnixBindFail"); + SET_SOCKSTATDESC(fdwatchbindfail, "FDwatch socket bind failures", + "FdwatchBindFail"); + SET_SOCKSTATDESC(udp4connectfail, "UDP/IPv4 socket connect failures", + "UDP4ConnFail"); + SET_SOCKSTATDESC(udp6connectfail, "UDP/IPv6 socket connect failures", + "UDP6ConnFail"); + SET_SOCKSTATDESC(tcp4connectfail, "TCP/IPv4 socket connect failures", + "TCP4ConnFail"); + SET_SOCKSTATDESC(tcp6connectfail, "TCP/IPv6 socket connect failures", + "TCP6ConnFail"); + SET_SOCKSTATDESC(unixconnectfail, "Unix domain socket connect failures", + "UnixConnFail"); + SET_SOCKSTATDESC(fdwatchconnectfail, "FDwatch socket connect failures", + "FDwatchConnFail"); + SET_SOCKSTATDESC(udp4connect, "UDP/IPv4 connections established", + "UDP4Conn"); + SET_SOCKSTATDESC(udp6connect, "UDP/IPv6 connections established", + "UDP6Conn"); + SET_SOCKSTATDESC(tcp4connect, "TCP/IPv4 connections established", + "TCP4Conn"); + SET_SOCKSTATDESC(tcp6connect, "TCP/IPv6 connections established", + "TCP6Conn"); + SET_SOCKSTATDESC(unixconnect, "Unix domain connections established", + "UnixConn"); + SET_SOCKSTATDESC(fdwatchconnect, + "FDwatch domain connections established", + "FDwatchConn"); + SET_SOCKSTATDESC(tcp4acceptfail, "TCP/IPv4 connection accept failures", + "TCP4AcceptFail"); + SET_SOCKSTATDESC(tcp6acceptfail, "TCP/IPv6 connection accept failures", + "TCP6AcceptFail"); + SET_SOCKSTATDESC(unixacceptfail, + "Unix domain connection accept failures", + "UnixAcceptFail"); + SET_SOCKSTATDESC(tcp4accept, "TCP/IPv4 connections accepted", + "TCP4Accept"); + SET_SOCKSTATDESC(tcp6accept, "TCP/IPv6 connections accepted", + "TCP6Accept"); + SET_SOCKSTATDESC(unixaccept, "Unix domain connections accepted", + "UnixAccept"); + SET_SOCKSTATDESC(udp4sendfail, "UDP/IPv4 send errors", "UDP4SendErr"); + SET_SOCKSTATDESC(udp6sendfail, "UDP/IPv6 send errors", "UDP6SendErr"); + SET_SOCKSTATDESC(tcp4sendfail, "TCP/IPv4 send errors", "TCP4SendErr"); + SET_SOCKSTATDESC(tcp6sendfail, "TCP/IPv6 send errors", "TCP6SendErr"); + SET_SOCKSTATDESC(unixsendfail, "Unix domain send errors", + "UnixSendErr"); + SET_SOCKSTATDESC(fdwatchsendfail, "FDwatch send errors", + "FDwatchSendErr"); + SET_SOCKSTATDESC(udp4recvfail, "UDP/IPv4 recv errors", "UDP4RecvErr"); + SET_SOCKSTATDESC(udp6recvfail, "UDP/IPv6 recv errors", "UDP6RecvErr"); + SET_SOCKSTATDESC(tcp4recvfail, "TCP/IPv4 recv errors", "TCP4RecvErr"); + SET_SOCKSTATDESC(tcp6recvfail, "TCP/IPv6 recv errors", "TCP6RecvErr"); + SET_SOCKSTATDESC(unixrecvfail, "Unix domain recv errors", + "UnixRecvErr"); + SET_SOCKSTATDESC(fdwatchrecvfail, "FDwatch recv errors", + "FDwatchRecvErr"); + INSIST(i == isc_sockstatscounter_max); /* Sanity check */ for (i = 0; i < dns_nsstatscounter_max; i++) @@ -356,6 +413,8 @@ init_desc(void) { INSIST(resstats_desc[i] != NULL); for (i = 0; i < dns_zonestatscounter_max; i++) INSIST(zonestats_desc[i] != NULL); + for (i = 0; i < isc_sockstatscounter_max; i++) + INSIST(sockstats_desc[i] != NULL); #ifdef HAVE_LIBXML2 for (i = 0; i < dns_nsstatscounter_max; i++) INSIST(nsstats_xmldesc[i] != NULL); @@ -363,6 +422,8 @@ init_desc(void) { INSIST(resstats_xmldesc[i] != NULL); for (i = 0; i < dns_zonestatscounter_max; i++) INSIST(zonestats_xmldesc[i] != NULL); + for (i = 0; i < isc_sockstatscounter_max; i++) + INSIST(sockstats_xmldesc[i] != NULL); #endif } @@ -370,48 +431,76 @@ init_desc(void) { * Dump callback functions. */ static void -generalstat_dump(dns_statscounter_t counter, isc_uint64_t val, void *arg) { +generalstat_dump(isc_statscounter_t counter, isc_uint64_t val, void *arg) { stats_dumparg_t *dumparg = arg; + + REQUIRE(counter < dumparg->ncounters); + dumparg->countervalues[counter] = val; +} + +static void +dump_counters(isc_stats_t *stats, statsformat_t type, void *arg, + const char *category, const char **desc, int ncounters, + int *indices, isc_uint64_t *values, int options) +{ + int i, index; + isc_uint64_t value; + stats_dumparg_t dumparg; FILE *fp; #ifdef HAVE_LIBXML2 xmlTextWriterPtr writer; #endif - REQUIRE(counter < dumparg->ncounters); + dumparg.type = type; + dumparg.ncounters = ncounters; + dumparg.counterindices = indices; + dumparg.countervalues = values; - switch (dumparg->type) { - case statsformat_file: - fp = dumparg->arg; - fprintf(fp, "%20" ISC_PRINT_QUADFORMAT "u %s\n", val, - dumparg->desc[counter]); - break; - case statsformat_xml: + memset(values, 0, sizeof(values[0]) * ncounters); + isc_stats_dump(stats, generalstat_dump, &dumparg, options); + + for (i = 0; i < ncounters; i++) { + index = indices[i]; + value = values[index]; + + if (value == 0 && (options & ISC_STATSDUMP_VERBOSE) == 0) + continue; + + switch (dumparg.type) { + case statsformat_file: + fp = arg; + fprintf(fp, "%20" ISC_PRINT_QUADFORMAT "u %s\n", + value, desc[index]); + break; + case statsformat_xml: #ifdef HAVE_LIBXML2 - writer = dumparg->arg; + writer = arg; - if (dumparg->category != NULL) { - xmlTextWriterStartElement(writer, - ISC_XMLCHAR - dumparg->category); - xmlTextWriterStartElement(writer, ISC_XMLCHAR "name"); - xmlTextWriterWriteString(writer, ISC_XMLCHAR - dumparg->desc[counter]); - xmlTextWriterEndElement(writer); /* name */ + if (category != NULL) { + xmlTextWriterStartElement(writer, + ISC_XMLCHAR + category); + xmlTextWriterStartElement(writer, + ISC_XMLCHAR "name"); + xmlTextWriterWriteString(writer, ISC_XMLCHAR + desc[index]); + xmlTextWriterEndElement(writer); /* name */ - xmlTextWriterStartElement(writer, ISC_XMLCHAR - "counter"); - } else { - xmlTextWriterStartElement(writer, ISC_XMLCHAR - dumparg->desc[counter]); - } - xmlTextWriterWriteFormatString(writer, - "%" ISC_PRINT_QUADFORMAT "u", - val); - xmlTextWriterEndElement(writer); /* counter */ - if (dumparg->category != NULL) - xmlTextWriterEndElement(writer); /* category */ + xmlTextWriterStartElement(writer, ISC_XMLCHAR + "counter"); + } else { + xmlTextWriterStartElement(writer, ISC_XMLCHAR + desc[index]); + } + xmlTextWriterWriteFormatString(writer, + "%" ISC_PRINT_QUADFORMAT + "u", value); + xmlTextWriterEndElement(writer); /* counter */ + if (category != NULL) + xmlTextWriterEndElement(writer); /* category */ #endif - break; + break; + } } } @@ -569,8 +658,8 @@ zone_xmlrender(dns_zone_t *zone, void *arg) { dns_rdataclass_t rdclass; isc_uint32_t serial; xmlTextWriterPtr writer = arg; - stats_dumparg_t dumparg; - dns_stats_t *zonestats; + isc_stats_t *zonestats; + isc_uint64_t nsstat_values[dns_nsstatscounter_max]; xmlTextWriterStartElement(writer, ISC_XMLCHAR "zone"); @@ -590,17 +679,13 @@ zone_xmlrender(dns_zone_t *zone, void *arg) { xmlTextWriterWriteFormatString(writer, "%u", serial); xmlTextWriterEndElement(writer); - dumparg.type = statsformat_xml; - dumparg.arg = writer; - dumparg.category = NULL; - dumparg.desc = nsstats_xmldesc; - dumparg.ncounters = dns_nsstatscounter_max; - zonestats = dns_zone_getrequeststats(zone); if (zonestats != NULL) { xmlTextWriterStartElement(writer, ISC_XMLCHAR "counters"); - dns_generalstats_dump(zonestats, generalstat_dump, - &dumparg, DNS_STATSDUMP_VERBOSE); + dump_counters(zonestats, statsformat_xml, writer, NULL, + nsstats_xmldesc, dns_nsstatscounter_max, + nsstats_index, nsstat_values, + ISC_STATSDUMP_VERBOSE); xmlTextWriterEndElement(writer); /* counters */ } @@ -620,6 +705,10 @@ generatexml(ns_server_t *server, int *buflen, xmlChar **buf) { dns_view_t *view; stats_dumparg_t dumparg; dns_stats_t *cachestats; + isc_uint64_t nsstat_values[dns_nsstatscounter_max]; + isc_uint64_t resstat_values[dns_resstatscounter_max]; + isc_uint64_t zonestat_values[dns_zonestatscounter_max]; + isc_uint64_t sockstat_values[isc_sockstatscounter_max]; isc_time_now(&now); isc_time_formatISO8601(&ns_g_boottime, boottime, sizeof boottime); @@ -666,11 +755,10 @@ generatexml(ns_server_t *server, int *buflen, xmlChar **buf) { } if (view->resstats != NULL) { - dumparg.ncounters = dns_resstatscounter_max; - dumparg.category = "resstat"; - dumparg.desc = resstats_xmldesc; - dns_generalstats_dump(view->resstats, generalstat_dump, - &dumparg, DNS_STATSDUMP_VERBOSE); + dump_counters(view->resstats, statsformat_xml, writer, + "resstat", resstats_xmldesc, + dns_resstatscounter_max, resstats_index, + resstat_values, ISC_STATSDUMP_VERBOSE); } cachestats = dns_db_getrrsetstats(view->cachedb); @@ -718,27 +806,25 @@ generatexml(ns_server_t *server, int *buflen, xmlChar **buf) { &dumparg, 0); xmlTextWriterEndElement(writer); /* queries-in */ - dumparg.category = "nsstat"; - dumparg.desc = nsstats_xmldesc; - dumparg.ncounters = dns_nsstatscounter_max; - dns_generalstats_dump(server->nsstats, generalstat_dump, &dumparg, - DNS_STATSDUMP_VERBOSE); + dump_counters(server->nsstats, statsformat_xml, writer, + "nsstat", nsstats_xmldesc, dns_nsstatscounter_max, + nsstats_index, nsstat_values, ISC_STATSDUMP_VERBOSE); - dumparg.category = "zonestat"; - dumparg.desc = zonestats_xmldesc; - dumparg.ncounters = dns_zonestatscounter_max; - dns_generalstats_dump(server->zonestats, generalstat_dump, &dumparg, - DNS_STATSDUMP_VERBOSE); + dump_counters(server->zonestats, statsformat_xml, writer, "zonestat", + zonestats_xmldesc, dns_zonestatscounter_max, + zonestats_index, zonestat_values, ISC_STATSDUMP_VERBOSE); /* * Most of the common resolver statistics entries are 0, so we don't * use the verbose dump here. */ - dumparg.category = "resstat"; - dumparg.ncounters = dns_resstatscounter_max; - dumparg.desc = resstats_xmldesc; - dns_generalstats_dump(server->resolverstats, generalstat_dump, - &dumparg, 0); + dump_counters(server->resolverstats, statsformat_xml, writer, "resstat", + resstats_xmldesc, dns_resstatscounter_max, resstats_index, + resstat_values, 0); + + dump_counters(server->sockstats, statsformat_xml, writer, "sockstat", + sockstats_xmldesc, isc_sockstatscounter_max, + sockstats_index, sockstat_values, ISC_STATSDUMP_VERBOSE); xmlTextWriterEndElement(writer); /* server */ @@ -1153,13 +1239,16 @@ ns_stats_dump(ns_server_t *server, FILE *fp) { dns_view_t *view; dns_zone_t *zone, *next; stats_dumparg_t dumparg; + isc_uint64_t nsstat_values[dns_nsstatscounter_max]; + isc_uint64_t resstat_values[dns_resstatscounter_max]; + isc_uint64_t zonestat_values[dns_zonestatscounter_max]; + isc_uint64_t sockstat_values[isc_sockstatscounter_max]; RUNTIME_CHECK(isc_once_do(&once, init_desc) == ISC_R_SUCCESS); /* Set common fields */ dumparg.type = statsformat_file; dumparg.arg = fp; - dumparg.category = NULL; /* unused */ isc_stdtime_get(&now); fprintf(fp, "+++ Statistics Dump +++ (%lu)\n", (unsigned long)now); @@ -1186,20 +1275,20 @@ ns_stats_dump(ns_server_t *server, FILE *fp) { } fprintf(fp, "++ Name Server Statistics ++\n"); - dumparg.desc = nsstats_desc; - dumparg.ncounters = dns_nsstatscounter_max; - dns_generalstats_dump(server->nsstats, generalstat_dump, &dumparg, 0); + dump_counters(server->nsstats, statsformat_file, fp, NULL, + nsstats_desc, dns_nsstatscounter_max, nsstats_index, + nsstat_values, 0); + fprintf(fp, "++ Zone Maintenance Statistics ++\n"); - dumparg.desc = zonestats_desc; - dumparg.ncounters = dns_zonestatscounter_max; - dns_generalstats_dump(server->zonestats, generalstat_dump, &dumparg, 0); + dump_counters(server->zonestats, statsformat_file, fp, NULL, + zonestats_desc, dns_zonestatscounter_max, + zonestats_index, zonestat_values, 0); fprintf(fp, "++ Resolver Statistics ++\n"); fprintf(fp, "[Common]\n"); - dumparg.desc = resstats_desc; - dumparg.ncounters = dns_resstatscounter_max; - dns_generalstats_dump(server->resolverstats, generalstat_dump, &dumparg, - 0); + dump_counters(server->resolverstats, statsformat_file, fp, NULL, + resstats_desc, dns_resstatscounter_max, resstats_index, + resstat_values, 0); for (view = ISC_LIST_HEAD(server->viewlist); view != NULL; view = ISC_LIST_NEXT(view, link)) { @@ -1209,8 +1298,9 @@ ns_stats_dump(ns_server_t *server, FILE *fp) { fprintf(fp, "[View: default]\n"); else fprintf(fp, "[View: %s]\n", view->name); - dns_generalstats_dump(view->resstats, generalstat_dump, - &dumparg, 0); + dump_counters(view->resstats, statsformat_file, fp, NULL, + resstats_desc, dns_resstatscounter_max, + resstats_index, resstat_values, 0); } fprintf(fp, "++ Cache DB RRsets ++\n"); @@ -1238,13 +1328,18 @@ ns_stats_dump(ns_server_t *server, FILE *fp) { 0); } + fprintf(fp, "++ Socket I/O Statistics ++\n"); + dump_counters(server->sockstats, statsformat_file, fp, NULL, + sockstats_desc, isc_sockstatscounter_max, sockstats_index, + sockstat_values, 0); + fprintf(fp, "++ Per Zone Query Statistics ++\n"); zone = NULL; for (result = dns_zone_first(server->zonemgr, &zone); result == ISC_R_SUCCESS; next = NULL, result = dns_zone_next(zone, &next), zone = next) { - dns_stats_t *zonestats = dns_zone_getrequeststats(zone); + isc_stats_t *zonestats = dns_zone_getrequeststats(zone); if (zonestats != NULL) { char zonename[DNS_NAME_FORMATSIZE]; @@ -1257,10 +1352,9 @@ ns_stats_dump(ns_server_t *server, FILE *fp) { fprintf(fp, " (view: %s)", view->name); fprintf(fp, "]\n"); - dumparg.desc = nsstats_desc; - dumparg.ncounters = dns_nsstatscounter_max; - dns_generalstats_dump(zonestats, generalstat_dump, - &dumparg, 0); + dump_counters(zonestats, statsformat_file, fp, NULL, + nsstats_desc, dns_nsstatscounter_max, + nsstats_index, nsstat_values, 0); } } diff --git a/bin/named/update.c b/bin/named/update.c index 28b677020d..f5aa6f50e2 100644 --- a/bin/named/update.c +++ b/bin/named/update.c @@ -15,13 +15,14 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: update.c,v 1.154 2009/01/20 01:40:04 marka Exp $ */ +/* $Id: update.c,v 1.155 2009/01/27 22:29:58 jinmei Exp $ */ #include #include #include #include +#include #include #include #include @@ -44,7 +45,6 @@ #include #include #include -#include #include #include #include @@ -270,13 +270,13 @@ update_log(ns_client_t *client, dns_zone_t *zone, * Increment updated-related statistics counters. */ static inline void -inc_stats(dns_zone_t *zone, dns_statscounter_t counter) { - dns_generalstats_increment(ns_g_server->nsstats, counter); +inc_stats(dns_zone_t *zone, isc_statscounter_t counter) { + isc_stats_increment(ns_g_server->nsstats, counter); if (zone != NULL) { - dns_stats_t *zonestats = dns_zone_getrequeststats(zone); + isc_stats_t *zonestats = dns_zone_getrequeststats(zone); if (zonestats != NULL) - dns_generalstats_increment(zonestats, counter); + isc_stats_increment(zonestats, counter); } } diff --git a/bin/named/xfrout.c b/bin/named/xfrout.c index de9fba3303..6236dfa4cc 100644 --- a/bin/named/xfrout.c +++ b/bin/named/xfrout.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: xfrout.c,v 1.134 2009/01/17 11:35:11 fdupont Exp $ */ +/* $Id: xfrout.c,v 1.135 2009/01/27 22:29:58 jinmei Exp $ */ #include @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -150,12 +151,12 @@ static void db_rr_iterator_destroy(db_rr_iterator_t *it); static inline void -inc_stats(dns_zone_t *zone, dns_statscounter_t counter) { - dns_generalstats_increment(ns_g_server->nsstats, counter); +inc_stats(dns_zone_t *zone, isc_statscounter_t counter) { + isc_stats_increment(ns_g_server->nsstats, counter); if (zone != NULL) { - dns_stats_t *zonestats = dns_zone_getrequeststats(zone); + isc_stats_t *zonestats = dns_zone_getrequeststats(zone); if (zonestats != NULL) - dns_generalstats_increment(zonestats, counter); + isc_stats_increment(zonestats, counter); } } diff --git a/bin/named/zoneconf.c b/bin/named/zoneconf.c index 7a420b52b8..f85bff7e30 100644 --- a/bin/named/zoneconf.c +++ b/bin/named/zoneconf.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: zoneconf.c,v 1.147 2008/09/24 02:46:21 marka Exp $ */ +/* $Id: zoneconf.c,v 1.148 2009/01/27 22:29:58 jinmei Exp $ */ /*% */ @@ -25,6 +25,7 @@ #include #include #include +#include #include /* Required for HP/UX (and others?) */ #include @@ -431,7 +432,7 @@ ns_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig, isc_boolean_t warn = ISC_FALSE, ignore = ISC_FALSE; isc_boolean_t ixfrdiff; dns_masterformat_t masterformat; - dns_stats_t *zoneqrystats; + isc_stats_t *zoneqrystats; isc_boolean_t zonestats_on; int seconds; @@ -564,12 +565,12 @@ ns_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig, zonestats_on = cfg_obj_asboolean(obj); zoneqrystats = NULL; if (zonestats_on) { - RETERR(dns_generalstats_create(mctx, &zoneqrystats, - dns_nsstatscounter_max)); + RETERR(isc_stats_create(mctx, &zoneqrystats, + dns_nsstatscounter_max)); } dns_zone_setrequeststats(zone, zoneqrystats); if (zoneqrystats != NULL) - dns_stats_detach(&zoneqrystats); + isc_stats_detach(&zoneqrystats); /* * Configure master functionality. This applies diff --git a/doc/arm/Bv9ARM-book.xml b/doc/arm/Bv9ARM-book.xml index e8e46ec7bc..30b3f3faba 100644 --- a/doc/arm/Bv9ARM-book.xml +++ b/doc/arm/Bv9ARM-book.xml @@ -18,7 +18,7 @@ - PERFORMANCE OF THIS SOFTWARE. --> - + BIND 9 Administrator Reference Manual @@ -11707,6 +11707,17 @@ HOST-127.EXAMPLE. MX 0 . + + + Socket I/O Statistics + + + + Statistics counters about network related events. + + + + @@ -12516,7 +12527,6 @@ HOST-127.EXAMPLE. MX 0 . - Queryv4 @@ -12686,6 +12696,48 @@ HOST-127.EXAMPLE. MX 0 . + + + QueryAbort + + + + + + + Queries aborted due to quota control. + + + + + + QuerySockFail + + + + + + + Failures in opening query sockets. + One common reason for such failures is a + failure of opening a new socket due to a + limitation on file descriptors. + + + + + + QueryTimeout + + + + + + + Query timeouts. + + + GlueFetchv4 @@ -12790,13 +12842,200 @@ HOST-127.EXAMPLE. MX 0 . - + + + QryRTTnn + + + + + + + Frequency table on round trip times (RTTs) of + queries. + Each nn specifies the corresponding + frequency. + In the sequence of + nn_1, + nn_2, + ..., + nn_m, + the value of nn_i is the + number of queries whose RTTs are between + nn_(i-1) (inclusive) and + nn_i (exclusive) milliseconds. + For the sake of convenience we define + nn_0 to be 0. + The last entry should be represented as + nn_m+, which means the + number of queries whose RTTs are equal to or over + nn_m milliseconds. + + + + + Socket I/O Statistics Counters + + + Socket I/O statistics counters are defined per socket + types, which are + UDP4 (UDP/IPv4), + UDP6 (UDP/IPv6), + TCP4 (TCP/IPv4), + TCP6 (TCP/IPv6), + Unix (Unix Domain), and + FDwatch (sockets opened outside the + socket module). + In the following table <TYPE> + represents a socket type. + Not all counters are available for all socket types; + exceptions are noted in the description field. + + + + + + + + + + + Symbol + + + + + Description + + + + + + + <TYPE>Open + + + + Sockets opened successfully. + This counter is not applicable to the + FDwatch type. + + + + + + <TYPE>OpenFail + + + + Failures of opening sockets. + This counter is not applicable to the + FDwatch type. + + + + + + <TYPE>Close + + + + Sockets closed. + + + + + + <TYPE>BindFail + + + + Failures of binding sockets. + + + + + + <TYPE>ConnFail + + + + Failures of connecting sockets. + + + + + + <TYPE>Conn + + + + Connections established successfully. + + + + + + <TYPE>AcceptFail + + + + Failures of accepting incoming connection requests. + This counter is not applicable to the + UDP and + FDwatch types. + + + + + + <TYPE>Accept + + + + Incoming connections successfully accepted. + This counter is not applicable to the + UDP and + FDwatch types. + + + + + + <TYPE>SendErr + + + + Errors in socket send operations. + This counter corresponds + to SErr counter of + BIND 8. + + + + + + <TYPE>RecvErr + + + + Errors in socket receive operations. + This includes errors of send operations on a + connected UDP socket notified by an ICMP error + message. + + + + + + + Compatibility with <emphasis>BIND</emphasis> 8 Counters @@ -12848,17 +13087,6 @@ HOST-127.EXAMPLE. MX 0 . - - - SErr - - - This counter could be implemented, but is not yet - supported. - - - - diff --git a/lib/dns/adb.c b/lib/dns/adb.c index a41515cdfd..ef261419b8 100644 --- a/lib/dns/adb.c +++ b/lib/dns/adb.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: adb.c,v 1.243 2008/10/17 03:23:13 marka Exp $ */ +/* $Id: adb.c,v 1.244 2009/01/27 22:29:58 jinmei Exp $ */ /*! \file * @@ -33,6 +33,7 @@ #include #include #include +#include #include /* Required for HP/UX (and others?) */ #include #include @@ -461,9 +462,9 @@ DP(int level, const char *format, ...) { * Increment resolver-related statistics counters. */ static inline void -inc_stats(dns_adb_t *adb, dns_statscounter_t counter) { +inc_stats(dns_adb_t *adb, isc_statscounter_t counter) { if (adb->view->resstats != NULL) - dns_generalstats_increment(adb->view->resstats, counter); + isc_stats_increment(adb->view->resstats, counter); } static inline dns_ttl_t diff --git a/lib/dns/dispatch.c b/lib/dns/dispatch.c index 989d0434e7..7b32a71d98 100644 --- a/lib/dns/dispatch.c +++ b/lib/dns/dispatch.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dispatch.c,v 1.159 2009/01/17 23:47:42 tbox Exp $ */ +/* $Id: dispatch.c,v 1.160 2009/01/27 22:29:59 jinmei Exp $ */ /*! \file */ @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -80,7 +81,7 @@ struct dns_dispatchmgr { isc_mem_t *mctx; dns_acl_t *blackhole; dns_portlist_t *portlist; - dns_stats_t *stats; + isc_stats_t *stats; isc_entropy_t *entropy; /*%< entropy source */ /* Locked by "lock". */ @@ -1262,8 +1263,8 @@ udp_recv(isc_event_t *ev_in, dns_dispatch_t *disp, dispsocket_t *dispsock) { bucket, (resp == NULL ? "not found" : "found")); if (resp == NULL) { - dns_generalstats_increment(mgr->stats, - dns_resstatscounter_mismatch); + isc_stats_increment(mgr->stats, + dns_resstatscounter_mismatch); free_buffer(disp, ev->region.base, ev->region.length); goto unlock; } @@ -1271,8 +1272,7 @@ udp_recv(isc_event_t *ev_in, dns_dispatch_t *disp, dispsocket_t *dispsock) { &resp->host)) { dispatch_log(disp, LVL(90), "response to an exclusive socket doesn't match"); - dns_generalstats_increment(mgr->stats, - dns_resstatscounter_mismatch); + isc_stats_increment(mgr->stats, dns_resstatscounter_mismatch); free_buffer(disp, ev->region.base, ev->region.length); goto unlock; } @@ -1709,7 +1709,7 @@ destroy_mgr(dns_dispatchmgr_t **mgrp) { dns_acl_detach(&mgr->blackhole); if (mgr->stats != NULL) - dns_stats_detach(&mgr->stats); + isc_stats_detach(&mgr->stats); if (mgr->v4ports != NULL) { isc_mem_put(mctx, mgr->v4ports, @@ -2112,12 +2112,12 @@ dns_dispatchmgr_destroy(dns_dispatchmgr_t **mgrp) { } void -dns_dispatchmgr_setstats(dns_dispatchmgr_t *mgr, dns_stats_t *stats) { +dns_dispatchmgr_setstats(dns_dispatchmgr_t *mgr, isc_stats_t *stats) { REQUIRE(VALID_DISPATCHMGR(mgr)); REQUIRE(ISC_LIST_EMPTY(mgr->list)); REQUIRE(mgr->stats == NULL); - dns_stats_attach(stats, &mgr->stats); + isc_stats_attach(stats, &mgr->stats); } static int @@ -2986,6 +2986,8 @@ dns_dispatch_addresponse2(dns_dispatch_t *disp, isc_sockaddr_t *dest, oldestresp->item_out = ISC_TRUE; isc_task_send(oldestresp->task, ISC_EVENT_PTR(&rev)); + isc_stats_increment(disp->mgr->stats, + dns_resstatscounter_dispabort); } } @@ -3009,6 +3011,8 @@ dns_dispatch_addresponse2(dns_dispatch_t *disp, isc_sockaddr_t *dest, if (result != ISC_R_SUCCESS) { UNLOCK(&qid->lock); UNLOCK(&disp->lock); + isc_stats_increment(disp->mgr->stats, + dns_resstatscounter_dispsockfail); return (result); } } else { diff --git a/lib/dns/include/dns/dispatch.h b/lib/dns/include/dns/dispatch.h index 8a0094ed43..8512b43cf6 100644 --- a/lib/dns/include/dns/dispatch.h +++ b/lib/dns/include/dns/dispatch.h @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dispatch.h,v 1.60 2008/06/23 23:47:11 tbox Exp $ */ +/* $Id: dispatch.h,v 1.61 2009/01/27 22:29:59 jinmei Exp $ */ #ifndef DNS_DISPATCH_H #define DNS_DISPATCH_H 1 @@ -55,7 +55,7 @@ #include #include #include -#include +#include #include @@ -223,7 +223,7 @@ dns_dispatchmgr_setavailports(dns_dispatchmgr_t *mgr, isc_portset_t *v4portset, */ void -dns_dispatchmgr_setstats(dns_dispatchmgr_t *mgr, dns_stats_t *stats); +dns_dispatchmgr_setstats(dns_dispatchmgr_t *mgr, isc_stats_t *stats); /*%< * Sets statistics counter for the dispatchmgr. This function is expected to * be called only on zone creation (when necessary). diff --git a/lib/dns/include/dns/resolver.h b/lib/dns/include/dns/resolver.h index 5608ec7701..04a7a1e0a5 100644 --- a/lib/dns/include/dns/resolver.h +++ b/lib/dns/include/dns/resolver.h @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: resolver.h,v 1.62 2009/01/07 23:47:47 tbox Exp $ */ +/* $Id: resolver.h,v 1.63 2009/01/27 22:29:59 jinmei Exp $ */ #ifndef DNS_RESOLVER_H #define DNS_RESOLVER_H 1 @@ -100,6 +100,21 @@ typedef struct dns_fetchevent { #define DNS_FETCHOPT_EDNSVERSIONMASK 0xff000000 #define DNS_FETCHOPT_EDNSVERSIONSHIFT 24 +/* + * Upper bounds of class of query RTT (ms). Corresponds to + * dns_resstatscounter_queryrttX statistics counters. + */ +#define DNS_RESOLVER_QRYRTTCLASS0 10 +#define DNS_RESOLVER_QRYRTTCLASS0STR "10" +#define DNS_RESOLVER_QRYRTTCLASS1 100 +#define DNS_RESOLVER_QRYRTTCLASS1STR "100" +#define DNS_RESOLVER_QRYRTTCLASS2 500 +#define DNS_RESOLVER_QRYRTTCLASS2STR "500" +#define DNS_RESOLVER_QRYRTTCLASS3 800 +#define DNS_RESOLVER_QRYRTTCLASS3STR "800" +#define DNS_RESOLVER_QRYRTTCLASS4 1600 +#define DNS_RESOLVER_QRYRTTCLASS4STR "1600" + /* * XXXRTH Should this API be made semi-private? (I.e. * _dns_resolver_create()). diff --git a/lib/dns/include/dns/stats.h b/lib/dns/include/dns/stats.h index 8f8e38a64b..d70c02a787 100644 --- a/lib/dns/include/dns/stats.h +++ b/lib/dns/include/dns/stats.h @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: stats.h,v 1.18 2008/09/08 05:59:11 marka Exp $ */ +/* $Id: stats.h,v 1.19 2009/01/27 22:29:59 jinmei Exp $ */ #ifndef DNS_STATS_H #define DNS_STATS_H 1 @@ -25,7 +25,7 @@ #include /*% - * Statistics counters. Used as dns_statscounter_t values. + * Statistics counters. Used as isc_statscounter_t values. */ enum { /*% @@ -52,8 +52,17 @@ enum { dns_resstatscounter_valsuccess = 18, dns_resstatscounter_valnegsuccess = 19, dns_resstatscounter_valfail = 20, + dns_resstatscounter_dispabort = 21, + dns_resstatscounter_dispsockfail = 22, + dns_resstatscounter_querytimeout = 23, + dns_resstatscounter_queryrtt0 = 24, + dns_resstatscounter_queryrtt1 = 25, + dns_resstatscounter_queryrtt2 = 26, + dns_resstatscounter_queryrtt3 = 27, + dns_resstatscounter_queryrtt4 = 28, + dns_resstatscounter_queryrtt5 = 29, - dns_resstatscounter_max = 21, + dns_resstatscounter_max = 30, /*% * Zone statistics counters. @@ -89,10 +98,14 @@ enum { #define DNS_STATS_NCOUNTERS 8 +#if 0 /*%< - * Flag(s) for dns_xxxstats_dump(). + * Flag(s) for dns_xxxstats_dump(). DNS_STATSDUMP_VERBOSE is obsolete. + * ISC_STATSDUMP_VERBOSE should be used instead. These two values are + * intentionally defined to be the same value to ensure binary compatibility. */ #define DNS_STATSDUMP_VERBOSE 0x00000001 /*%< dump 0-value counters */ +#endif /*%< * (Obsoleted) @@ -119,7 +132,7 @@ LIBDNS_EXTERNAL_DATA extern const char *dns_statscounter_names[]; #define DNS_RDATASTATSTYPE_ATTR_NXDOMAIN 0x0004 /*%< - * Conversion macros among dns_rdatatype_t, attributes and dns_statscounter_t. + * Conversion macros among dns_rdatatype_t, attributes and isc_statscounter_t. */ #define DNS_RDATASTATSTYPE_BASE(type) ((dns_rdatatype_t)((type) & 0xFFFF)) #define DNS_RDATASTATSTYPE_ATTR(type) ((type) >> 16) @@ -128,7 +141,7 @@ LIBDNS_EXTERNAL_DATA extern const char *dns_statscounter_names[]; /*%< * Types of dump callbacks. */ -typedef void (*dns_generalstats_dumper_t)(dns_statscounter_t, isc_uint64_t, +typedef void (*dns_generalstats_dumper_t)(isc_statscounter_t, isc_uint64_t, void *); typedef void (*dns_rdatatypestats_dumper_t)(dns_rdatastatstype_t, isc_uint64_t, void *); @@ -139,6 +152,8 @@ dns_generalstats_create(isc_mem_t *mctx, dns_stats_t **statsp, int ncounters); /*%< * Create a statistics counter structure of general type. It counts a general * set of counters indexed by an ID between 0 and ncounters -1. + * This function is obsolete. A more general function, isc_stats_create(), + * should be used. * * Requires: *\li 'mctx' must be a valid memory context. @@ -220,9 +235,10 @@ dns_stats_detach(dns_stats_t **statsp); */ void -dns_generalstats_increment(dns_stats_t *stats, dns_statscounter_t counter); +dns_generalstats_increment(dns_stats_t *stats, isc_statscounter_t counter); /*%< - * Increment the counter-th counter of stats. + * Increment the counter-th counter of stats. This function is obsolete. + * A more general function, isc_stats_increment(), should be used. * * Requires: *\li 'stats' is a valid dns_stats_t created by dns_generalstats_create(). @@ -274,7 +290,10 @@ dns_generalstats_dump(dns_stats_t *stats, dns_generalstats_dumper_t dump_fn, * Dump the current statistics counters in a specified way. For each counter * in stats, dump_fn is called with its current value and the given argument * arg. By default counters that have a value of 0 is skipped; if options has - * the DNS_STATSDUMP_VERBOSE flag, even such counters are dumped. + * the ISC_STATSDUMP_VERBOSE flag, even such counters are dumped. + * + * This function is obsolete. A more general function, isc_stats_dump(), + * should be used. * * Requires: *\li 'stats' is a valid dns_stats_t created by dns_generalstats_create(). @@ -288,7 +307,7 @@ dns_rdatatypestats_dump(dns_stats_t *stats, dns_rdatatypestats_dumper_t dump_fn, * in stats, dump_fn is called with the corresponding type in the form of * dns_rdatastatstype_t, the current counter value and the given argument * arg. By default counters that have a value of 0 is skipped; if options has - * the DNS_STATSDUMP_VERBOSE flag, even such counters are dumped. + * the ISC_STATSDUMP_VERBOSE flag, even such counters are dumped. * * Requires: *\li 'stats' is a valid dns_stats_t created by dns_generalstats_create(). @@ -302,7 +321,7 @@ dns_rdatasetstats_dump(dns_stats_t *stats, dns_rdatatypestats_dumper_t dump_fn, * in stats, dump_fn is called with the corresponding type in the form of * dns_rdatastatstype_t, the current counter value and the given argument * arg. By default counters that have a value of 0 is skipped; if options has - * the DNS_STATSDUMP_VERBOSE flag, even such counters are dumped. + * the ISC_STATSDUMP_VERBOSE flag, even such counters are dumped. * * Requires: *\li 'stats' is a valid dns_stats_t created by dns_generalstats_create(). @@ -315,7 +334,7 @@ dns_opcodestats_dump(dns_stats_t *stats, dns_opcodestats_dumper_t dump_fn, * Dump the current statistics counters in a specified way. For each counter * in stats, dump_fn is called with the corresponding opcode, the current * counter value and the given argument arg. By default counters that have a - * value of 0 is skipped; if options has the DNS_STATSDUMP_VERBOSE flag, even + * value of 0 is skipped; if options has the ISC_STATSDUMP_VERBOSE flag, even * such counters are dumped. * * Requires: diff --git a/lib/dns/include/dns/types.h b/lib/dns/include/dns/types.h index 02aaabae15..292ec60042 100644 --- a/lib/dns/include/dns/types.h +++ b/lib/dns/include/dns/types.h @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: types.h,v 1.132 2009/01/17 23:47:43 tbox Exp $ */ +/* $Id: types.h,v 1.133 2009/01/27 22:29:59 jinmei Exp $ */ #ifndef DNS_TYPES_H #define DNS_TYPES_H 1 @@ -108,7 +108,6 @@ typedef struct dns_signature dns_signature_t; typedef struct dns_ssurule dns_ssurule_t; typedef struct dns_ssutable dns_ssutable_t; typedef struct dns_stats dns_stats_t; -typedef int dns_statscounter_t; typedef isc_uint32_t dns_rdatastatstype_t; typedef struct dns_tkeyctx dns_tkeyctx_t; typedef isc_uint16_t dns_trust_t; diff --git a/lib/dns/include/dns/view.h b/lib/dns/include/dns/view.h index 8cfb029a76..6c99ef1f7f 100644 --- a/lib/dns/include/dns/view.h +++ b/lib/dns/include/dns/view.h @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: view.h,v 1.115 2009/01/17 13:23:56 fdupont Exp $ */ +/* $Id: view.h,v 1.116 2009/01/27 22:29:59 jinmei Exp $ */ #ifndef DNS_VIEW_H #define DNS_VIEW_H 1 @@ -100,7 +100,7 @@ struct dns_view { isc_event_t resevent; isc_event_t adbevent; isc_event_t reqevent; - dns_stats_t * resstats; + isc_stats_t * resstats; dns_stats_t * resquerystats; isc_boolean_t cacheshared; @@ -837,7 +837,7 @@ dns_view_freezezones(dns_view_t *view, isc_boolean_t freeze); */ void -dns_view_setresstats(dns_view_t *view, dns_stats_t *stats); +dns_view_setresstats(dns_view_t *view, isc_stats_t *stats); /*%< * Set a general resolver statistics counter set 'stats' for 'view'. * @@ -849,7 +849,7 @@ dns_view_setresstats(dns_view_t *view, dns_stats_t *stats); */ void -dns_view_getresstats(dns_view_t *view, dns_stats_t **statsp); +dns_view_getresstats(dns_view_t *view, isc_stats_t **statsp); /*%< * Get the general statistics counter set for 'view'. If a statistics set is * set '*statsp' will be attached to the set; otherwise, '*statsp' will be diff --git a/lib/dns/include/dns/zone.h b/lib/dns/include/dns/zone.h index fe9a0453fa..b917b4d651 100644 --- a/lib/dns/include/dns/zone.h +++ b/lib/dns/include/dns/zone.h @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: zone.h,v 1.163 2009/01/17 13:30:15 fdupont Exp $ */ +/* $Id: zone.h,v 1.164 2009/01/27 22:29:59 jinmei Exp $ */ #ifndef DNS_ZONE_H #define DNS_ZONE_H 1 @@ -1522,7 +1522,7 @@ dns_zone_getstatscounters(dns_zone_t *zone); */ void -dns_zone_setstats(dns_zone_t *zone, dns_stats_t *stats); +dns_zone_setstats(dns_zone_t *zone, isc_stats_t *stats); /*%< * Set a general zone-maintenance statistics set 'stats' for 'zone'. This * function is expected to be called only on zone creation (when necessary). @@ -1539,7 +1539,7 @@ dns_zone_setstats(dns_zone_t *zone, dns_stats_t *stats); */ void -dns_zone_setrequeststats(dns_zone_t *zone, dns_stats_t *stats); +dns_zone_setrequeststats(dns_zone_t *zone, isc_stats_t *stats); /*%< * Set an additional statistics set to zone. It is attached in the zone * but is not counted in the zone module; only the caller updates the counters. @@ -1550,7 +1550,7 @@ dns_zone_setrequeststats(dns_zone_t *zone, dns_stats_t *stats); *\li stats is a valid statistics. */ -dns_stats_t * +isc_stats_t * dns_zone_getrequeststats(dns_zone_t *zone); /*%< * Get the additional statistics for zone, if one is installed. diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index c243fb5fe5..805b0a14fe 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: resolver.c,v 1.389 2009/01/17 14:59:03 fdupont Exp $ */ +/* $Id: resolver.c,v 1.390 2009/01/27 22:29:59 jinmei Exp $ */ /*! \file */ @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -425,9 +426,9 @@ static void add_bad(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo, * Increment resolver-related statistics counters. */ static inline void -inc_stats(dns_resolver_t *res, dns_statscounter_t counter) { +inc_stats(dns_resolver_t *res, isc_statscounter_t counter) { if (res->view->resstats != NULL) - dns_generalstats_increment(res->view->resstats, counter); + isc_stats_increment(res->view->resstats, counter); } static isc_result_t @@ -616,7 +617,7 @@ fctx_cancelquery(resquery_t **queryp, dns_dispatchevent_t **deventp, { fetchctx_t *fctx; resquery_t *query; - unsigned int rtt; + unsigned int rtt, rttms; unsigned int factor; dns_adbfind_t *find; dns_adbaddrinfo_t *addrinfo; @@ -643,6 +644,27 @@ fctx_cancelquery(resquery_t **queryp, dns_dispatchevent_t **deventp, rtt = (unsigned int)isc_time_microdiff(finish, &query->start); factor = DNS_ADB_RTTADJDEFAULT; + + rttms = rtt / 1000; + if (rttms < DNS_RESOLVER_QRYRTTCLASS0) { + inc_stats(fctx->res, + dns_resstatscounter_queryrtt0); + } else if (rttms < DNS_RESOLVER_QRYRTTCLASS1) { + inc_stats(fctx->res, + dns_resstatscounter_queryrtt1); + } else if (rttms < DNS_RESOLVER_QRYRTTCLASS2) { + inc_stats(fctx->res, + dns_resstatscounter_queryrtt2); + } else if (rttms < DNS_RESOLVER_QRYRTTCLASS3) { + inc_stats(fctx->res, + dns_resstatscounter_queryrtt3); + } else if (rttms < DNS_RESOLVER_QRYRTTCLASS4) { + inc_stats(fctx->res, + dns_resstatscounter_queryrtt4); + } else { + inc_stats(fctx->res, + dns_resstatscounter_queryrtt5); + } } else { /* * We don't have an RTT for this query. Maybe the @@ -2965,6 +2987,8 @@ fctx_timeout(isc_task_t *task, isc_event_t *event) { FCTXTRACE("timeout"); + inc_stats(fctx->res, dns_resstatscounter_querytimeout); + if (event->ev_type == ISC_TIMEREVENT_LIFE) { fctx->reason = NULL; fctx_done(fctx, ISC_R_TIMEDOUT, __LINE__); diff --git a/lib/dns/stats.c b/lib/dns/stats.c index 71108834d9..6975e2aa4c 100644 --- a/lib/dns/stats.c +++ b/lib/dns/stats.c @@ -15,21 +15,15 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: stats.c,v 1.16 2008/04/03 06:09:04 tbox Exp $ */ +/* $Id: stats.c,v 1.17 2009/01/27 22:29:59 jinmei Exp $ */ /*! \file */ #include -#include - -#include -#include #include #include -#include -#include -#include +#include #include #include @@ -67,120 +61,27 @@ enum { rdatasettypecounter_max = rdtypecounter_nxdomain + 1 }; -#ifndef DNS_STATS_USEMULTIFIELDS -#if defined(ISC_RWLOCK_USEATOMIC) && defined(ISC_PLATFORM_HAVEXADD) && !defined(ISC_PLATFORM_HAVEXADDQ) -#define DNS_STATS_USEMULTIFIELDS 1 -#else -#define DNS_STATS_USEMULTIFIELDS 0 -#endif -#endif /* DNS_STATS_USEMULTIFIELDS */ - -#if DNS_STATS_USEMULTIFIELDS -typedef struct { - isc_uint32_t hi; - isc_uint32_t lo; -} dns_stat_t; -#else -typedef isc_uint64_t dns_stat_t; -#endif - struct dns_stats { /*% Unlocked */ unsigned int magic; dns_statstype_t type; isc_mem_t *mctx; - int ncounters; - isc_mutex_t lock; - unsigned int references; /* locked by lock */ + isc_stats_t *counters; - /*% - * Locked by counterlock or unlocked if efficient rwlock is not - * available. - */ -#ifdef ISC_RWLOCK_USEATOMIC - isc_rwlock_t counterlock; -#endif - dns_stat_t *counters; - - /*% - * We don't want to lock the counters while we are dumping, so we first - * copy the current counter values into a local array. This buffer - * will be used as the copy destination. It's allocated on creation - * of the stats structure so that the dump operation won't fail due - * to memory allocation failure. - * XXX: this approach is weird for non-threaded build because the - * additional memory and the copy overhead could be avoided. We prefer - * simplicity here, however, under the assumption that this function - * should be only rarely called. - */ - isc_uint64_t *copiedcounters; + /*% Locked by lock */ + unsigned int references; }; -static isc_result_t -create_stats(isc_mem_t *mctx, dns_statstype_t type, int ncounters, - dns_stats_t **statsp) -{ - dns_stats_t *stats; - isc_result_t result = ISC_R_SUCCESS; +typedef struct rdatadumparg { + dns_rdatatypestats_dumper_t fn; + void *arg; +} rdatadumparg_t; - REQUIRE(statsp != NULL && *statsp == NULL); - - stats = isc_mem_get(mctx, sizeof(*stats)); - if (stats == NULL) - return (ISC_R_NOMEMORY); - - result = isc_mutex_init(&stats->lock); - if (result != ISC_R_SUCCESS) - goto clean_stats; - - stats->counters = isc_mem_get(mctx, sizeof(dns_stat_t) * ncounters); - if (stats->counters == NULL) { - result = ISC_R_NOMEMORY; - goto clean_mutex; - } - stats->copiedcounters = isc_mem_get(mctx, - sizeof(isc_uint64_t) * ncounters); - if (stats->copiedcounters == NULL) { - result = ISC_R_NOMEMORY; - goto clean_counters; - } - -#ifdef ISC_RWLOCK_USEATOMIC - result = isc_rwlock_init(&stats->counterlock, 0, 0); - if (result != ISC_R_SUCCESS) - goto clean_copiedcounters; -#endif - - stats->type = type; - stats->references = 1; - memset(stats->counters, 0, sizeof(dns_stat_t) * ncounters); - stats->mctx = NULL; - isc_mem_attach(mctx, &stats->mctx); - stats->ncounters = ncounters; - stats->magic = DNS_STATS_MAGIC; - - *statsp = stats; - - return (result); - -clean_counters: - isc_mem_put(mctx, stats->counters, sizeof(dns_stat_t) * ncounters); - -#ifdef ISC_RWLOCK_USEATOMIC -clean_copiedcounters: - isc_mem_put(mctx, stats->copiedcounters, - sizeof(dns_stat_t) * ncounters); -#endif - -clean_mutex: - DESTROYLOCK(&stats->lock); - -clean_stats: - isc_mem_put(mctx, stats, sizeof(*stats)); - - return (result); -} +typedef struct opcodedumparg { + dns_opcodestats_dumper_t fn; + void *arg; +} opcodedumparg_t; void dns_stats_attach(dns_stats_t *stats, dns_stats_t **statsp) { @@ -208,114 +109,53 @@ dns_stats_detach(dns_stats_t **statsp) { UNLOCK(&stats->lock); if (stats->references == 0) { - isc_mem_put(stats->mctx, stats->copiedcounters, - sizeof(dns_stat_t) * stats->ncounters); - isc_mem_put(stats->mctx, stats->counters, - sizeof(dns_stat_t) * stats->ncounters); + isc_stats_detach(&stats->counters); DESTROYLOCK(&stats->lock); -#ifdef ISC_RWLOCK_USEATOMIC - isc_rwlock_destroy(&stats->counterlock); -#endif isc_mem_putanddetach(&stats->mctx, stats, sizeof(*stats)); } } -static inline void -incrementcounter(dns_stats_t *stats, int counter) { - isc_int32_t prev; - -#ifdef ISC_RWLOCK_USEATOMIC - /* - * We use a "read" lock to prevent other threads from reading the - * counter while we "writing" a counter field. The write access itself - * is protected by the atomic operation. - */ - isc_rwlock_lock(&stats->counterlock, isc_rwlocktype_read); -#endif - -#if DNS_STATS_USEMULTIFIELDS - prev = isc_atomic_xadd((isc_int32_t *)&stats->counters[counter].lo, 1); - /* - * If the lower 32-bit field overflows, increment the higher field. - * Note that it's *theoretically* possible that the lower field - * overlaps again before the higher field is incremented. It doesn't - * matter, however, because we don't read the value until - * dns_stats_copy() is called where the whole process is protected - * by the write (exclusive) lock. - */ - if (prev == (isc_int32_t)0xffffffff) - isc_atomic_xadd((isc_int32_t *)&stats->counters[counter].hi, 1); -#elif defined(ISC_PLATFORM_HAVEXADDQ) - UNUSED(prev); - isc_atomic_xaddq((isc_int64_t *)&stats->counters[counter], 1); -#else - UNUSED(prev); - stats->counters[counter]++; -#endif - -#ifdef ISC_RWLOCK_USEATOMIC - isc_rwlock_unlock(&stats->counterlock, isc_rwlocktype_read); -#endif -} - -static inline void -decrementcounter(dns_stats_t *stats, int counter) { - isc_int32_t prev; - -#ifdef ISC_RWLOCK_USEATOMIC - isc_rwlock_lock(&stats->counterlock, isc_rwlocktype_read); -#endif - -#if DNS_STATS_USEMULTIFIELDS - prev = isc_atomic_xadd((isc_int32_t *)&stats->counters[counter].lo, -1); - if (prev == 0) - isc_atomic_xadd((isc_int32_t *)&stats->counters[counter].hi, - -1); -#elif defined(ISC_PLATFORM_HAVEXADDQ) - UNUSED(prev); - isc_atomic_xaddq((isc_int64_t *)&stats->counters[counter], -1); -#else - UNUSED(prev); - stats->counters[counter]--; -#endif - -#ifdef ISC_RWLOCK_USEATOMIC - isc_rwlock_unlock(&stats->counterlock, isc_rwlocktype_read); -#endif -} - -static void -copy_counters(dns_stats_t *stats) { - int i; - -#ifdef ISC_RWLOCK_USEATOMIC - /* - * We use a "write" lock before "reading" the statistics counters as - * an exclusive lock. - */ - isc_rwlock_lock(&stats->counterlock, isc_rwlocktype_write); -#endif - -#if DNS_STATS_USEMULTIFIELDS - for (i = 0; i < stats->ncounters; i++) { - stats->copiedcounters[i] = - (isc_uint64_t)(stats->counters[i].hi) << 32 | - stats->counters[i].lo; - } -#else - UNUSED(i); - memcpy(stats->copiedcounters, stats->counters, - stats->ncounters * sizeof(dns_stat_t)); -#endif - -#ifdef ISC_RWLOCK_USEATOMIC - isc_rwlock_unlock(&stats->counterlock, isc_rwlocktype_write); -#endif -} - /*% * Create methods */ +static isc_result_t +create_stats(isc_mem_t *mctx, dns_statstype_t type, int ncounters, + dns_stats_t **statsp) +{ + dns_stats_t *stats; + isc_result_t result; + + stats = isc_mem_get(mctx, sizeof(*stats)); + if (stats == NULL) + return (ISC_R_NOMEMORY); + + stats->counters = NULL; + stats->references = 1; + + result = isc_mutex_init(&stats->lock); + if (result != ISC_R_SUCCESS) + goto clean_stats; + + result = isc_stats_create(mctx, &stats->counters, ncounters); + if (result != ISC_R_SUCCESS) + goto clean_mutex; + + stats->magic = DNS_STATS_MAGIC; + stats->type = type; + stats->mctx = NULL; + isc_mem_attach(mctx, &stats->mctx); + *statsp = stats; + + return (ISC_R_SUCCESS); + + clean_mutex: + DESTROYLOCK(&stats->lock); + clean_stats: + isc_mem_put(mctx, stats, sizeof(*stats)); + + return (result); +} + isc_result_t dns_generalstats_create(isc_mem_t *mctx, dns_stats_t **statsp, int ncounters) { REQUIRE(statsp != NULL && *statsp == NULL); @@ -350,11 +190,10 @@ dns_opcodestats_create(isc_mem_t *mctx, dns_stats_t **statsp) { * Increment/Decrement methods */ void -dns_generalstats_increment(dns_stats_t *stats, dns_statscounter_t counter) { +dns_generalstats_increment(dns_stats_t *stats, isc_statscounter_t counter) { REQUIRE(DNS_STATS_VALID(stats) && stats->type == dns_statstype_general); - REQUIRE(counter < stats->ncounters); - incrementcounter(stats, (int)counter); + isc_stats_increment(stats->counters, counter); } void @@ -370,7 +209,7 @@ dns_rdatatypestats_increment(dns_stats_t *stats, dns_rdatatype_t type) { else counter = (int)type; - incrementcounter(stats, counter); + isc_stats_increment(stats->counters, (isc_statscounter_t)counter); } static inline void @@ -398,9 +237,9 @@ update_rdatasetstats(dns_stats_t *stats, dns_rdatastatstype_t rrsettype, } if (increment) - incrementcounter(stats, counter); + isc_stats_increment(stats->counters, counter); else - decrementcounter(stats, counter); + isc_stats_decrement(stats->counters, counter); } void @@ -424,7 +263,7 @@ void dns_opcodestats_increment(dns_stats_t *stats, dns_opcode_t code) { REQUIRE(DNS_STATS_VALID(stats) && stats->type == dns_statstype_opcode); - incrementcounter(stats, (int)code); + isc_stats_increment(stats->counters, (isc_statscounter_t)code); } /*% @@ -434,32 +273,19 @@ void dns_generalstats_dump(dns_stats_t *stats, dns_generalstats_dumper_t dump_fn, void *arg, unsigned int options) { - int i; - REQUIRE(DNS_STATS_VALID(stats) && stats->type == dns_statstype_general); - copy_counters(stats); - - for (i = 0; i < stats->ncounters; i++) { - if ((options & DNS_STATSDUMP_VERBOSE) == 0 && - stats->copiedcounters[i] == 0) - continue; - dump_fn(i, stats->copiedcounters[i], arg); - } + isc_stats_dump(stats->counters, (isc_stats_dumper_t)dump_fn, + arg, options); } static void -dump_rdentry(dns_stats_t *stats, int counter, int rdcounter, - dns_rdatastatstype_t attributes, - dns_rdatatypestats_dumper_t dump_fn, void * arg, - unsigned int options) +dump_rdentry(int rdcounter, isc_uint64_t value, dns_rdatastatstype_t attributes, + dns_rdatatypestats_dumper_t dump_fn, void * arg) { dns_rdatatype_t rdtype = dns_rdatatype_none; /* sentinel */ dns_rdatastatstype_t type; - if ((options & DNS_STATSDUMP_VERBOSE) == 0 && - stats->copiedcounters[counter] == 0) - return; if (rdcounter == rdtypecounter_others) attributes |= DNS_RDATASTATSTYPE_ATTR_OTHERTYPE; else { @@ -470,63 +296,77 @@ dump_rdentry(dns_stats_t *stats, int counter, int rdcounter, } type = DNS_RDATASTATSTYPE_VALUE((dns_rdatastatstype_t)rdtype, attributes); - dump_fn(type, stats->copiedcounters[counter], arg); + dump_fn(type, value, arg); +} + +static void +rdatatype_dumpcb(isc_statscounter_t counter, isc_uint64_t value, void *arg) { + rdatadumparg_t *rdatadumparg = arg; + + dump_rdentry(counter, value, 0, rdatadumparg->fn, rdatadumparg->arg); } void dns_rdatatypestats_dump(dns_stats_t *stats, dns_rdatatypestats_dumper_t dump_fn, - void *arg, unsigned int options) + void *arg0, unsigned int options) { - int i; - + rdatadumparg_t arg; REQUIRE(DNS_STATS_VALID(stats) && stats->type == dns_statstype_rdtype); - copy_counters(stats); + arg.fn = dump_fn; + arg.arg = arg0; + isc_stats_dump(stats->counters, rdatatype_dumpcb, &arg, options); +} - for (i = 0; i < stats->ncounters; i++) - dump_rdentry(stats, i, i, 0, dump_fn, arg, options); +static void +rdataset_dumpcb(isc_statscounter_t counter, isc_uint64_t value, void *arg) { + rdatadumparg_t *rdatadumparg = arg; + + if (counter < rdtypecounter_max) { + dump_rdentry(counter, value, 0, rdatadumparg->fn, + rdatadumparg->arg); + } else if (counter < rdtypenxcounter_max) { + dump_rdentry(counter - rdtypecounter_max, value, + DNS_RDATASTATSTYPE_ATTR_NXRRSET, + rdatadumparg->fn, rdatadumparg->arg); + } else { + dump_rdentry(0, value, DNS_RDATASTATSTYPE_ATTR_NXDOMAIN, + rdatadumparg->fn, rdatadumparg->arg); + } } void dns_rdatasetstats_dump(dns_stats_t *stats, dns_rdatatypestats_dumper_t dump_fn, - void *arg, unsigned int options) + void *arg0, unsigned int options) { - int i; + rdatadumparg_t arg; REQUIRE(DNS_STATS_VALID(stats) && stats->type == dns_statstype_rdataset); - copy_counters(stats); + arg.fn = dump_fn; + arg.arg = arg0; + isc_stats_dump(stats->counters, rdataset_dumpcb, &arg, options); +} - for (i = 0; i < rdtypecounter_max; i++) - dump_rdentry(stats, i, i, 0, dump_fn, arg, options); - for (i = rdtypecounter_max; i < rdtypenxcounter_max; i++) { - dump_rdentry(stats, i, i - rdtypecounter_max, - DNS_RDATASTATSTYPE_ATTR_NXRRSET, - dump_fn, arg, options); - } - dump_rdentry(stats, rdtypecounter_nxdomain, 0, - DNS_RDATASTATSTYPE_ATTR_NXDOMAIN, dump_fn, arg, options); +static void +opcode_dumpcb(isc_statscounter_t counter, isc_uint64_t value, void *arg) { + opcodedumparg_t *opcodearg = arg; - INSIST(i < stats->ncounters); + opcodearg->fn((dns_opcode_t)counter, value, opcodearg->arg); } void dns_opcodestats_dump(dns_stats_t *stats, dns_opcodestats_dumper_t dump_fn, - void *arg, unsigned int options) + void *arg0, unsigned int options) { - int i; + opcodedumparg_t arg; REQUIRE(DNS_STATS_VALID(stats) && stats->type == dns_statstype_opcode); - copy_counters(stats); - - for (i = 0; i < stats->ncounters; i++) { - if ((options & DNS_STATSDUMP_VERBOSE) == 0 && - stats->copiedcounters[i] == 0) - continue; - dump_fn((dns_opcode_t)i, stats->copiedcounters[i], arg); - } + arg.fn = dump_fn; + arg.arg = arg0; + isc_stats_dump(stats->counters, opcode_dumpcb, &arg, options); } /*** diff --git a/lib/dns/view.c b/lib/dns/view.c index d97e4b7041..f7a3662916 100644 --- a/lib/dns/view.c +++ b/lib/dns/view.c @@ -15,13 +15,14 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: view.c,v 1.152 2009/01/09 23:47:45 tbox Exp $ */ +/* $Id: view.c,v 1.153 2009/01/27 22:29:59 jinmei Exp $ */ /*! \file */ #include #include +#include #include /* Required for HP/UX (and others?) */ #include #include @@ -348,7 +349,7 @@ destroy(dns_view_t *view) { view->rootexclude = NULL; } if (view->resstats != NULL) - dns_stats_detach(&view->resstats); + isc_stats_detach(&view->resstats); if (view->resquerystats != NULL) dns_stats_detach(&view->resquerystats); dns_keytable_detach(&view->trustedkeys); @@ -1452,21 +1453,21 @@ dns_view_freezezones(dns_view_t *view, isc_boolean_t value) { } void -dns_view_setresstats(dns_view_t *view, dns_stats_t *stats) { +dns_view_setresstats(dns_view_t *view, isc_stats_t *stats) { REQUIRE(DNS_VIEW_VALID(view)); REQUIRE(!view->frozen); REQUIRE(view->resstats == NULL); - dns_stats_attach(stats, &view->resstats); + isc_stats_attach(stats, &view->resstats); } void -dns_view_getresstats(dns_view_t *view, dns_stats_t **statsp) { +dns_view_getresstats(dns_view_t *view, isc_stats_t **statsp) { REQUIRE(DNS_VIEW_VALID(view)); REQUIRE(statsp != NULL && *statsp == NULL); if (view->resstats != NULL) - dns_stats_attach(view->resstats, statsp); + isc_stats_attach(view->resstats, statsp); } void diff --git a/lib/dns/zone.c b/lib/dns/zone.c index 76a84af203..5001ebcb2f 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: zone.c,v 1.485 2009/01/17 23:47:43 tbox Exp $ */ +/* $Id: zone.c,v 1.486 2009/01/27 22:29:59 jinmei Exp $ */ /*! \file */ @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -271,13 +272,13 @@ struct dns_zone { /*% * Statistics counters about zone management. */ - dns_stats_t *stats; + isc_stats_t *stats; /*% * Optional per-zone statistics counters. Counted outside of this * module. */ isc_boolean_t requeststats_on; - dns_stats_t *requeststats; + isc_stats_t *requeststats; isc_uint32_t notifydelay; dns_isselffunc_t isself; void *isselfarg; @@ -645,9 +646,9 @@ static const char *dbargv_default[] = { "rbt" }; * Increment resolver-related statistics counters. Zone must be locked. */ static inline void -inc_stats(dns_zone_t *zone, dns_statscounter_t counter) { +inc_stats(dns_zone_t *zone, isc_statscounter_t counter) { if (zone->stats != NULL) - dns_generalstats_increment(zone->stats, counter); + isc_stats_increment(zone->stats, counter); } /*** @@ -869,9 +870,9 @@ zone_free(dns_zone_t *zone) { isc_mem_free(zone->mctx, zone->journal); zone->journal = NULL; if (zone->stats != NULL) - dns_stats_detach(&zone->stats); + isc_stats_detach(&zone->stats); if (zone->requeststats != NULL) - dns_stats_detach(&zone->requeststats); + isc_stats_detach(&zone->requeststats); if (zone->db != NULL) zone_detachdb(zone); if (zone->acache != NULL) @@ -11099,18 +11100,18 @@ dns_zone_getstatscounters(dns_zone_t *zone) { } void -dns_zone_setstats(dns_zone_t *zone, dns_stats_t *stats) { +dns_zone_setstats(dns_zone_t *zone, isc_stats_t *stats) { REQUIRE(DNS_ZONE_VALID(zone)); REQUIRE(zone->stats == NULL); LOCK_ZONE(zone); zone->stats = NULL; - dns_stats_attach(stats, &zone->stats); + isc_stats_attach(stats, &zone->stats); UNLOCK_ZONE(zone); } void -dns_zone_setrequeststats(dns_zone_t *zone, dns_stats_t *stats) { +dns_zone_setrequeststats(dns_zone_t *zone, isc_stats_t *stats) { REQUIRE(DNS_ZONE_VALID(zone)); LOCK_ZONE(zone); @@ -11118,7 +11119,7 @@ dns_zone_setrequeststats(dns_zone_t *zone, dns_stats_t *stats) { zone->requeststats_on = ISC_FALSE; else if (!zone->requeststats_on && stats != NULL) { if (zone->requeststats == NULL) { - dns_stats_attach(stats, &zone->requeststats); + isc_stats_attach(stats, &zone->requeststats); zone->requeststats_on = ISC_TRUE; } } @@ -11127,7 +11128,7 @@ dns_zone_setrequeststats(dns_zone_t *zone, dns_stats_t *stats) { return; } -dns_stats_t * +isc_stats_t * dns_zone_getrequeststats(dns_zone_t *zone) { /* * We don't lock zone for efficiency reason. This is not catastrophic diff --git a/lib/isc/Makefile.in b/lib/isc/Makefile.in index 67a659b27c..5aa02013d5 100644 --- a/lib/isc/Makefile.in +++ b/lib/isc/Makefile.in @@ -13,7 +13,7 @@ # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # PERFORMANCE OF THIS SOFTWARE. -# $Id: Makefile.in,v 1.97 2008/12/01 03:51:47 marka Exp $ +# $Id: Makefile.in,v 1.98 2009/01/27 22:29:59 jinmei Exp $ srcdir = @srcdir@ VPATH = @srcdir@ @@ -60,7 +60,7 @@ OBJS = @ISC_EXTRA_OBJS@ \ netaddr.@O@ netscope.@O@ ondestroy.@O@ \ parseint.@O@ portset.@O@ quota.@O@ radix.@O@ random.@O@ \ ratelimiter.@O@ refcount.@O@ region.@O@ result.@O@ rwlock.@O@ \ - serial.@O@ sha1.@O@ sha2.@O@ sockaddr.@O@ \ + serial.@O@ sha1.@O@ sha2.@O@ sockaddr.@O@ stats.@O@ \ string.@O@ strtoul.@O@ symtab.@O@ task.@O@ taskpool.@O@ \ timer.@O@ version.@O@ ${UNIXOBJS} ${NLSOBJS} ${THREADOBJS} @@ -75,7 +75,7 @@ SRCS = @ISC_EXTRA_SRCS@ \ netaddr.c netscope.c ondestroy.c \ parseint.c portset.c quota.c radix.c random.c \ ratelimiter.c refcount.c region.c result.c rwlock.c \ - serial.c sha1.c sha2.c sockaddr.c string.c strtoul.c \ + serial.c sha1.c sha2.c sockaddr.c stats.c string.c strtoul.c \ symtab.c task.c taskpool.c timer.c version.c LIBS = @LIBS@ diff --git a/lib/isc/include/isc/socket.h b/lib/isc/include/isc/socket.h index 63a7b395bb..90f6565e27 100644 --- a/lib/isc/include/isc/socket.h +++ b/lib/isc/include/isc/socket.h @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: socket.h,v 1.87 2009/01/18 23:48:14 tbox Exp $ */ +/* $Id: socket.h,v 1.88 2009/01/27 22:29:59 jinmei Exp $ */ #ifndef ISC_SOCKET_H #define ISC_SOCKET_H 1 @@ -84,6 +84,75 @@ ISC_LANG_BEGINDECLS */ #define ISC_SOCKET_REUSEADDRESS 0x01U +/*% + * Statistics counters. Used as isc_statscounter_t values. + */ +enum { + isc_sockstatscounter_udp4open = 0, + isc_sockstatscounter_udp6open = 1, + isc_sockstatscounter_tcp4open = 2, + isc_sockstatscounter_tcp6open = 3, + isc_sockstatscounter_unixopen = 4, + + isc_sockstatscounter_udp4openfail = 5, + isc_sockstatscounter_udp6openfail = 6, + isc_sockstatscounter_tcp4openfail = 7, + isc_sockstatscounter_tcp6openfail = 8, + isc_sockstatscounter_unixopenfail = 9, + + isc_sockstatscounter_udp4close = 10, + isc_sockstatscounter_udp6close = 11, + isc_sockstatscounter_tcp4close = 12, + isc_sockstatscounter_tcp6close = 13, + isc_sockstatscounter_unixclose = 14, + isc_sockstatscounter_fdwatchclose = 15, + + isc_sockstatscounter_udp4bindfail = 16, + isc_sockstatscounter_udp6bindfail = 17, + isc_sockstatscounter_tcp4bindfail = 18, + isc_sockstatscounter_tcp6bindfail = 19, + isc_sockstatscounter_unixbindfail = 20, + isc_sockstatscounter_fdwatchbindfail = 21, + + isc_sockstatscounter_udp4connect = 22, + isc_sockstatscounter_udp6connect = 23, + isc_sockstatscounter_tcp4connect = 24, + isc_sockstatscounter_tcp6connect = 25, + isc_sockstatscounter_unixconnect = 26, + isc_sockstatscounter_fdwatchconnect = 27, + + isc_sockstatscounter_udp4connectfail = 28, + isc_sockstatscounter_udp6connectfail = 29, + isc_sockstatscounter_tcp4connectfail = 30, + isc_sockstatscounter_tcp6connectfail = 31, + isc_sockstatscounter_unixconnectfail = 32, + isc_sockstatscounter_fdwatchconnectfail = 33, + + isc_sockstatscounter_tcp4accept = 34, + isc_sockstatscounter_tcp6accept = 35, + isc_sockstatscounter_unixaccept = 36, + + isc_sockstatscounter_tcp4acceptfail = 37, + isc_sockstatscounter_tcp6acceptfail = 38, + isc_sockstatscounter_unixacceptfail = 39, + + isc_sockstatscounter_udp4sendfail = 40, + isc_sockstatscounter_udp6sendfail = 41, + isc_sockstatscounter_tcp4sendfail = 42, + isc_sockstatscounter_tcp6sendfail = 43, + isc_sockstatscounter_unixsendfail = 44, + isc_sockstatscounter_fdwatchsendfail = 45, + + isc_sockstatscounter_udp4recvfail = 46, + isc_sockstatscounter_udp6recvfail = 47, + isc_sockstatscounter_tcp4recvfail = 48, + isc_sockstatscounter_tcp6recvfail = 49, + isc_sockstatscounter_unixrecvfail = 50, + isc_sockstatscounter_fdwatchrecvfail = 51, + + isc_sockstatscounter_max = 52 +}; + /*** *** Types ***/ @@ -801,6 +870,19 @@ isc_socketmgr_getmaxsockets(isc_socketmgr_t *manager, unsigned int *nsockp); *\li #ISC_R_NOTIMPLEMENTED */ +void +isc_socketmgr_setstats(isc_socketmgr_t *manager, isc_stats_t *stats); +/*%< + * Set a general socket statistics counter set 'stats' for 'manager'. + * + * Requires: + * \li 'manager' is valid, hasn't opened any socket, and doesn't have + * stats already set. + * + *\li stats is a valid statistics supporting socket statistics counters + * (see above). + */ + void isc_socketmgr_destroy(isc_socketmgr_t **managerp); /*%< diff --git a/lib/isc/include/isc/stats.h b/lib/isc/include/isc/stats.h new file mode 100644 index 0000000000..2f1d21bacb --- /dev/null +++ b/lib/isc/include/isc/stats.h @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2008 Internet Systems Consortium, Inc. ("ISC") + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: stats.h,v 1.2 2009/01/27 22:30:00 jinmei Exp $ */ + +#ifndef ISC_STATS_H +#define ISC_STATS_H 1 + +/*! \file isc/stats.h */ + +#include + +/*%< + * Flag(s) for isc_stats_dump(). + */ +#define ISC_STATSDUMP_VERBOSE 0x00000001 /*%< dump 0-value counters */ + +/*%< + * Dump callback type. + */ +typedef void (*isc_stats_dumper_t)(isc_statscounter_t, isc_uint64_t, void *); + +isc_result_t +isc_stats_create(isc_mem_t *mctx, isc_stats_t **statsp, int ncounters); +/*%< + * Create a statistics counter structure of general type. It counts a general + * set of counters indexed by an ID between 0 and ncounters -1. + * + * Requires: + *\li 'mctx' must be a valid memory context. + * + *\li 'statsp' != NULL && '*statsp' == NULL. + * + * Returns: + *\li ISC_R_SUCCESS -- all ok + * + *\li anything else -- failure + */ + +void +isc_stats_attach(isc_stats_t *stats, isc_stats_t **statsp); +/*%< + * Attach to a statistics set. + * + * Requires: + *\li 'stats' is a valid isc_stats_t. + * + *\li 'statsp' != NULL && '*statsp' == NULL + */ + +void +isc_stats_detach(isc_stats_t **statsp); +/*%< + * Detaches from the statistics set. + * + * Requires: + *\li 'statsp' != NULL and '*statsp' is a valid isc_stats_t. + */ + +int +isc_stats_ncounters(isc_stats_t *stats); +/*%< + * Returns the number of counters contained in stats. + * + * Requires: + *\li 'stats' is a valid isc_stats_t. + * + */ + +void +isc_stats_increment(isc_stats_t *stats, isc_statscounter_t counter); +/*%< + * Increment the counter-th counter of stats. + * + * Requires: + *\li 'stats' is a valid isc_stats_t. + * + *\li counter is less than the maximum available ID for the stats specified + * on creation. + */ + +void +isc_stats_decrement(isc_stats_t *stats, isc_statscounter_t counter); +/*%< + * Decrement the counter-th counter of stats. + * + * Requires: + *\li 'stats' is a valid isc_stats_t. + */ + +void +isc_stats_dump(isc_stats_t *stats, isc_stats_dumper_t dump_fn, void *arg, + unsigned int options); +/*%< + * Dump the current statistics counters in a specified way. For each counter + * in stats, dump_fn is called with its current value and the given argument + * arg. By default counters that have a value of 0 is skipped; if options has + * the ISC_STATSDUMP_VERBOSE flag, even such counters are dumped. + * + * Requires: + *\li 'stats' is a valid isc_stats_t. + */ + +ISC_LANG_ENDDECLS + +#endif /* ISC_STATS_H */ diff --git a/lib/isc/include/isc/types.h b/lib/isc/include/isc/types.h index 88c06ff666..cf4b47cfb6 100644 --- a/lib/isc/include/isc/types.h +++ b/lib/isc/include/isc/types.h @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: types.h,v 1.46 2008/06/23 19:41:19 jinmei Exp $ */ +/* $Id: types.h,v 1.47 2009/01/27 22:30:00 jinmei Exp $ */ #ifndef ISC_TYPES_H #define ISC_TYPES_H 1 @@ -82,6 +82,8 @@ typedef struct isc_sockaddr isc_sockaddr_t; /*%< Socket Address */ typedef struct isc_socket isc_socket_t; /*%< Socket */ typedef struct isc_socketevent isc_socketevent_t; /*%< Socket Event */ typedef struct isc_socketmgr isc_socketmgr_t; /*%< Socket Manager */ +typedef struct isc_stats isc_stats_t; /*%< Statistics */ +typedef int isc_statscounter_t; /*%< Statistics Counter */ typedef struct isc_symtab isc_symtab_t; /*%< Symbol Table */ typedef struct isc_task isc_task_t; /*%< Task */ typedef ISC_LIST(isc_task_t) isc_tasklist_t; /*%< Task List */ diff --git a/lib/isc/stats.c b/lib/isc/stats.c new file mode 100644 index 0000000000..c4f483db2d --- /dev/null +++ b/lib/isc/stats.c @@ -0,0 +1,326 @@ +/* + * Copyright (C) 2008 Internet Systems Consortium, Inc. ("ISC") + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: stats.c,v 1.2 2009/01/27 22:29:59 jinmei Exp $ */ + +/*! \file */ + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define ISC_STATS_MAGIC ISC_MAGIC('S', 't', 'a', 't') +#define ISC_STATS_VALID(x) ISC_MAGIC_VALID(x, ISC_STATS_MAGIC) + +#ifndef ISC_STATS_USEMULTIFIELDS +#if defined(ISC_RWLOCK_USEATOMIC) && defined(ISC_PLATFORM_HAVEXADD) && !defined(ISC_PLATFORM_HAVEXADDQ) +#define ISC_STATS_USEMULTIFIELDS 1 +#else +#define ISC_STATS_USEMULTIFIELDS 0 +#endif +#endif /* ISC_STATS_USEMULTIFIELDS */ + +#if ISC_STATS_USEMULTIFIELDS +typedef struct { + isc_uint32_t hi; + isc_uint32_t lo; +} isc_stat_t; +#else +typedef isc_uint64_t isc_stat_t; +#endif + +struct isc_stats { + /*% Unlocked */ + unsigned int magic; + isc_mem_t *mctx; + int ncounters; + + isc_mutex_t lock; + unsigned int references; /* locked by lock */ + + /*% + * Locked by counterlock or unlocked if efficient rwlock is not + * available. + */ +#ifdef ISC_RWLOCK_USEATOMIC + isc_rwlock_t counterlock; +#endif + isc_stat_t *counters; + + /*% + * We don't want to lock the counters while we are dumping, so we first + * copy the current counter values into a local array. This buffer + * will be used as the copy destination. It's allocated on creation + * of the stats structure so that the dump operation won't fail due + * to memory allocation failure. + * XXX: this approach is weird for non-threaded build because the + * additional memory and the copy overhead could be avoided. We prefer + * simplicity here, however, under the assumption that this function + * should be only rarely called. + */ + isc_uint64_t *copiedcounters; +}; + +static isc_result_t +create_stats(isc_mem_t *mctx, int ncounters, isc_stats_t **statsp) { + isc_stats_t *stats; + isc_result_t result = ISC_R_SUCCESS; + + REQUIRE(statsp != NULL && *statsp == NULL); + + stats = isc_mem_get(mctx, sizeof(*stats)); + if (stats == NULL) + return (ISC_R_NOMEMORY); + + result = isc_mutex_init(&stats->lock); + if (result != ISC_R_SUCCESS) + goto clean_stats; + + stats->counters = isc_mem_get(mctx, sizeof(isc_stat_t) * ncounters); + if (stats->counters == NULL) { + result = ISC_R_NOMEMORY; + goto clean_mutex; + } + stats->copiedcounters = isc_mem_get(mctx, + sizeof(isc_uint64_t) * ncounters); + if (stats->copiedcounters == NULL) { + result = ISC_R_NOMEMORY; + goto clean_counters; + } + +#ifdef ISC_RWLOCK_USEATOMIC + result = isc_rwlock_init(&stats->counterlock, 0, 0); + if (result != ISC_R_SUCCESS) + goto clean_copiedcounters; +#endif + + stats->references = 1; + memset(stats->counters, 0, sizeof(isc_stat_t) * ncounters); + stats->mctx = NULL; + isc_mem_attach(mctx, &stats->mctx); + stats->ncounters = ncounters; + stats->magic = ISC_STATS_MAGIC; + + *statsp = stats; + + return (result); + +clean_counters: + isc_mem_put(mctx, stats->counters, sizeof(isc_stat_t) * ncounters); + +#ifdef ISC_RWLOCK_USEATOMIC +clean_copiedcounters: + isc_mem_put(mctx, stats->copiedcounters, + sizeof(isc_stat_t) * ncounters); +#endif + +clean_mutex: + DESTROYLOCK(&stats->lock); + +clean_stats: + isc_mem_put(mctx, stats, sizeof(*stats)); + + return (result); +} + +void +isc_stats_attach(isc_stats_t *stats, isc_stats_t **statsp) { + REQUIRE(ISC_STATS_VALID(stats)); + REQUIRE(statsp != NULL && *statsp == NULL); + + LOCK(&stats->lock); + stats->references++; + UNLOCK(&stats->lock); + + *statsp = stats; +} + +void +isc_stats_detach(isc_stats_t **statsp) { + isc_stats_t *stats; + + REQUIRE(statsp != NULL && ISC_STATS_VALID(*statsp)); + + stats = *statsp; + *statsp = NULL; + + LOCK(&stats->lock); + stats->references--; + UNLOCK(&stats->lock); + + if (stats->references == 0) { + isc_mem_put(stats->mctx, stats->copiedcounters, + sizeof(isc_stat_t) * stats->ncounters); + isc_mem_put(stats->mctx, stats->counters, + sizeof(isc_stat_t) * stats->ncounters); + DESTROYLOCK(&stats->lock); +#ifdef ISC_RWLOCK_USEATOMIC + isc_rwlock_destroy(&stats->counterlock); +#endif + isc_mem_putanddetach(&stats->mctx, stats, sizeof(*stats)); + } +} + +int +isc_stats_ncounters(isc_stats_t *stats) { + REQUIRE(ISC_STATS_VALID(stats)); + + return (stats->ncounters); +} + +static inline void +incrementcounter(isc_stats_t *stats, int counter) { + isc_int32_t prev; + +#ifdef ISC_RWLOCK_USEATOMIC + /* + * We use a "read" lock to prevent other threads from reading the + * counter while we "writing" a counter field. The write access itself + * is protected by the atomic operation. + */ + isc_rwlock_lock(&stats->counterlock, isc_rwlocktype_read); +#endif + +#if ISC_STATS_USEMULTIFIELDS + prev = isc_atomic_xadd((isc_int32_t *)&stats->counters[counter].lo, 1); + /* + * If the lower 32-bit field overflows, increment the higher field. + * Note that it's *theoretically* possible that the lower field + * overlaps again before the higher field is incremented. It doesn't + * matter, however, because we don't read the value until + * isc_stats_copy() is called where the whole process is protected + * by the write (exclusive) lock. + */ + if (prev == (isc_int32_t)0xffffffff) + isc_atomic_xadd((isc_int32_t *)&stats->counters[counter].hi, 1); +#elif defined(ISC_PLATFORM_HAVEXADDQ) + UNUSED(prev); + isc_atomic_xaddq((isc_int64_t *)&stats->counters[counter], 1); +#else + UNUSED(prev); + stats->counters[counter]++; +#endif + +#ifdef ISC_RWLOCK_USEATOMIC + isc_rwlock_unlock(&stats->counterlock, isc_rwlocktype_read); +#endif +} + +static inline void +decrementcounter(isc_stats_t *stats, int counter) { + isc_int32_t prev; + +#ifdef ISC_RWLOCK_USEATOMIC + isc_rwlock_lock(&stats->counterlock, isc_rwlocktype_read); +#endif + +#if ISC_STATS_USEMULTIFIELDS + prev = isc_atomic_xadd((isc_int32_t *)&stats->counters[counter].lo, -1); + if (prev == 0) + isc_atomic_xadd((isc_int32_t *)&stats->counters[counter].hi, + -1); +#elif defined(ISC_PLATFORM_HAVEXADDQ) + UNUSED(prev); + isc_atomic_xaddq((isc_int64_t *)&stats->counters[counter], -1); +#else + UNUSED(prev); + stats->counters[counter]--; +#endif + +#ifdef ISC_RWLOCK_USEATOMIC + isc_rwlock_unlock(&stats->counterlock, isc_rwlocktype_read); +#endif +} + +static void +copy_counters(isc_stats_t *stats) { + int i; + +#ifdef ISC_RWLOCK_USEATOMIC + /* + * We use a "write" lock before "reading" the statistics counters as + * an exclusive lock. + */ + isc_rwlock_lock(&stats->counterlock, isc_rwlocktype_write); +#endif + +#if ISC_STATS_USEMULTIFIELDS + for (i = 0; i < stats->ncounters; i++) { + stats->copiedcounters[i] = + (isc_uint64_t)(stats->counters[i].hi) << 32 | + stats->counters[i].lo; + } +#else + UNUSED(i); + memcpy(stats->copiedcounters, stats->counters, + stats->ncounters * sizeof(isc_stat_t)); +#endif + +#ifdef ISC_RWLOCK_USEATOMIC + isc_rwlock_unlock(&stats->counterlock, isc_rwlocktype_write); +#endif +} + +isc_result_t +isc_stats_create(isc_mem_t *mctx, isc_stats_t **statsp, int ncounters) { + REQUIRE(statsp != NULL && *statsp == NULL); + + return (create_stats(mctx, ncounters, statsp)); +} + +void +isc_stats_increment(isc_stats_t *stats, isc_statscounter_t counter) { + REQUIRE(ISC_STATS_VALID(stats)); + REQUIRE(counter < stats->ncounters); + + incrementcounter(stats, (int)counter); +} + +void +isc_stats_decrement(isc_stats_t *stats, isc_statscounter_t counter) { + REQUIRE(ISC_STATS_VALID(stats)); + REQUIRE(counter < stats->ncounters); + + decrementcounter(stats, (int)counter); +} + +void +isc_stats_dump(isc_stats_t *stats, isc_stats_dumper_t dump_fn, + void *arg, unsigned int options) +{ + int i; + + REQUIRE(ISC_STATS_VALID(stats)); + + copy_counters(stats); + + for (i = 0; i < stats->ncounters; i++) { + if ((options & ISC_STATSDUMP_VERBOSE) == 0 && + stats->copiedcounters[i] == 0) + continue; + dump_fn((isc_statscounter_t)i, stats->copiedcounters[i], arg); + } +} diff --git a/lib/isc/unix/socket.c b/lib/isc/unix/socket.c index 9b6fa7fb4f..5dd4cdc392 100644 --- a/lib/isc/unix/socket.c +++ b/lib/isc/unix/socket.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: socket.c,v 1.315 2009/01/22 23:47:54 tbox Exp $ */ +/* $Id: socket.c,v 1.316 2009/01/27 22:30:00 jinmei Exp $ */ /*! \file */ @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -283,6 +284,7 @@ struct isc_socket { isc_socketmgr_t *manager; isc_mutex_t lock; isc_sockettype_t type; + const isc_statscounter_t *statsindex; /* Locked by socket lock. */ ISC_LINK(isc_socket_t) link; @@ -339,6 +341,7 @@ struct isc_socketmgr { isc_mem_t *mctx; isc_mutex_t lock; isc_mutex_t *fdlock; + isc_stats_t *stats; #ifdef USE_KQUEUE int kqueue_fd; int nevents; @@ -436,6 +439,94 @@ static isc_boolean_t process_ctlfd(isc_socketmgr_t *manager); #define SOCK_DEAD(s) ((s)->references == 0) +/*% + * Shortcut index arrays to get access to statistics counters. + */ +enum { + STATID_OPEN = 0, + STATID_OPENFAIL = 1, + STATID_CLOSE = 2, + STATID_BINDFAIL = 3, + STATID_CONNECTFAIL = 4, + STATID_CONNECT = 5, + STATID_ACCEPTFAIL = 6, + STATID_ACCEPT = 7, + STATID_SENDFAIL = 8, + STATID_RECVFAIL = 9 +}; +static const isc_statscounter_t upd4statsindex[] = { + isc_sockstatscounter_udp4open, + isc_sockstatscounter_udp4openfail, + isc_sockstatscounter_udp4close, + isc_sockstatscounter_udp4bindfail, + isc_sockstatscounter_udp4connectfail, + isc_sockstatscounter_udp4connect, + -1, + -1, + isc_sockstatscounter_udp4sendfail, + isc_sockstatscounter_udp4recvfail +}; +static const isc_statscounter_t upd6statsindex[] = { + isc_sockstatscounter_udp6open, + isc_sockstatscounter_udp6openfail, + isc_sockstatscounter_udp6close, + isc_sockstatscounter_udp6bindfail, + isc_sockstatscounter_udp6connectfail, + isc_sockstatscounter_udp6connect, + -1, + -1, + isc_sockstatscounter_udp6sendfail, + isc_sockstatscounter_udp6recvfail +}; +static const isc_statscounter_t tcp4statsindex[] = { + isc_sockstatscounter_tcp4open, + isc_sockstatscounter_tcp4openfail, + isc_sockstatscounter_tcp4close, + isc_sockstatscounter_tcp4bindfail, + isc_sockstatscounter_tcp4connectfail, + isc_sockstatscounter_tcp4connect, + isc_sockstatscounter_tcp4acceptfail, + isc_sockstatscounter_tcp4accept, + isc_sockstatscounter_tcp4sendfail, + isc_sockstatscounter_tcp4recvfail +}; +static const isc_statscounter_t tcp6statsindex[] = { + isc_sockstatscounter_tcp6open, + isc_sockstatscounter_tcp6openfail, + isc_sockstatscounter_tcp6close, + isc_sockstatscounter_tcp6bindfail, + isc_sockstatscounter_tcp6connectfail, + isc_sockstatscounter_tcp6connect, + isc_sockstatscounter_tcp6acceptfail, + isc_sockstatscounter_tcp6accept, + isc_sockstatscounter_tcp6sendfail, + isc_sockstatscounter_tcp6recvfail +}; +static const isc_statscounter_t unixstatsindex[] = { + isc_sockstatscounter_unixopen, + isc_sockstatscounter_unixopenfail, + isc_sockstatscounter_unixclose, + isc_sockstatscounter_unixbindfail, + isc_sockstatscounter_unixconnectfail, + isc_sockstatscounter_unixconnect, + isc_sockstatscounter_unixacceptfail, + isc_sockstatscounter_unixaccept, + isc_sockstatscounter_unixsendfail, + isc_sockstatscounter_unixrecvfail +}; +static const isc_statscounter_t fdwatchstatsindex[] = { + -1, + -1, + isc_sockstatscounter_fdwatchclose, + isc_sockstatscounter_fdwatchbindfail, + isc_sockstatscounter_fdwatchconnectfail, + isc_sockstatscounter_fdwatchconnect, + -1, + -1, + isc_sockstatscounter_fdwatchsendfail, + isc_sockstatscounter_fdwatchrecvfail +}; + static void manager_log(isc_socketmgr_t *sockmgr, isc_logcategory_t *category, isc_logmodule_t *module, int level, @@ -525,6 +616,17 @@ FIX_IPV6_RECVPKTINFO(isc_socket_t *sock) #define FIX_IPV6_RECVPKTINFO(sock) (void)0 #endif +/*% + * Increment socket-related statistics counters. + */ +static inline void +inc_stats(isc_stats_t *stats, isc_statscounter_t counterid) { + REQUIRE(counterid != -1); + + if (stats != NULL) + isc_stats_increment(stats, counterid); +} + static inline isc_result_t watch_fd(isc_socketmgr_t *manager, int fd, int msg) { isc_result_t result = ISC_R_SUCCESS; @@ -1378,6 +1480,8 @@ doio_recv(isc_socket_t *sock, isc_socketevent_t *dev) { if (recv_errno == _system) { \ if (sock->connected) { \ dev->result = _isc; \ + inc_stats(sock->manager->stats, \ + sock->statsindex[STATID_RECVFAIL]); \ return (DOIO_HARD); \ } \ return (DOIO_SOFT); \ @@ -1385,6 +1489,8 @@ doio_recv(isc_socket_t *sock, isc_socketevent_t *dev) { #define ALWAYS_HARD(_system, _isc) \ if (recv_errno == _system) { \ dev->result = _isc; \ + inc_stats(sock->manager->stats, \ + sock->statsindex[STATID_RECVFAIL]); \ return (DOIO_HARD); \ } @@ -1408,6 +1514,8 @@ doio_recv(isc_socket_t *sock, isc_socketevent_t *dev) { #undef ALWAYS_HARD dev->result = isc__errno2result(recv_errno); + inc_stats(sock->manager->stats, + sock->statsindex[STATID_RECVFAIL]); return (DOIO_HARD); } @@ -1536,6 +1644,8 @@ doio_send(isc_socket_t *sock, isc_socketevent_t *dev) { if (send_errno == _system) { \ if (sock->connected) { \ dev->result = _isc; \ + inc_stats(sock->manager->stats, \ + sock->statsindex[STATID_SENDFAIL]); \ return (DOIO_HARD); \ } \ return (DOIO_SOFT); \ @@ -1543,6 +1653,8 @@ doio_send(isc_socket_t *sock, isc_socketevent_t *dev) { #define ALWAYS_HARD(_system, _isc) \ if (send_errno == _system) { \ dev->result = _isc; \ + inc_stats(sock->manager->stats, \ + sock->statsindex[STATID_SENDFAIL]); \ return (DOIO_HARD); \ } @@ -1577,14 +1689,19 @@ doio_send(isc_socket_t *sock, isc_socketevent_t *dev) { UNEXPECTED_ERROR(__FILE__, __LINE__, "internal_send: %s: %s", addrbuf, strbuf); dev->result = isc__errno2result(send_errno); + inc_stats(sock->manager->stats, + sock->statsindex[STATID_SENDFAIL]); return (DOIO_HARD); } - if (cc == 0) + if (cc == 0) { + inc_stats(sock->manager->stats, + sock->statsindex[STATID_SENDFAIL]); UNEXPECTED_ERROR(__FILE__, __LINE__, - "internal_send: send() %s 0", + "doio_send: send() %s 0", isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL, ISC_MSG_RETURNED, "returned")); + } /* * If we write less than we expected, update counters, poke. @@ -1608,7 +1725,8 @@ doio_send(isc_socket_t *sock, isc_socketevent_t *dev) { * references exist. */ static void -closesocket(isc_socketmgr_t *manager, isc_sockettype_t type, int fd) { +closesocket(isc_socketmgr_t *manager, isc_socket_t *sock, int fd) { + isc_sockettype_t type = sock->type; int lockid = FDLOCK_ID(fd); /* @@ -1637,6 +1755,8 @@ closesocket(isc_socketmgr_t *manager, isc_sockettype_t type, int fd) { } else select_poke(manager, fd, SELECT_POKE_CLOSE); + inc_stats(manager->stats, sock->statsindex[STATID_CLOSE]); + /* * update manager->maxfd here (XXX: this should be implemented more * efficiently) @@ -1685,7 +1805,7 @@ destroy(isc_socket_t **sockp) { if (sock->fd >= 0) { fd = sock->fd; sock->fd = -1; - closesocket(manager, sock->type, fd); + closesocket(manager, sock, fd); } LOCK(&manager->lock); @@ -1723,6 +1843,7 @@ allocate_socket(isc_socketmgr_t *manager, isc_sockettype_t type, sock->manager = manager; sock->type = type; sock->fd = -1; + sock->statsindex = NULL; ISC_LINK_INIT(sock, link); @@ -2145,6 +2266,8 @@ opensocket(isc_socketmgr_t *manager, isc_socket_t *sock) { } #endif /* defined(USE_CMSG) || defined(SO_RCVBUF) */ + inc_stats(manager->stats, sock->statsindex[STATID_OPEN]); + return (ISC_R_SUCCESS); } @@ -2170,9 +2293,26 @@ isc_socket_create(isc_socketmgr_t *manager, int pf, isc_sockettype_t type, if (result != ISC_R_SUCCESS) return (result); + switch (sock->type) { + case isc_sockettype_udp: + sock->statsindex = + (pf == AF_INET) ? upd4statsindex : upd6statsindex; + break; + case isc_sockettype_tcp: + sock->statsindex = + (pf == AF_INET) ? tcp4statsindex : tcp6statsindex; + break; + case isc_sockettype_unix: + sock->statsindex = unixstatsindex; + break; + default: + INSIST(0); + } + sock->pf = pf; result = opensocket(manager, sock); if (result != ISC_R_SUCCESS) { + inc_stats(manager->stats, sock->statsindex[STATID_OPENFAIL]); free_socket(&sock); return (result); } @@ -2282,6 +2422,7 @@ isc_socket_fdwatchcreate(isc_socketmgr_t *manager, int fd, int flags, sock->fdwatchcb = callback; sock->fdwatchflags = flags; sock->fdwatchtask = task; + sock->statsindex = fdwatchstatsindex; sock->references = 1; *socketp = sock; @@ -2391,7 +2532,7 @@ isc_socket_close(isc_socket_t *sock) { isc_sockaddr_any(&sock->peer_address); UNLOCK(&sock->lock); - closesocket(manager, type, fd); + closesocket(manager, sock, fd); return (ISC_R_SUCCESS); } @@ -2797,7 +2938,10 @@ internal_accept(isc_task_t *me, isc_event_t *ev) { dev->newsocket); UNLOCK(&manager->lock); + + inc_stats(manager->stats, sock->statsindex[STATID_ACCEPT]); } else { + inc_stats(manager->stats, sock->statsindex[STATID_ACCEPTFAIL]); dev->newsocket->references--; free_socket(&dev->newsocket); } @@ -2815,6 +2959,8 @@ internal_accept(isc_task_t *me, isc_event_t *ev) { soft_error: select_poke(sock->manager, sock->fd, SELECT_POKE_ACCEPT); UNLOCK(&sock->lock); + + inc_stats(manager->stats, sock->statsindex[STATID_ACCEPTFAIL]); return; } @@ -3676,6 +3822,7 @@ isc_socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp, result = ISC_R_NOMEMORY; goto free_manager; } + manager->stats = NULL; manager->magic = SOCKET_MANAGER_MAGIC; manager->mctx = NULL; @@ -3812,6 +3959,16 @@ isc_socketmgr_getmaxsockets(isc_socketmgr_t *manager, unsigned int *nsockp) { return (ISC_R_SUCCESS); } +void +isc_socketmgr_setstats(isc_socketmgr_t *manager, isc_stats_t *stats) { + REQUIRE(VALID_MANAGER(manager)); + REQUIRE(ISC_LIST_EMPTY(manager->socklist)); + REQUIRE(manager->stats == NULL); + REQUIRE(isc_stats_ncounters(stats) == isc_sockstatscounter_max); + + isc_stats_attach(stats, &manager->stats); +} + void isc_socketmgr_destroy(isc_socketmgr_t **managerp) { isc_socketmgr_t *manager; @@ -3900,6 +4057,9 @@ isc_socketmgr_destroy(isc_socketmgr_t **managerp) { isc_mem_put(manager->mctx, manager->fdstate, manager->maxsocks * sizeof(int)); + if (manager->stats != NULL) + isc_stats_detach(&manager->stats); + if (manager->fdlock != NULL) { for (i = 0; i < FDLOCK_COUNT; i++) DESTROYLOCK(&manager->fdlock[i]); @@ -4510,6 +4670,9 @@ isc_socket_bind(isc_socket_t *sock, isc_sockaddr_t *sockaddr, bind_socket: #endif if (bind(sock->fd, &sockaddr->type.sa, sockaddr->length) < 0) { + inc_stats(sock->manager->stats, + sock->statsindex[STATID_BINDFAIL]); + UNLOCK(&sock->lock); switch (errno) { case EACCES: @@ -4654,6 +4817,7 @@ isc_socket_accept(isc_socket_t *sock, */ isc_task_attach(task, &ntask); nsock->references++; + nsock->statsindex = sock->statsindex; dev->ev_sender = ntask; dev->newsocket = nsock; @@ -4755,6 +4919,8 @@ isc_socket_connect(isc_socket_t *sock, isc_sockaddr_t *addr, UNEXPECTED_ERROR(__FILE__, __LINE__, "%d/%s", errno, strbuf); UNLOCK(&sock->lock); + inc_stats(sock->manager->stats, + sock->statsindex[STATID_CONNECTFAIL]); isc_event_free(ISC_EVENT_PTR(&dev)); return (ISC_R_UNEXPECTED); @@ -4763,6 +4929,8 @@ isc_socket_connect(isc_socket_t *sock, isc_sockaddr_t *addr, isc_task_send(task, ISC_EVENT_PTR(&dev)); UNLOCK(&sock->lock); + inc_stats(sock->manager->stats, + sock->statsindex[STATID_CONNECTFAIL]); return (ISC_R_SUCCESS); } @@ -4777,6 +4945,10 @@ isc_socket_connect(isc_socket_t *sock, isc_sockaddr_t *addr, isc_task_send(task, ISC_EVENT_PTR(&dev)); UNLOCK(&sock->lock); + + inc_stats(sock->manager->stats, + sock->statsindex[STATID_CONNECT]); + return (ISC_R_SUCCESS); } @@ -4875,6 +5047,9 @@ internal_connect(isc_task_t *me, isc_event_t *ev) { return; } + inc_stats(sock->manager->stats, + sock->statsindex[STATID_CONNECTFAIL]); + /* * Translate other errors into ISC_R_* flavors. */ @@ -4905,6 +5080,8 @@ internal_connect(isc_task_t *me, isc_event_t *ev) { peerbuf, strbuf); } } else { + inc_stats(sock->manager->stats, + sock->statsindex[STATID_CONNECT]); dev->result = ISC_R_SUCCESS; sock->connected = 1; sock->bound = 1; diff --git a/lib/isc/win32/libisc.def b/lib/isc/win32/libisc.def index 065a6024f6..f27b02ac6f 100644 --- a/lib/isc/win32/libisc.def +++ b/lib/isc/win32/libisc.def @@ -444,6 +444,14 @@ isc_socketmgr_create isc_socketmgr_create2 isc_socketmgr_destroy isc_socketmgr_getmaxsockets +isc_socketmgr_setstats +isc_stats_create +isc_stats_attach +isc_stats_detach +isc_stats_ncounters +isc_stats_increment +isc_stats_decrement +isc_stats_dump isc_stdio_close isc_stdio_flush isc_stdio_open diff --git a/lib/isc/win32/socket.c b/lib/isc/win32/socket.c index 4ba15a7f04..ac9503c7a3 100644 --- a/lib/isc/win32/socket.c +++ b/lib/isc/win32/socket.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: socket.c,v 1.73 2009/01/18 00:27:17 fdupont Exp $ */ +/* $Id: socket.c,v 1.74 2009/01/27 22:30:00 jinmei Exp $ */ /* This code uses functions which are only available on Server 2003 and * higher, and Windows XP and higher. @@ -65,6 +65,7 @@ #include #include #include +#include #include #include #include @@ -318,6 +319,8 @@ struct isc_socketmgr { unsigned int magic; isc_mem_t *mctx; isc_mutex_t lock; + isc_stats_t *stats; + /* Locked by manager lock. */ ISC_LIST(isc_socket_t) socklist; isc_boolean_t bShutdown; @@ -2455,6 +2458,7 @@ isc_socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp, manager->magic = SOCKET_MANAGER_MAGIC; manager->mctx = NULL; + manager->stats = NULL; ISC_LIST_INIT(manager->socklist); result = isc_mutex_init(&manager->lock); if (result != ISC_R_SUCCESS) { @@ -2492,6 +2496,16 @@ isc_socketmgr_getmaxsockets(isc_socketmgr_t *manager, unsigned int *nsockp) { return (ISC_R_NOTIMPLEMENTED); } +void +isc_socketmgr_setstats(isc_socketmgr_t *manager, isc_stats_t *stats) { + REQUIRE(VALID_MANAGER(manager)); + REQUIRE(ISC_LIST_EMPTY(manager->socklist)); + REQUIRE(manager->stats == NULL); + REQUIRE(isc_stats_ncounters(stats) == isc_sockstatscounter_max); + + isc_stats_attach(stats, &manager->stats); +} + void isc_socketmgr_destroy(isc_socketmgr_t **managerp) { isc_socketmgr_t *manager; @@ -2548,6 +2562,8 @@ isc_socketmgr_destroy(isc_socketmgr_t **managerp) { (void)isc_condition_destroy(&manager->shutdown_ok); DESTROYLOCK(&manager->lock); + if (manager->stats != NULL) + isc_stats_detach(&manager->stats); manager->magic = 0; mctx= manager->mctx; isc_mem_put(mctx, manager, sizeof(*manager));