]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Use isc_histo for the message size statistics
authorTony Finch <fanf@isc.org>
Thu, 16 Mar 2023 14:31:46 +0000 (14:31 +0000)
committerTony Finch <dot@dotat.at>
Mon, 3 Apr 2023 11:08:05 +0000 (12:08 +0100)
This should have no functional effects.

The message size stats are specified by RSSAC002 so it's best not
to mess around with how they appear in the statschannel. But it's
worth changing the implementation to use general-purpose histograms,
to reduce code size and benefit from sharded counters.

bin/named/statschannel.c
lib/dns/include/dns/stats.h
lib/ns/client.c
lib/ns/include/ns/server.h
lib/ns/server.c

index 7c924b1f86fac223dfd3753e3b07c28a8caba6d8..7b595ec2678c9a7974ad9d2d0bc8a3436f6ae16e 100644 (file)
@@ -228,6 +228,30 @@ set_desc(int counter, int maxcounter, const char *fdesc, const char **fdescs,
 #endif /* if defined(EXTENDED_STATS) */
 }
 
+static const char *
+get_histo_desc(const char *prefix, int i, int inf, bool ext) {
+       static char buf[(DNS_SIZEHISTO_MAXIN + DNS_SIZEHISTO_MAXOUT) * 80];
+       static size_t used = 0;
+       char *desc = buf + used;
+       size_t space = sizeof(buf) - used;
+       int min = DNS_SIZEHISTO_QUANTUM * i;
+       int max = DNS_SIZEHISTO_QUANTUM * (i + 1) - 1;
+       int len = 0;
+
+       if (!ext && i < inf) {
+               len = snprintf(desc, space, "%s %u-%u bytes", prefix, min, max);
+       } else if (!ext && i >= inf) {
+               len = snprintf(desc, space, "%s %u+ bytes", prefix, min);
+       } else if (ext && i < inf) {
+               len = snprintf(desc, space, "%u-%u", min, max);
+       } else if (ext && i >= inf) {
+               len = snprintf(desc, space, "%u+", min);
+       }
+       INSIST(0 < len && (size_t)len < space);
+       used += len + 1;
+       return (desc);
+}
+
 static void
 init_desc(void) {
        int i;
@@ -755,575 +779,49 @@ init_desc(void) {
 #endif /* if defined(EXTENDED_STATS) */
 
        /* Initialize traffic size statistics */
-       for (i = 0; i < dns_sizecounter_in_max; i++) {
-               udpinsizestats_desc[i] = NULL;
-               tcpinsizestats_desc[i] = NULL;
-#if defined(EXTENDED_STATS)
-               udpinsizestats_xmldesc[i] = NULL;
-               tcpinsizestats_xmldesc[i] = NULL;
-#endif /* if defined(EXTENDED_STATS) */
-       }
-       for (i = 0; i < dns_sizecounter_out_max; i++) {
-               udpoutsizestats_desc[i] = NULL;
-               tcpoutsizestats_desc[i] = NULL;
+
+       for (i = 0; i < DNS_SIZEHISTO_MAXOUT; i++) {
+               udpoutsizestats_index[i] = i;
+               tcpoutsizestats_index[i] = i;
+               udpoutsizestats_desc[i] = get_histo_desc(
+                       "responses sent", i, DNS_SIZEHISTO_MAXOUT, false);
+               tcpoutsizestats_desc[i] = udpoutsizestats_desc[i];
 #if defined(EXTENDED_STATS)
-               udpoutsizestats_xmldesc[i] = NULL;
-               tcpoutsizestats_xmldesc[i] = NULL;
+               udpoutsizestats_xmldesc[i] = get_histo_desc(
+                       "responses sent", i, DNS_SIZEHISTO_MAXOUT, true);
+               tcpoutsizestats_xmldesc[i] = udpoutsizestats_xmldesc[i];
 #endif /* if defined(EXTENDED_STATS) */
        }
 
-#define SET_SIZESTATDESC(counterid, desc, xmldesc, inout)       \
-       do {                                                    \
-               set_desc(dns_sizecounter_##inout##_##counterid, \
-                        dns_sizecounter_##inout##_max, desc,   \
-                        udp##inout##sizestats_desc, xmldesc,   \
-                        udp##inout##sizestats_xmldesc);        \
-               set_desc(dns_sizecounter_##inout##_##counterid, \
-                        dns_sizecounter_##inout##_max, desc,   \
-                        tcp##inout##sizestats_desc, xmldesc,   \
-                        tcp##inout##sizestats_xmldesc);        \
-               udp##inout##sizestats_index[i] =                \
-                       dns_sizecounter_##inout##_##counterid;  \
-               tcp##inout##sizestats_index[i] =                \
-                       dns_sizecounter_##inout##_##counterid;  \
-               i++;                                            \
-       } while (0)
-
-       i = 0;
-       SET_SIZESTATDESC(0, "requests received 0-15 bytes", "0-15", in);
-       SET_SIZESTATDESC(16, "requests received 16-31 bytes", "16-31", in);
-       SET_SIZESTATDESC(32, "requests received 32-47 bytes", "32-47", in);
-       SET_SIZESTATDESC(48, "requests received 48-63 bytes", "48-63", in);
-       SET_SIZESTATDESC(64, "requests received 64-79 bytes", "64-79", in);
-       SET_SIZESTATDESC(80, "requests received 80-95 bytes", "80-95", in);
-       SET_SIZESTATDESC(96, "requests received 96-111 bytes", "96-111", in);
-       SET_SIZESTATDESC(112, "requests received 112-127 bytes", "112-127", in);
-       SET_SIZESTATDESC(128, "requests received 128-143 bytes", "128-143", in);
-       SET_SIZESTATDESC(144, "requests received 144-159 bytes", "144-159", in);
-       SET_SIZESTATDESC(160, "requests received 160-175 bytes", "160-175", in);
-       SET_SIZESTATDESC(176, "requests received 176-191 bytes", "176-191", in);
-       SET_SIZESTATDESC(192, "requests received 192-207 bytes", "192-207", in);
-       SET_SIZESTATDESC(208, "requests received 208-223 bytes", "208-223", in);
-       SET_SIZESTATDESC(224, "requests received 224-239 bytes", "224-239", in);
-       SET_SIZESTATDESC(240, "requests received 240-255 bytes", "240-255", in);
-       SET_SIZESTATDESC(256, "requests received 256-271 bytes", "256-271", in);
-       SET_SIZESTATDESC(272, "requests received 272-287 bytes", "272-287", in);
-       SET_SIZESTATDESC(288, "requests received 288+ bytes", "288+", in);
-       INSIST(i == dns_sizecounter_in_max);
-
-       i = 0;
-       SET_SIZESTATDESC(0, "responses sent 0-15 bytes", "0-15", out);
-       SET_SIZESTATDESC(16, "responses sent 16-31 bytes", "16-31", out);
-       SET_SIZESTATDESC(32, "responses sent 32-47 bytes", "32-47", out);
-       SET_SIZESTATDESC(48, "responses sent 48-63 bytes", "48-63", out);
-       SET_SIZESTATDESC(64, "responses sent 64-79 bytes", "64-79", out);
-       SET_SIZESTATDESC(80, "responses sent 80-95 bytes", "80-95", out);
-       SET_SIZESTATDESC(96, "responses sent 96-111 bytes", "96-111", out);
-       SET_SIZESTATDESC(112, "responses sent 112-127 bytes", "112-127", out);
-       SET_SIZESTATDESC(128, "responses sent 128-143 bytes", "128-143", out);
-       SET_SIZESTATDESC(144, "responses sent 144-159 bytes", "144-159", out);
-       SET_SIZESTATDESC(160, "responses sent 160-175 bytes", "160-175", out);
-       SET_SIZESTATDESC(176, "responses sent 176-191 bytes", "176-191", out);
-       SET_SIZESTATDESC(192, "responses sent 192-207 bytes", "192-207", out);
-       SET_SIZESTATDESC(208, "responses sent 208-223 bytes", "208-223", out);
-       SET_SIZESTATDESC(224, "responses sent 224-239 bytes", "224-239", out);
-       SET_SIZESTATDESC(240, "responses sent 240-255 bytes", "240-255", out);
-       SET_SIZESTATDESC(256, "responses sent 256-271 bytes", "256-271", out);
-       SET_SIZESTATDESC(272, "responses sent 272-287 bytes", "272-287", out);
-       SET_SIZESTATDESC(288, "responses sent 288-303 bytes", "288-303", out);
-       SET_SIZESTATDESC(304, "responses sent 304-319 bytes", "304-319", out);
-       SET_SIZESTATDESC(320, "responses sent 320-335 bytes", "320-335", out);
-       SET_SIZESTATDESC(336, "responses sent 336-351 bytes", "336-351", out);
-       SET_SIZESTATDESC(352, "responses sent 352-367 bytes", "352-367", out);
-       SET_SIZESTATDESC(368, "responses sent 368-383 bytes", "368-383", out);
-       SET_SIZESTATDESC(384, "responses sent 384-399 bytes", "384-399", out);
-       SET_SIZESTATDESC(400, "responses sent 400-415 bytes", "400-415", out);
-       SET_SIZESTATDESC(416, "responses sent 416-431 bytes", "416-431", out);
-       SET_SIZESTATDESC(432, "responses sent 432-447 bytes", "432-447", out);
-       SET_SIZESTATDESC(448, "responses sent 448-463 bytes", "448-463", out);
-       SET_SIZESTATDESC(464, "responses sent 464-479 bytes", "464-479", out);
-       SET_SIZESTATDESC(480, "responses sent 480-495 bytes", "480-495", out);
-       SET_SIZESTATDESC(496, "responses sent 496-511 bytes", "496-511", out);
-       SET_SIZESTATDESC(512, "responses sent 512-527 bytes", "512-527", out);
-       SET_SIZESTATDESC(528, "responses sent 528-543 bytes", "528-543", out);
-       SET_SIZESTATDESC(544, "responses sent 544-559 bytes", "544-559", out);
-       SET_SIZESTATDESC(560, "responses sent 560-575 bytes", "560-575", out);
-       SET_SIZESTATDESC(576, "responses sent 576-591 bytes", "576-591", out);
-       SET_SIZESTATDESC(592, "responses sent 592-607 bytes", "592-607", out);
-       SET_SIZESTATDESC(608, "responses sent 608-623 bytes", "608-623", out);
-       SET_SIZESTATDESC(624, "responses sent 624-639 bytes", "624-639", out);
-       SET_SIZESTATDESC(640, "responses sent 640-655 bytes", "640-655", out);
-       SET_SIZESTATDESC(656, "responses sent 656-671 bytes", "656-671", out);
-       SET_SIZESTATDESC(672, "responses sent 672-687 bytes", "672-687", out);
-       SET_SIZESTATDESC(688, "responses sent 688-703 bytes", "688-703", out);
-       SET_SIZESTATDESC(704, "responses sent 704-719 bytes", "704-719", out);
-       SET_SIZESTATDESC(720, "responses sent 720-735 bytes", "720-735", out);
-       SET_SIZESTATDESC(736, "responses sent 736-751 bytes", "736-751", out);
-       SET_SIZESTATDESC(752, "responses sent 752-767 bytes", "752-767", out);
-       SET_SIZESTATDESC(768, "responses sent 768-783 bytes", "768-783", out);
-       SET_SIZESTATDESC(784, "responses sent 784-799 bytes", "784-799", out);
-       SET_SIZESTATDESC(800, "responses sent 800-815 bytes", "800-815", out);
-       SET_SIZESTATDESC(816, "responses sent 816-831 bytes", "816-831", out);
-       SET_SIZESTATDESC(832, "responses sent 832-847 bytes", "832-847", out);
-       SET_SIZESTATDESC(848, "responses sent 848-863 bytes", "848-863", out);
-       SET_SIZESTATDESC(864, "responses sent 864-879 bytes", "864-879", out);
-       SET_SIZESTATDESC(880, "responses sent 880-895 bytes", "880-895", out);
-       SET_SIZESTATDESC(896, "responses sent 896-911 bytes", "896-911", out);
-       SET_SIZESTATDESC(912, "responses sent 912-927 bytes", "912-927", out);
-       SET_SIZESTATDESC(928, "responses sent 928-943 bytes", "928-943", out);
-       SET_SIZESTATDESC(944, "responses sent 944-959 bytes", "944-959", out);
-       SET_SIZESTATDESC(960, "responses sent 960-975 bytes", "960-975", out);
-       SET_SIZESTATDESC(976, "responses sent 976-991 bytes", "976-991", out);
-       SET_SIZESTATDESC(992, "responses sent 992-1007 bytes", "992-1007", out);
-       SET_SIZESTATDESC(1008, "responses sent 1008-1023 bytes", "1008-1023",
-                        out);
-       SET_SIZESTATDESC(1024, "responses sent 1024-1039 bytes", "1024-1039",
-                        out);
-       SET_SIZESTATDESC(1040, "responses sent 1040-1055 bytes", "1040-1055",
-                        out);
-       SET_SIZESTATDESC(1056, "responses sent 1056-1071 bytes", "1056-1071",
-                        out);
-       SET_SIZESTATDESC(1072, "responses sent 1072-1087 bytes", "1072-1087",
-                        out);
-       SET_SIZESTATDESC(1088, "responses sent 1088-1103 bytes", "1088-1103",
-                        out);
-       SET_SIZESTATDESC(1104, "responses sent 1104-1119 bytes", "1104-1119",
-                        out);
-       SET_SIZESTATDESC(1120, "responses sent 1120-1135 bytes", "1120-1135",
-                        out);
-       SET_SIZESTATDESC(1136, "responses sent 1136-1151 bytes", "1136-1151",
-                        out);
-       SET_SIZESTATDESC(1152, "responses sent 1152-1167 bytes", "1152-1167",
-                        out);
-       SET_SIZESTATDESC(1168, "responses sent 1168-1183 bytes", "1168-1183",
-                        out);
-       SET_SIZESTATDESC(1184, "responses sent 1184-1199 bytes", "1184-1199",
-                        out);
-       SET_SIZESTATDESC(1200, "responses sent 1200-1215 bytes", "1200-1215",
-                        out);
-       SET_SIZESTATDESC(1216, "responses sent 1216-1231 bytes", "1216-1231",
-                        out);
-       SET_SIZESTATDESC(1232, "responses sent 1232-1247 bytes", "1232-1247",
-                        out);
-       SET_SIZESTATDESC(1248, "responses sent 1248-1263 bytes", "1248-1263",
-                        out);
-       SET_SIZESTATDESC(1264, "responses sent 1264-1279 bytes", "1264-1279",
-                        out);
-       SET_SIZESTATDESC(1280, "responses sent 1280-1295 bytes", "1280-1295",
-                        out);
-       SET_SIZESTATDESC(1296, "responses sent 1296-1311 bytes", "1296-1311",
-                        out);
-       SET_SIZESTATDESC(1312, "responses sent 1312-1327 bytes", "1312-1327",
-                        out);
-       SET_SIZESTATDESC(1328, "responses sent 1328-1343 bytes", "1328-1343",
-                        out);
-       SET_SIZESTATDESC(1344, "responses sent 1344-1359 bytes", "1344-1359",
-                        out);
-       SET_SIZESTATDESC(1360, "responses sent 1360-1375 bytes", "1360-1375",
-                        out);
-       SET_SIZESTATDESC(1376, "responses sent 1376-1391 bytes", "1376-1391",
-                        out);
-       SET_SIZESTATDESC(1392, "responses sent 1392-1407 bytes", "1392-1407",
-                        out);
-       SET_SIZESTATDESC(1408, "responses sent 1408-1423 bytes", "1408-1423",
-                        out);
-       SET_SIZESTATDESC(1424, "responses sent 1424-1439 bytes", "1424-1439",
-                        out);
-       SET_SIZESTATDESC(1440, "responses sent 1440-1455 bytes", "1440-1455",
-                        out);
-       SET_SIZESTATDESC(1456, "responses sent 1456-1471 bytes", "1456-1471",
-                        out);
-       SET_SIZESTATDESC(1472, "responses sent 1472-1487 bytes", "1472-1487",
-                        out);
-       SET_SIZESTATDESC(1488, "responses sent 1488-1503 bytes", "1488-1503",
-                        out);
-       SET_SIZESTATDESC(1504, "responses sent 1504-1519 bytes", "1504-1519",
-                        out);
-       SET_SIZESTATDESC(1520, "responses sent 1520-1535 bytes", "1520-1535",
-                        out);
-       SET_SIZESTATDESC(1536, "responses sent 1536-1551 bytes", "1536-1551",
-                        out);
-       SET_SIZESTATDESC(1552, "responses sent 1552-1567 bytes", "1552-1567",
-                        out);
-       SET_SIZESTATDESC(1568, "responses sent 1568-1583 bytes", "1568-1583",
-                        out);
-       SET_SIZESTATDESC(1584, "responses sent 1584-1599 bytes", "1584-1599",
-                        out);
-       SET_SIZESTATDESC(1600, "responses sent 1600-1615 bytes", "1600-1615",
-                        out);
-       SET_SIZESTATDESC(1616, "responses sent 1616-1631 bytes", "1616-1631",
-                        out);
-       SET_SIZESTATDESC(1632, "responses sent 1632-1647 bytes", "1632-1647",
-                        out);
-       SET_SIZESTATDESC(1648, "responses sent 1648-1663 bytes", "1648-1663",
-                        out);
-       SET_SIZESTATDESC(1664, "responses sent 1664-1679 bytes", "1664-1679",
-                        out);
-       SET_SIZESTATDESC(1680, "responses sent 1680-1695 bytes", "1680-1695",
-                        out);
-       SET_SIZESTATDESC(1696, "responses sent 1696-1711 bytes", "1696-1711",
-                        out);
-       SET_SIZESTATDESC(1712, "responses sent 1712-1727 bytes", "1712-1727",
-                        out);
-       SET_SIZESTATDESC(1728, "responses sent 1728-1743 bytes", "1728-1743",
-                        out);
-       SET_SIZESTATDESC(1744, "responses sent 1744-1759 bytes", "1744-1759",
-                        out);
-       SET_SIZESTATDESC(1760, "responses sent 1760-1775 bytes", "1760-1775",
-                        out);
-       SET_SIZESTATDESC(1776, "responses sent 1776-1791 bytes", "1776-1791",
-                        out);
-       SET_SIZESTATDESC(1792, "responses sent 1792-1807 bytes", "1792-1807",
-                        out);
-       SET_SIZESTATDESC(1808, "responses sent 1808-1823 bytes", "1808-1823",
-                        out);
-       SET_SIZESTATDESC(1824, "responses sent 1824-1839 bytes", "1824-1839",
-                        out);
-       SET_SIZESTATDESC(1840, "responses sent 1840-1855 bytes", "1840-1855",
-                        out);
-       SET_SIZESTATDESC(1856, "responses sent 1856-1871 bytes", "1856-1871",
-                        out);
-       SET_SIZESTATDESC(1872, "responses sent 1872-1887 bytes", "1872-1887",
-                        out);
-       SET_SIZESTATDESC(1888, "responses sent 1888-1903 bytes", "1888-1903",
-                        out);
-       SET_SIZESTATDESC(1904, "responses sent 1904-1919 bytes", "1904-1919",
-                        out);
-       SET_SIZESTATDESC(1920, "responses sent 1920-1935 bytes", "1920-1935",
-                        out);
-       SET_SIZESTATDESC(1936, "responses sent 1936-1951 bytes", "1936-1951",
-                        out);
-       SET_SIZESTATDESC(1952, "responses sent 1952-1967 bytes", "1952-1967",
-                        out);
-       SET_SIZESTATDESC(1968, "responses sent 1968-1983 bytes", "1968-1983",
-                        out);
-       SET_SIZESTATDESC(1984, "responses sent 1984-1999 bytes", "1984-1999",
-                        out);
-       SET_SIZESTATDESC(2000, "responses sent 2000-2015 bytes", "2000-2015",
-                        out);
-       SET_SIZESTATDESC(2016, "responses sent 2016-2031 bytes", "2016-2031",
-                        out);
-       SET_SIZESTATDESC(2032, "responses sent 2032-2047 bytes", "2032-2047",
-                        out);
-       SET_SIZESTATDESC(2048, "responses sent 2048-2063 bytes", "2048-2063",
-                        out);
-       SET_SIZESTATDESC(2064, "responses sent 2064-2079 bytes", "2064-2079",
-                        out);
-       SET_SIZESTATDESC(2080, "responses sent 2080-2095 bytes", "2080-2095",
-                        out);
-       SET_SIZESTATDESC(2096, "responses sent 2096-2111 bytes", "2096-2111",
-                        out);
-       SET_SIZESTATDESC(2112, "responses sent 2112-2127 bytes", "2112-2127",
-                        out);
-       SET_SIZESTATDESC(2128, "responses sent 2128-2143 bytes", "2128-2143",
-                        out);
-       SET_SIZESTATDESC(2144, "responses sent 2144-2159 bytes", "2144-2159",
-                        out);
-       SET_SIZESTATDESC(2160, "responses sent 2160-2175 bytes", "2160-2175",
-                        out);
-       SET_SIZESTATDESC(2176, "responses sent 2176-2191 bytes", "2176-2191",
-                        out);
-       SET_SIZESTATDESC(2192, "responses sent 2192-2207 bytes", "2192-2207",
-                        out);
-       SET_SIZESTATDESC(2208, "responses sent 2208-2223 bytes", "2208-2223",
-                        out);
-       SET_SIZESTATDESC(2224, "responses sent 2224-2239 bytes", "2224-2239",
-                        out);
-       SET_SIZESTATDESC(2240, "responses sent 2240-2255 bytes", "2240-2255",
-                        out);
-       SET_SIZESTATDESC(2256, "responses sent 2256-2271 bytes", "2256-2271",
-                        out);
-       SET_SIZESTATDESC(2272, "responses sent 2272-2287 bytes", "2272-2287",
-                        out);
-       SET_SIZESTATDESC(2288, "responses sent 2288-2303 bytes", "2288-2303",
-                        out);
-       SET_SIZESTATDESC(2304, "responses sent 2304-2319 bytes", "2304-2319",
-                        out);
-       SET_SIZESTATDESC(2320, "responses sent 2320-2335 bytes", "2320-2335",
-                        out);
-       SET_SIZESTATDESC(2336, "responses sent 2336-2351 bytes", "2336-2351",
-                        out);
-       SET_SIZESTATDESC(2352, "responses sent 2352-2367 bytes", "2352-2367",
-                        out);
-       SET_SIZESTATDESC(2368, "responses sent 2368-2383 bytes", "2368-2383",
-                        out);
-       SET_SIZESTATDESC(2384, "responses sent 2384-2399 bytes", "2384-2399",
-                        out);
-       SET_SIZESTATDESC(2400, "responses sent 2400-2415 bytes", "2400-2415",
-                        out);
-       SET_SIZESTATDESC(2416, "responses sent 2416-2431 bytes", "2416-2431",
-                        out);
-       SET_SIZESTATDESC(2432, "responses sent 2432-2447 bytes", "2432-2447",
-                        out);
-       SET_SIZESTATDESC(2448, "responses sent 2448-2463 bytes", "2448-2463",
-                        out);
-       SET_SIZESTATDESC(2464, "responses sent 2464-2479 bytes", "2464-2479",
-                        out);
-       SET_SIZESTATDESC(2480, "responses sent 2480-2495 bytes", "2480-2495",
-                        out);
-       SET_SIZESTATDESC(2496, "responses sent 2496-2511 bytes", "2496-2511",
-                        out);
-       SET_SIZESTATDESC(2512, "responses sent 2512-2527 bytes", "2512-2527",
-                        out);
-       SET_SIZESTATDESC(2528, "responses sent 2528-2543 bytes", "2528-2543",
-                        out);
-       SET_SIZESTATDESC(2544, "responses sent 2544-2559 bytes", "2544-2559",
-                        out);
-       SET_SIZESTATDESC(2560, "responses sent 2560-2575 bytes", "2560-2575",
-                        out);
-       SET_SIZESTATDESC(2576, "responses sent 2576-2591 bytes", "2576-2591",
-                        out);
-       SET_SIZESTATDESC(2592, "responses sent 2592-2607 bytes", "2592-2607",
-                        out);
-       SET_SIZESTATDESC(2608, "responses sent 2608-2623 bytes", "2608-2623",
-                        out);
-       SET_SIZESTATDESC(2624, "responses sent 2624-2639 bytes", "2624-2639",
-                        out);
-       SET_SIZESTATDESC(2640, "responses sent 2640-2655 bytes", "2640-2655",
-                        out);
-       SET_SIZESTATDESC(2656, "responses sent 2656-2671 bytes", "2656-2671",
-                        out);
-       SET_SIZESTATDESC(2672, "responses sent 2672-2687 bytes", "2672-2687",
-                        out);
-       SET_SIZESTATDESC(2688, "responses sent 2688-2703 bytes", "2688-2703",
-                        out);
-       SET_SIZESTATDESC(2704, "responses sent 2704-2719 bytes", "2704-2719",
-                        out);
-       SET_SIZESTATDESC(2720, "responses sent 2720-2735 bytes", "2720-2735",
-                        out);
-       SET_SIZESTATDESC(2736, "responses sent 2736-2751 bytes", "2736-2751",
-                        out);
-       SET_SIZESTATDESC(2752, "responses sent 2752-2767 bytes", "2752-2767",
-                        out);
-       SET_SIZESTATDESC(2768, "responses sent 2768-2783 bytes", "2768-2783",
-                        out);
-       SET_SIZESTATDESC(2784, "responses sent 2784-2799 bytes", "2784-2799",
-                        out);
-       SET_SIZESTATDESC(2800, "responses sent 2800-2815 bytes", "2800-2815",
-                        out);
-       SET_SIZESTATDESC(2816, "responses sent 2816-2831 bytes", "2816-2831",
-                        out);
-       SET_SIZESTATDESC(2832, "responses sent 2832-2847 bytes", "2832-2847",
-                        out);
-       SET_SIZESTATDESC(2848, "responses sent 2848-2863 bytes", "2848-2863",
-                        out);
-       SET_SIZESTATDESC(2864, "responses sent 2864-2879 bytes", "2864-2879",
-                        out);
-       SET_SIZESTATDESC(2880, "responses sent 2880-2895 bytes", "2880-2895",
-                        out);
-       SET_SIZESTATDESC(2896, "responses sent 2896-2911 bytes", "2896-2911",
-                        out);
-       SET_SIZESTATDESC(2912, "responses sent 2912-2927 bytes", "2912-2927",
-                        out);
-       SET_SIZESTATDESC(2928, "responses sent 2928-2943 bytes", "2928-2943",
-                        out);
-       SET_SIZESTATDESC(2944, "responses sent 2944-2959 bytes", "2944-2959",
-                        out);
-       SET_SIZESTATDESC(2960, "responses sent 2960-2975 bytes", "2960-2975",
-                        out);
-       SET_SIZESTATDESC(2976, "responses sent 2976-2991 bytes", "2976-2991",
-                        out);
-       SET_SIZESTATDESC(2992, "responses sent 2992-3007 bytes", "2992-3007",
-                        out);
-       SET_SIZESTATDESC(3008, "responses sent 3008-3023 bytes", "3008-3023",
-                        out);
-       SET_SIZESTATDESC(3024, "responses sent 3024-3039 bytes", "3024-3039",
-                        out);
-       SET_SIZESTATDESC(3040, "responses sent 3040-3055 bytes", "3040-3055",
-                        out);
-       SET_SIZESTATDESC(3056, "responses sent 3056-3071 bytes", "3056-3071",
-                        out);
-       SET_SIZESTATDESC(3072, "responses sent 3072-3087 bytes", "3072-3087",
-                        out);
-       SET_SIZESTATDESC(3088, "responses sent 3088-3103 bytes", "3088-3103",
-                        out);
-       SET_SIZESTATDESC(3104, "responses sent 3104-3119 bytes", "3104-3119",
-                        out);
-       SET_SIZESTATDESC(3120, "responses sent 3120-3135 bytes", "3120-3135",
-                        out);
-       SET_SIZESTATDESC(3136, "responses sent 3136-3151 bytes", "3136-3151",
-                        out);
-       SET_SIZESTATDESC(3152, "responses sent 3152-3167 bytes", "3152-3167",
-                        out);
-       SET_SIZESTATDESC(3168, "responses sent 3168-3183 bytes", "3168-3183",
-                        out);
-       SET_SIZESTATDESC(3184, "responses sent 3184-3199 bytes", "3184-3199",
-                        out);
-       SET_SIZESTATDESC(3200, "responses sent 3200-3215 bytes", "3200-3215",
-                        out);
-       SET_SIZESTATDESC(3216, "responses sent 3216-3231 bytes", "3216-3231",
-                        out);
-       SET_SIZESTATDESC(3232, "responses sent 3232-3247 bytes", "3232-3247",
-                        out);
-       SET_SIZESTATDESC(3248, "responses sent 3248-3263 bytes", "3248-3263",
-                        out);
-       SET_SIZESTATDESC(3264, "responses sent 3264-3279 bytes", "3264-3279",
-                        out);
-       SET_SIZESTATDESC(3280, "responses sent 3280-3295 bytes", "3280-3295",
-                        out);
-       SET_SIZESTATDESC(3296, "responses sent 3296-3311 bytes", "3296-3311",
-                        out);
-       SET_SIZESTATDESC(3312, "responses sent 3312-3327 bytes", "3312-3327",
-                        out);
-       SET_SIZESTATDESC(3328, "responses sent 3328-3343 bytes", "3328-3343",
-                        out);
-       SET_SIZESTATDESC(3344, "responses sent 3344-3359 bytes", "3344-3359",
-                        out);
-       SET_SIZESTATDESC(3360, "responses sent 3360-3375 bytes", "3360-3375",
-                        out);
-       SET_SIZESTATDESC(3376, "responses sent 3376-3391 bytes", "3376-3391",
-                        out);
-       SET_SIZESTATDESC(3392, "responses sent 3392-3407 bytes", "3392-3407",
-                        out);
-       SET_SIZESTATDESC(3408, "responses sent 3408-3423 bytes", "3408-3423",
-                        out);
-       SET_SIZESTATDESC(3424, "responses sent 3424-3439 bytes", "3424-3439",
-                        out);
-       SET_SIZESTATDESC(3440, "responses sent 3440-3455 bytes", "3440-3455",
-                        out);
-       SET_SIZESTATDESC(3456, "responses sent 3456-3471 bytes", "3456-3471",
-                        out);
-       SET_SIZESTATDESC(3472, "responses sent 3472-3487 bytes", "3472-3487",
-                        out);
-       SET_SIZESTATDESC(3488, "responses sent 3488-3503 bytes", "3488-3503",
-                        out);
-       SET_SIZESTATDESC(3504, "responses sent 3504-3519 bytes", "3504-3519",
-                        out);
-       SET_SIZESTATDESC(3520, "responses sent 3520-3535 bytes", "3520-3535",
-                        out);
-       SET_SIZESTATDESC(3536, "responses sent 3536-3551 bytes", "3536-3551",
-                        out);
-       SET_SIZESTATDESC(3552, "responses sent 3552-3567 bytes", "3552-3567",
-                        out);
-       SET_SIZESTATDESC(3568, "responses sent 3568-3583 bytes", "3568-3583",
-                        out);
-       SET_SIZESTATDESC(3584, "responses sent 3584-3599 bytes", "3584-3599",
-                        out);
-       SET_SIZESTATDESC(3600, "responses sent 3600-3615 bytes", "3600-3615",
-                        out);
-       SET_SIZESTATDESC(3616, "responses sent 3616-3631 bytes", "3616-3631",
-                        out);
-       SET_SIZESTATDESC(3632, "responses sent 3632-3647 bytes", "3632-3647",
-                        out);
-       SET_SIZESTATDESC(3648, "responses sent 3648-3663 bytes", "3648-3663",
-                        out);
-       SET_SIZESTATDESC(3664, "responses sent 3664-3679 bytes", "3664-3679",
-                        out);
-       SET_SIZESTATDESC(3680, "responses sent 3680-3695 bytes", "3680-3695",
-                        out);
-       SET_SIZESTATDESC(3696, "responses sent 3696-3711 bytes", "3696-3711",
-                        out);
-       SET_SIZESTATDESC(3712, "responses sent 3712-3727 bytes", "3712-3727",
-                        out);
-       SET_SIZESTATDESC(3728, "responses sent 3728-3743 bytes", "3728-3743",
-                        out);
-       SET_SIZESTATDESC(3744, "responses sent 3744-3759 bytes", "3744-3759",
-                        out);
-       SET_SIZESTATDESC(3760, "responses sent 3760-3775 bytes", "3760-3775",
-                        out);
-       SET_SIZESTATDESC(3776, "responses sent 3776-3791 bytes", "3776-3791",
-                        out);
-       SET_SIZESTATDESC(3792, "responses sent 3792-3807 bytes", "3792-3807",
-                        out);
-       SET_SIZESTATDESC(3808, "responses sent 3808-3823 bytes", "3808-3823",
-                        out);
-       SET_SIZESTATDESC(3824, "responses sent 3824-3839 bytes", "3824-3839",
-                        out);
-       SET_SIZESTATDESC(3840, "responses sent 3840-3855 bytes", "3840-3855",
-                        out);
-       SET_SIZESTATDESC(3856, "responses sent 3856-3871 bytes", "3856-3871",
-                        out);
-       SET_SIZESTATDESC(3872, "responses sent 3872-3887 bytes", "3872-3887",
-                        out);
-       SET_SIZESTATDESC(3888, "responses sent 3888-3903 bytes", "3888-3903",
-                        out);
-       SET_SIZESTATDESC(3904, "responses sent 3904-3919 bytes", "3904-3919",
-                        out);
-       SET_SIZESTATDESC(3920, "responses sent 3920-3935 bytes", "3920-3935",
-                        out);
-       SET_SIZESTATDESC(3936, "responses sent 3936-3951 bytes", "3936-3951",
-                        out);
-       SET_SIZESTATDESC(3952, "responses sent 3952-3967 bytes", "3952-3967",
-                        out);
-       SET_SIZESTATDESC(3968, "responses sent 3968-3983 bytes", "3968-3983",
-                        out);
-       SET_SIZESTATDESC(3984, "responses sent 3984-3999 bytes", "3984-3999",
-                        out);
-       SET_SIZESTATDESC(4000, "responses sent 4000-4015 bytes", "4000-4015",
-                        out);
-       SET_SIZESTATDESC(4016, "responses sent 4016-4031 bytes", "4016-4031",
-                        out);
-       SET_SIZESTATDESC(4032, "responses sent 4032-4047 bytes", "4032-4047",
-                        out);
-       SET_SIZESTATDESC(4048, "responses sent 4048-4063 bytes", "4048-4063",
-                        out);
-       SET_SIZESTATDESC(4064, "responses sent 4064-4079 bytes", "4064-4079",
-                        out);
-       SET_SIZESTATDESC(4080, "responses sent 4080-4095 bytes", "4080-4095",
-                        out);
-       SET_SIZESTATDESC(4096, "responses sent 4096+ bytes", "4096+", out);
-       INSIST(i == dns_sizecounter_out_max);
-
-       /* Sanity check */
-       for (i = 0; i < ns_statscounter_max; i++) {
-               INSIST(nsstats_desc[i] != NULL);
-       }
-       for (i = 0; i < dns_resstatscounter_max; i++) {
-               INSIST(resstats_desc[i] != NULL);
-       }
-       for (i = 0; i < dns_adbstats_max; i++) {
-               INSIST(adbstats_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);
-       }
-       for (i = 0; i < dns_dnssecstats_max; i++) {
-               INSIST(dnssecstats_desc[i] != NULL);
-       }
-       for (i = 0; i < dns_sizecounter_in_max; i++) {
-               INSIST(udpinsizestats_desc[i] != NULL);
-               INSIST(tcpinsizestats_desc[i] != NULL);
-       }
-       for (i = 0; i < dns_sizecounter_out_max; i++) {
-               INSIST(udpoutsizestats_desc[i] != NULL);
-               INSIST(tcpoutsizestats_desc[i] != NULL);
-       }
+       for (i = 0; i <= DNS_SIZEHISTO_MAXIN; i++) {
+               udpinsizestats_index[i] = i;
+               tcpinsizestats_index[i] = i;
+               udpinsizestats_desc[i] = get_histo_desc(
+                       "requests received", i, DNS_SIZEHISTO_MAXIN, false);
+               tcpinsizestats_desc[i] = udpinsizestats_desc[i];
 #if defined(EXTENDED_STATS)
-       for (i = 0; i < ns_statscounter_max; i++) {
-               INSIST(nsstats_xmldesc[i] != NULL);
-       }
-       for (i = 0; i < dns_resstatscounter_max; i++) {
-               INSIST(resstats_xmldesc[i] != NULL);
-       }
-       for (i = 0; i < dns_adbstats_max; i++) {
-               INSIST(adbstats_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);
-       }
-       for (i = 0; i < dns_dnssecstats_max; i++) {
-               INSIST(dnssecstats_xmldesc[i] != NULL);
-       }
-       for (i = 0; i < dns_sizecounter_in_max; i++) {
-               INSIST(udpinsizestats_xmldesc[i] != NULL);
-               INSIST(tcpinsizestats_xmldesc[i] != NULL);
-       }
-       for (i = 0; i < dns_sizecounter_out_max; i++) {
-               INSIST(udpoutsizestats_xmldesc[i] != NULL);
-               INSIST(tcpoutsizestats_xmldesc[i] != NULL);
-       }
+               if (i < DNS_SIZEHISTO_MAXIN) {
+                       udpinsizestats_xmldesc[i] = udpoutsizestats_xmldesc[i];
+                       tcpinsizestats_xmldesc[i] = tcpoutsizestats_xmldesc[i];
+               } else {
+                       udpinsizestats_xmldesc[i] =
+                               get_histo_desc("requests received", i,
+                                              DNS_SIZEHISTO_MAXIN, true);
+                       tcpinsizestats_xmldesc[i] = udpinsizestats_xmldesc[i];
+               }
 #endif /* if defined(EXTENDED_STATS) */
+       }
 }
 
 /*%
  * Dump callback functions.
  */
+
+static isc_result_t
+dump_counters(isc_statsformat_t type, void *arg, const char *category,
+             const char **desc, int ncounters, int *indices, uint64_t *values,
+             int options);
+
 static void
 generalstat_dump(isc_statscounter_t counter, uint64_t val, void *arg) {
        stats_dumparg_t *dumparg = arg;
@@ -1333,12 +831,45 @@ generalstat_dump(isc_statscounter_t counter, uint64_t val, void *arg) {
 }
 
 static isc_result_t
-dump_counters(isc_stats_t *stats, isc_statsformat_t type, void *arg,
-             const char *category, const char **desc, int ncounters,
-             int *indices, uint64_t *values, int options) {
+dump_stats(isc_stats_t *stats, isc_statsformat_t type, void *arg,
+          const char *category, const char **desc, int ncounters, int *indices,
+          uint64_t *values, int options) {
+       stats_dumparg_t dumparg;
+
+       dumparg.type = type;
+       dumparg.ncounters = ncounters;
+       dumparg.counterindices = indices;
+       dumparg.countervalues = values;
+
+       memset(values, 0, sizeof(values[0]) * ncounters);
+       isc_stats_dump(stats, generalstat_dump, &dumparg, options);
+
+       return (dump_counters(type, arg, category, desc, ncounters, indices,
+                             values, options));
+}
+
+static isc_result_t
+dump_histo(isc_histomulti_t *hm, isc_statsformat_t type, void *arg,
+          const char *category, const char **desc, int ncounters, int *indices,
+          uint64_t *values, int options) {
+       isc_histo_t *hg = NULL;
+
+       isc_histomulti_merge(&hg, hm);
+       for (int i = 0; i < ncounters; i++) {
+               isc_histo_get(hg, i, NULL, NULL, &values[i]);
+       }
+       isc_histo_destroy(&hg);
+
+       return (dump_counters(type, arg, category, desc, ncounters, indices,
+                             values, options));
+}
+
+static isc_result_t
+dump_counters(isc_statsformat_t type, void *arg, const char *category,
+             const char **desc, int ncounters, int *indices, uint64_t *values,
+             int options) {
        int i, idx;
        uint64_t value;
-       stats_dumparg_t dumparg;
        FILE *fp;
 #ifdef HAVE_LIBXML2
        void *writer;
@@ -1352,14 +883,6 @@ dump_counters(isc_stats_t *stats, isc_statsformat_t type, void *arg,
        UNUSED(category);
 #endif /* if !defined(EXTENDED_STATS) */
 
-       dumparg.type = type;
-       dumparg.ncounters = ncounters;
-       dumparg.counterindices = indices;
-       dumparg.countervalues = values;
-
-       memset(values, 0, sizeof(values[0]) * ncounters);
-       isc_stats_dump(stats, generalstat_dump, &dumparg, options);
-
 #ifdef HAVE_JSON_C
        cat = job = (json_object *)arg;
        if (ncounters > 0 && type == isc_statsformat_json) {
@@ -1381,7 +904,7 @@ dump_counters(isc_stats_t *stats, isc_statsformat_t type, void *arg,
                        continue;
                }
 
-               switch (dumparg.type) {
+               switch (type) {
                case isc_statsformat_file:
                        fp = arg;
                        fprintf(fp, "%20" PRIu64 " %s\n", value, desc[idx]);
@@ -1873,11 +1396,10 @@ zone_xmlrender(dns_zone_t *zone, void *arg) {
                                                         ISC_XMLCHAR "type",
                                                         ISC_XMLCHAR "rcode"));
 
-                       CHECK(dump_counters(zonestats, isc_statsformat_xml,
-                                           writer, NULL, nsstats_xmldesc,
-                                           ns_statscounter_max, nsstats_index,
-                                           nsstat_values,
-                                           ISC_STATSDUMP_VERBOSE));
+                       CHECK(dump_stats(zonestats, isc_statsformat_xml, writer,
+                                        NULL, nsstats_xmldesc,
+                                        ns_statscounter_max, nsstats_index,
+                                        nsstat_values, ISC_STATSDUMP_VERBOSE));
                        /* counters type="rcode"*/
                        TRY0(xmlTextWriterEndElement(writer));
                }
@@ -1890,12 +1412,12 @@ zone_xmlrender(dns_zone_t *zone, void *arg) {
                                writer, ISC_XMLCHAR "type",
                                ISC_XMLCHAR "gluecache"));
 
-                       CHECK(dump_counters(
-                               gluecachestats, isc_statsformat_xml, writer,
-                               NULL, gluecachestats_xmldesc,
-                               dns_gluecachestatscounter_max,
-                               gluecachestats_index, gluecachestats_values,
-                               ISC_STATSDUMP_VERBOSE));
+                       CHECK(dump_stats(gluecachestats, isc_statsformat_xml,
+                                        writer, NULL, gluecachestats_xmldesc,
+                                        dns_gluecachestatscounter_max,
+                                        gluecachestats_index,
+                                        gluecachestats_values,
+                                        ISC_STATSDUMP_VERBOSE));
                        /* counters type="rcode"*/
                        TRY0(xmlTextWriterEndElement(writer));
                }
@@ -1981,10 +1503,10 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
        uint64_t adbstat_values[dns_adbstats_max];
        uint64_t zonestat_values[dns_zonestatscounter_max];
        uint64_t sockstat_values[isc_sockstatscounter_max];
-       uint64_t udpinsizestat_values[dns_sizecounter_in_max];
-       uint64_t udpoutsizestat_values[dns_sizecounter_out_max];
-       uint64_t tcpinsizestat_values[dns_sizecounter_in_max];
-       uint64_t tcpoutsizestat_values[dns_sizecounter_out_max];
+       uint64_t udpinsizestat_values[DNS_SIZEHISTO_MAXIN + 1];
+       uint64_t udpoutsizestat_values[DNS_SIZEHISTO_MAXOUT + 1];
+       uint64_t tcpinsizestat_values[DNS_SIZEHISTO_MAXIN + 1];
+       uint64_t tcpoutsizestat_values[DNS_SIZEHISTO_MAXOUT + 1];
 #ifdef HAVE_DNSTAP
        uint64_t dnstapstat_values[dns_dnstapcounter_max];
 #endif /* ifdef HAVE_DNSTAP */
@@ -2064,11 +1586,11 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
                TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
                                                 ISC_XMLCHAR "nsstat"));
 
-               CHECK(dump_counters(ns_stats_get(server->sctx->nsstats),
-                                   isc_statsformat_xml, writer, NULL,
-                                   nsstats_xmldesc, ns_statscounter_max,
-                                   nsstats_index, nsstat_values,
-                                   ISC_STATSDUMP_VERBOSE));
+               CHECK(dump_stats(ns_stats_get(server->sctx->nsstats),
+                                isc_statsformat_xml, writer, NULL,
+                                nsstats_xmldesc, ns_statscounter_max,
+                                nsstats_index, nsstat_values,
+                                ISC_STATSDUMP_VERBOSE));
 
                TRY0(xmlTextWriterEndElement(writer)); /* /nsstat */
 
@@ -2076,10 +1598,10 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
                TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
                                                 ISC_XMLCHAR "zonestat"));
 
-               CHECK(dump_counters(server->zonestats, isc_statsformat_xml,
-                                   writer, NULL, zonestats_xmldesc,
-                                   dns_zonestatscounter_max, zonestats_index,
-                                   zonestat_values, ISC_STATSDUMP_VERBOSE));
+               CHECK(dump_stats(server->zonestats, isc_statsformat_xml, writer,
+                                NULL, zonestats_xmldesc,
+                                dns_zonestatscounter_max, zonestats_index,
+                                zonestat_values, ISC_STATSDUMP_VERBOSE));
 
                TRY0(xmlTextWriterEndElement(writer)); /* /zonestat */
 
@@ -2090,10 +1612,10 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
                TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "counters"));
                TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
                                                 ISC_XMLCHAR "resstat"));
-               CHECK(dump_counters(server->resolverstats, isc_statsformat_xml,
-                                   writer, NULL, resstats_xmldesc,
-                                   dns_resstatscounter_max, resstats_index,
-                                   resstat_values, 0));
+               CHECK(dump_stats(server->resolverstats, isc_statsformat_xml,
+                                writer, NULL, resstats_xmldesc,
+                                dns_resstatscounter_max, resstats_index,
+                                resstat_values, 0));
 
                TRY0(xmlTextWriterEndElement(writer)); /* resstat */
 
@@ -2106,7 +1628,7 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
                                                         ISC_XMLCHAR "type",
                                                         ISC_XMLCHAR "dnstap"));
                        dns_dt_getstats(named_g_server->dtenv, &dnstapstats);
-                       result = dump_counters(
+                       result = dump_stats(
                                dnstapstats, isc_statsformat_xml, writer, NULL,
                                dnstapstats_xmldesc, dns_dnstapcounter_max,
                                dnstapstats_index, dnstapstat_values, 0);
@@ -2123,10 +1645,10 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
                TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
                                                 ISC_XMLCHAR "sockstat"));
 
-               CHECK(dump_counters(server->sockstats, isc_statsformat_xml,
-                                   writer, NULL, sockstats_xmldesc,
-                                   isc_sockstatscounter_max, sockstats_index,
-                                   sockstat_values, ISC_STATSDUMP_VERBOSE));
+               CHECK(dump_stats(server->sockstats, isc_statsformat_xml, writer,
+                                NULL, sockstats_xmldesc,
+                                isc_sockstatscounter_max, sockstats_index,
+                                sockstat_values, ISC_STATSDUMP_VERBOSE));
 
                TRY0(xmlTextWriterEndElement(writer)); /* /sockstat */
        }
@@ -2140,10 +1662,10 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
                TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
                                                 ISC_XMLCHAR "request-size"));
 
-               CHECK(dump_counters(
-                       server->sctx->udpinstats4, isc_statsformat_xml, writer,
-                       NULL, udpinsizestats_xmldesc, dns_sizecounter_in_max,
-                       udpinsizestats_index, udpinsizestat_values, 0));
+               CHECK(dump_histo(server->sctx->udpinstats4, isc_statsformat_xml,
+                                writer, NULL, udpinsizestats_xmldesc,
+                                dns_sizecounter_in_max, udpinsizestats_index,
+                                udpinsizestat_values, 0));
 
                TRY0(xmlTextWriterEndElement(writer)); /* </counters> */
 
@@ -2151,7 +1673,7 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
                TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
                                                 ISC_XMLCHAR "response-size"));
 
-               CHECK(dump_counters(
+               CHECK(dump_histo(
                        server->sctx->udpoutstats4, isc_statsformat_xml, writer,
                        NULL, udpoutsizestats_xmldesc, dns_sizecounter_out_max,
                        udpoutsizestats_index, udpoutsizestat_values, 0));
@@ -2164,17 +1686,17 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
                TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
                                                 ISC_XMLCHAR "request-size"));
 
-               CHECK(dump_counters(
-                       server->sctx->tcpinstats4, isc_statsformat_xml, writer,
-                       NULL, tcpinsizestats_xmldesc, dns_sizecounter_in_max,
-                       tcpinsizestats_index, tcpinsizestat_values, 0));
+               CHECK(dump_histo(server->sctx->tcpinstats4, isc_statsformat_xml,
+                                writer, NULL, tcpinsizestats_xmldesc,
+                                dns_sizecounter_in_max, tcpinsizestats_index,
+                                tcpinsizestat_values, 0));
 
                TRY0(xmlTextWriterEndElement(writer)); /* </counters> */
                TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "counters"));
                TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
                                                 ISC_XMLCHAR "response-size"));
 
-               CHECK(dump_counters(
+               CHECK(dump_histo(
                        server->sctx->tcpoutstats4, isc_statsformat_xml, writer,
                        NULL, tcpoutsizestats_xmldesc, dns_sizecounter_out_max,
                        tcpoutsizestats_index, tcpoutsizestat_values, 0));
@@ -2189,10 +1711,10 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
                TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
                                                 ISC_XMLCHAR "request-size"));
 
-               CHECK(dump_counters(
-                       server->sctx->udpinstats6, isc_statsformat_xml, writer,
-                       NULL, udpinsizestats_xmldesc, dns_sizecounter_in_max,
-                       udpinsizestats_index, udpinsizestat_values, 0));
+               CHECK(dump_histo(server->sctx->udpinstats6, isc_statsformat_xml,
+                                writer, NULL, udpinsizestats_xmldesc,
+                                dns_sizecounter_in_max, udpinsizestats_index,
+                                udpinsizestat_values, 0));
 
                TRY0(xmlTextWriterEndElement(writer)); /* </counters> */
 
@@ -2200,7 +1722,7 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
                TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
                                                 ISC_XMLCHAR "response-size"));
 
-               CHECK(dump_counters(
+               CHECK(dump_histo(
                        server->sctx->udpoutstats6, isc_statsformat_xml, writer,
                        NULL, udpoutsizestats_xmldesc, dns_sizecounter_out_max,
                        udpoutsizestats_index, udpoutsizestat_values, 0));
@@ -2213,10 +1735,10 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
                TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
                                                 ISC_XMLCHAR "request-size"));
 
-               CHECK(dump_counters(
-                       server->sctx->tcpinstats6, isc_statsformat_xml, writer,
-                       NULL, tcpinsizestats_xmldesc, dns_sizecounter_in_max,
-                       tcpinsizestats_index, tcpinsizestat_values, 0));
+               CHECK(dump_histo(server->sctx->tcpinstats6, isc_statsformat_xml,
+                                writer, NULL, tcpinsizestats_xmldesc,
+                                dns_sizecounter_in_max, tcpinsizestats_index,
+                                tcpinsizestat_values, 0));
 
                TRY0(xmlTextWriterEndElement(writer)); /* </counters> */
 
@@ -2224,7 +1746,7 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
                TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
                                                 ISC_XMLCHAR "response-size"));
 
-               CHECK(dump_counters(
+               CHECK(dump_histo(
                        server->sctx->tcpoutstats6, isc_statsformat_xml, writer,
                        NULL, tcpoutsizestats_xmldesc, dns_sizecounter_out_max,
                        tcpoutsizestats_index, tcpoutsizestat_values, 0));
@@ -2285,11 +1807,11 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
                                                 ISC_XMLCHAR "resstats"));
                dns_resolver_getstats(view->resolver, &istats);
                if (istats != NULL) {
-                       CHECK(dump_counters(istats, isc_statsformat_xml, writer,
-                                           NULL, resstats_xmldesc,
-                                           dns_resstatscounter_max,
-                                           resstats_index, resstat_values,
-                                           ISC_STATSDUMP_VERBOSE));
+                       CHECK(dump_stats(istats, isc_statsformat_xml, writer,
+                                        NULL, resstats_xmldesc,
+                                        dns_resstatscounter_max,
+                                        resstats_index, resstat_values,
+                                        ISC_STATSDUMP_VERBOSE));
                }
                isc_stats_detach(&istats);
                TRY0(xmlTextWriterEndElement(writer)); /* </resstats> */
@@ -2312,7 +1834,7 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
                TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "counters"));
                TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
                                                 ISC_XMLCHAR "adbstat"));
-               CHECK(dump_counters(
+               CHECK(dump_stats(
                        dns_adb_getstats(view->adb), isc_statsformat_xml,
                        writer, NULL, adbstats_xmldesc, dns_adbstats_max,
                        adbstats_index, adbstat_values, ISC_STATSDUMP_VERBOSE));
@@ -2604,10 +2126,10 @@ zone_jsonrender(dns_zone_t *zone, void *arg) {
                                goto cleanup;
                        }
 
-                       result = dump_counters(zonestats, isc_statsformat_json,
-                                              counters, NULL, nsstats_xmldesc,
-                                              ns_statscounter_max,
-                                              nsstats_index, nsstat_values, 0);
+                       result = dump_stats(zonestats, isc_statsformat_json,
+                                           counters, NULL, nsstats_xmldesc,
+                                           ns_statscounter_max, nsstats_index,
+                                           nsstat_values, 0);
                        if (result != ISC_R_SUCCESS) {
                                json_object_put(counters);
                                goto cleanup;
@@ -2629,7 +2151,7 @@ zone_jsonrender(dns_zone_t *zone, void *arg) {
                                goto cleanup;
                        }
 
-                       result = dump_counters(
+                       result = dump_stats(
                                gluecachestats, isc_statsformat_json, counters,
                                NULL, gluecachestats_xmldesc,
                                dns_gluecachestatscounter_max,
@@ -2864,10 +2386,10 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
                dumparg.result = ISC_R_SUCCESS;
                dumparg.arg = counters;
 
-               result = dump_counters(ns_stats_get(server->sctx->nsstats),
-                                      isc_statsformat_json, counters, NULL,
-                                      nsstats_xmldesc, ns_statscounter_max,
-                                      nsstats_index, nsstat_values, 0);
+               result = dump_stats(ns_stats_get(server->sctx->nsstats),
+                                   isc_statsformat_json, counters, NULL,
+                                   nsstats_xmldesc, ns_statscounter_max,
+                                   nsstats_index, nsstat_values, 0);
                if (result != ISC_R_SUCCESS) {
                        json_object_put(counters);
                        goto cleanup;
@@ -2885,10 +2407,10 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
                dumparg.result = ISC_R_SUCCESS;
                dumparg.arg = counters;
 
-               result = dump_counters(server->zonestats, isc_statsformat_json,
-                                      counters, NULL, zonestats_xmldesc,
-                                      dns_zonestatscounter_max,
-                                      zonestats_index, zonestat_values, 0);
+               result = dump_stats(server->zonestats, isc_statsformat_json,
+                                   counters, NULL, zonestats_xmldesc,
+                                   dns_zonestatscounter_max, zonestats_index,
+                                   zonestat_values, 0);
                if (result != ISC_R_SUCCESS) {
                        json_object_put(counters);
                        goto cleanup;
@@ -2907,10 +2429,10 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
                dumparg.result = ISC_R_SUCCESS;
                dumparg.arg = counters;
 
-               result = dump_counters(
-                       server->resolverstats, isc_statsformat_json, counters,
-                       NULL, resstats_xmldesc, dns_resstatscounter_max,
-                       resstats_index, resstat_values, 0);
+               result = dump_stats(server->resolverstats, isc_statsformat_json,
+                                   counters, NULL, resstats_xmldesc,
+                                   dns_resstatscounter_max, resstats_index,
+                                   resstat_values, 0);
                if (result != ISC_R_SUCCESS) {
                        json_object_put(counters);
                        goto cleanup;
@@ -2930,11 +2452,11 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
                        counters = json_object_new_object();
                        dumparg.result = ISC_R_SUCCESS;
                        dumparg.arg = counters;
-                       result = dump_counters(
-                               dnstapstats, isc_statsformat_json, counters,
-                               NULL, dnstapstats_xmldesc,
-                               dns_dnstapcounter_max, dnstapstats_index,
-                               dnstapstat_values, 0);
+                       result = dump_stats(dnstapstats, isc_statsformat_json,
+                                           counters, NULL, dnstapstats_xmldesc,
+                                           dns_dnstapcounter_max,
+                                           dnstapstats_index,
+                                           dnstapstat_values, 0);
                        isc_stats_detach(&dnstapstats);
                        if (result != ISC_R_SUCCESS) {
                                json_object_put(counters);
@@ -2993,7 +2515,7 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
                                        counters = json_object_new_object();
                                        CHECKMEM(counters);
 
-                                       result = dump_counters(
+                                       result = dump_stats(
                                                istats, isc_statsformat_json,
                                                counters, NULL,
                                                resstats_xmldesc,
@@ -3071,7 +2593,7 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
                                        counters = json_object_new_object();
                                        CHECKMEM(counters);
 
-                                       result = dump_counters(
+                                       result = dump_stats(
                                                istats, isc_statsformat_json,
                                                counters, NULL,
                                                adbstats_xmldesc,
@@ -3100,10 +2622,10 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
                dumparg.result = ISC_R_SUCCESS;
                dumparg.arg = counters;
 
-               result = dump_counters(server->sockstats, isc_statsformat_json,
-                                      counters, NULL, sockstats_xmldesc,
-                                      isc_sockstatscounter_max,
-                                      sockstats_index, sockstat_values, 0);
+               result = dump_stats(server->sockstats, isc_statsformat_json,
+                                   counters, NULL, sockstats_xmldesc,
+                                   isc_sockstatscounter_max, sockstats_index,
+                                   sockstat_values, 0);
                if (result != ISC_R_SUCCESS) {
                        json_object_put(counters);
                        goto cleanup;
@@ -3158,53 +2680,53 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
                tcpresp6 = json_object_new_object();
                CHECKMEM(tcpresp6);
 
-               CHECK(dump_counters(
-                       server->sctx->udpinstats4, isc_statsformat_json,
-                       udpreq4, NULL, udpinsizestats_xmldesc,
-                       dns_sizecounter_in_max, udpinsizestats_index,
-                       udpinsizestat_values, 0));
-
-               CHECK(dump_counters(
-                       server->sctx->udpoutstats4, isc_statsformat_json,
-                       udpresp4, NULL, udpoutsizestats_xmldesc,
-                       dns_sizecounter_out_max, udpoutsizestats_index,
-                       udpoutsizestat_values, 0));
-
-               CHECK(dump_counters(
-                       server->sctx->tcpinstats4, isc_statsformat_json,
-                       tcpreq4, NULL, tcpinsizestats_xmldesc,
-                       dns_sizecounter_in_max, tcpinsizestats_index,
-                       tcpinsizestat_values, 0));
-
-               CHECK(dump_counters(
-                       server->sctx->tcpoutstats4, isc_statsformat_json,
-                       tcpresp4, NULL, tcpoutsizestats_xmldesc,
-                       dns_sizecounter_out_max, tcpoutsizestats_index,
-                       tcpoutsizestat_values, 0));
-
-               CHECK(dump_counters(
-                       server->sctx->udpinstats6, isc_statsformat_json,
-                       udpreq6, NULL, udpinsizestats_xmldesc,
-                       dns_sizecounter_in_max, udpinsizestats_index,
-                       udpinsizestat_values, 0));
-
-               CHECK(dump_counters(
-                       server->sctx->udpoutstats6, isc_statsformat_json,
-                       udpresp6, NULL, udpoutsizestats_xmldesc,
-                       dns_sizecounter_out_max, udpoutsizestats_index,
-                       udpoutsizestat_values, 0));
-
-               CHECK(dump_counters(
-                       server->sctx->tcpinstats6, isc_statsformat_json,
-                       tcpreq6, NULL, tcpinsizestats_xmldesc,
-                       dns_sizecounter_in_max, tcpinsizestats_index,
-                       tcpinsizestat_values, 0));
-
-               CHECK(dump_counters(
-                       server->sctx->tcpoutstats6, isc_statsformat_json,
-                       tcpresp6, NULL, tcpoutsizestats_xmldesc,
-                       dns_sizecounter_out_max, tcpoutsizestats_index,
-                       tcpoutsizestat_values, 0));
+               CHECK(dump_histo(server->sctx->udpinstats4,
+                                isc_statsformat_json, udpreq4, NULL,
+                                udpinsizestats_xmldesc, dns_sizecounter_in_max,
+                                udpinsizestats_index, udpinsizestat_values,
+                                0));
+
+               CHECK(dump_histo(server->sctx->udpoutstats4,
+                                isc_statsformat_json, udpresp4, NULL,
+                                udpoutsizestats_xmldesc,
+                                dns_sizecounter_out_max, udpoutsizestats_index,
+                                udpoutsizestat_values, 0));
+
+               CHECK(dump_histo(server->sctx->tcpinstats4,
+                                isc_statsformat_json, tcpreq4, NULL,
+                                tcpinsizestats_xmldesc, dns_sizecounter_in_max,
+                                tcpinsizestats_index, tcpinsizestat_values,
+                                0));
+
+               CHECK(dump_histo(server->sctx->tcpoutstats4,
+                                isc_statsformat_json, tcpresp4, NULL,
+                                tcpoutsizestats_xmldesc,
+                                dns_sizecounter_out_max, tcpoutsizestats_index,
+                                tcpoutsizestat_values, 0));
+
+               CHECK(dump_histo(server->sctx->udpinstats6,
+                                isc_statsformat_json, udpreq6, NULL,
+                                udpinsizestats_xmldesc, dns_sizecounter_in_max,
+                                udpinsizestats_index, udpinsizestat_values,
+                                0));
+
+               CHECK(dump_histo(server->sctx->udpoutstats6,
+                                isc_statsformat_json, udpresp6, NULL,
+                                udpoutsizestats_xmldesc,
+                                dns_sizecounter_out_max, udpoutsizestats_index,
+                                udpoutsizestat_values, 0));
+
+               CHECK(dump_histo(server->sctx->tcpinstats6,
+                                isc_statsformat_json, tcpreq6, NULL,
+                                tcpinsizestats_xmldesc, dns_sizecounter_in_max,
+                                tcpinsizestats_index, tcpinsizestat_values,
+                                0));
+
+               CHECK(dump_histo(server->sctx->tcpoutstats6,
+                                isc_statsformat_json, tcpresp6, NULL,
+                                tcpoutsizestats_xmldesc,
+                                dns_sizecounter_out_max, tcpoutsizestats_index,
+                                tcpoutsizestat_values, 0));
 
                json_object_object_add(traffic,
                                       "dns-udp-requests-sizes-received-ipv4",
@@ -3876,21 +3398,20 @@ named_stats_dump(named_server_t *server, FILE *fp) {
        }
 
        fprintf(fp, "++ Name Server Statistics ++\n");
-       (void)dump_counters(ns_stats_get(server->sctx->nsstats),
-                           isc_statsformat_file, fp, NULL, nsstats_desc,
-                           ns_statscounter_max, nsstats_index, nsstat_values,
-                           0);
+       (void)dump_stats(ns_stats_get(server->sctx->nsstats),
+                        isc_statsformat_file, fp, NULL, nsstats_desc,
+                        ns_statscounter_max, nsstats_index, nsstat_values, 0);
 
        fprintf(fp, "++ Zone Maintenance Statistics ++\n");
-       (void)dump_counters(server->zonestats, isc_statsformat_file, fp, NULL,
-                           zonestats_desc, dns_zonestatscounter_max,
-                           zonestats_index, zonestat_values, 0);
+       (void)dump_stats(server->zonestats, isc_statsformat_file, fp, NULL,
+                        zonestats_desc, dns_zonestatscounter_max,
+                        zonestats_index, zonestat_values, 0);
 
        fprintf(fp, "++ Resolver Statistics ++\n");
        fprintf(fp, "[Common]\n");
-       (void)dump_counters(server->resolverstats, isc_statsformat_file, fp,
-                           NULL, resstats_desc, dns_resstatscounter_max,
-                           resstats_index, resstat_values, 0);
+       (void)dump_stats(server->resolverstats, isc_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))
        {
@@ -3904,9 +3425,9 @@ named_stats_dump(named_server_t *server, FILE *fp) {
                } else {
                        fprintf(fp, "[View: %s]\n", view->name);
                }
-               (void)dump_counters(istats, isc_statsformat_file, fp, NULL,
-                                   resstats_desc, dns_resstatscounter_max,
-                                   resstats_index, resstat_values, 0);
+               (void)dump_stats(istats, isc_statsformat_file, fp, NULL,
+                                resstats_desc, dns_resstatscounter_max,
+                                resstats_index, resstat_values, 0);
                isc_stats_detach(&istats);
        }
 
@@ -3970,15 +3491,15 @@ named_stats_dump(named_server_t *server, FILE *fp) {
                } else {
                        fprintf(fp, "[View: %s]\n", view->name);
                }
-               (void)dump_counters(adbstats, isc_statsformat_file, fp, NULL,
-                                   adbstats_desc, dns_adbstats_max,
-                                   adbstats_index, adbstat_values, 0);
+               (void)dump_stats(adbstats, isc_statsformat_file, fp, NULL,
+                                adbstats_desc, dns_adbstats_max,
+                                adbstats_index, adbstat_values, 0);
        }
 
        fprintf(fp, "++ Socket I/O Statistics ++\n");
-       (void)dump_counters(server->sockstats, isc_statsformat_file, fp, NULL,
-                           sockstats_desc, isc_sockstatscounter_max,
-                           sockstats_index, sockstat_values, 0);
+       (void)dump_stats(server->sockstats, isc_statsformat_file, fp, NULL,
+                        sockstats_desc, isc_sockstatscounter_max,
+                        sockstats_index, sockstat_values, 0);
 
        fprintf(fp, "++ Per Zone Query Statistics ++\n");
        zone = NULL;
@@ -4003,10 +3524,10 @@ named_stats_dump(named_server_t *server, FILE *fp) {
                        }
                        fprintf(fp, "]\n");
 
-                       (void)dump_counters(zonestats, isc_statsformat_file, fp,
-                                           NULL, nsstats_desc,
-                                           ns_statscounter_max, nsstats_index,
-                                           nsstat_values, 0);
+                       (void)dump_stats(zonestats, isc_statsformat_file, fp,
+                                        NULL, nsstats_desc,
+                                        ns_statscounter_max, nsstats_index,
+                                        nsstat_values, 0);
                }
        }
 
@@ -4033,11 +3554,11 @@ named_stats_dump(named_server_t *server, FILE *fp) {
                        }
                        fprintf(fp, "]\n");
 
-                       (void)dump_counters(
-                               gluecachestats, isc_statsformat_file, fp, NULL,
-                               gluecachestats_desc,
-                               dns_gluecachestatscounter_max,
-                               gluecachestats_index, gluecachestats_values, 0);
+                       (void)dump_stats(gluecachestats, isc_statsformat_file,
+                                        fp, NULL, gluecachestats_desc,
+                                        dns_gluecachestatscounter_max,
+                                        gluecachestats_index,
+                                        gluecachestats_values, 0);
                }
        }
 
index 5728f54ff0b2c47fe49813f67e44fc9a243db646..7b1b03e3a34af072f4931c6982d83bb89968f71b 100644 (file)
@@ -17,6 +17,8 @@
 
 #include <inttypes.h>
 
+#include <isc/histo.h>
+
 #include <dns/types.h>
 
 /*%
@@ -156,292 +158,47 @@ enum {
 };
 
 /*%
- * Traffic size statistics counters. Used as isc_statscounter_t values.
+ * Traffic size statistics, according to RSSAC002 section 2.4
+ * https://www.icann.org/en/system/files/files/rssac-002-measurements-root-20nov14-en.pdf
+ *
+ * The RSSAC002 linear bucketing does not directly match the log-linear
+ * bucketing of an `isc_histo_t`, so we need to adjust some parameters
+ * to fit.
+ *
+ * To map a message size to an `isc_histo_t`, first divide by
+ * DNS_SIZEHISTO_QUANTUM so that `isc_histo_inc()` is presented with
+ * one value per RSSAC002 bucket.
+ *
+ * Configure the `isc_histo_t` with large enough `sigbits` that its
+ * one-value-per-bucket range (its `UNITBUCKETS`) covers the range
+ * required by RSSAC002.
  */
-enum {
-       dns_sizecounter_in_0 = 0,
-       dns_sizecounter_in_16 = 1,
-       dns_sizecounter_in_32 = 2,
-       dns_sizecounter_in_48 = 3,
-       dns_sizecounter_in_64 = 4,
-       dns_sizecounter_in_80 = 5,
-       dns_sizecounter_in_96 = 6,
-       dns_sizecounter_in_112 = 7,
-       dns_sizecounter_in_128 = 8,
-       dns_sizecounter_in_144 = 9,
-       dns_sizecounter_in_160 = 10,
-       dns_sizecounter_in_176 = 11,
-       dns_sizecounter_in_192 = 12,
-       dns_sizecounter_in_208 = 13,
-       dns_sizecounter_in_224 = 14,
-       dns_sizecounter_in_240 = 15,
-       dns_sizecounter_in_256 = 16,
-       dns_sizecounter_in_272 = 17,
-       dns_sizecounter_in_288 = 18,
-
-       dns_sizecounter_in_max = 19,
-};
+#define DNS_SIZEHISTO_QUANTUM   16
+#define DNS_SIZEHISTO_MAXIN     (288 / DNS_SIZEHISTO_QUANTUM)
+#define DNS_SIZEHISTO_MAXOUT    (4096 / DNS_SIZEHISTO_QUANTUM)
+#define DNS_SIZEHISTO_SIGBITSIN         4
+#define DNS_SIZEHISTO_SIGBITSOUT 7
 
+#define DNS_SIZEHISTO_BUCKETIN(size) \
+       ISC_MIN(size / DNS_SIZEHISTO_QUANTUM, DNS_SIZEHISTO_MAXIN)
+
+#define DNS_SIZEHISTO_BUCKETOUT(size) \
+       ISC_MIN(size / DNS_SIZEHISTO_QUANTUM, DNS_SIZEHISTO_MAXOUT)
+
+STATIC_ASSERT(DNS_SIZEHISTO_MAXIN <=
+                     ISC_HISTO_UNITBUCKETS(DNS_SIZEHISTO_SIGBITSIN),
+             "must be enough histogram buckets for RSSAC002");
+
+STATIC_ASSERT(DNS_SIZEHISTO_MAXOUT <=
+                     ISC_HISTO_UNITBUCKETS(DNS_SIZEHISTO_SIGBITSOUT),
+             "must be enough histogram buckets for RSSAC002");
+
+/*
+ * For consistency with other stats counters
+ */
 enum {
-       dns_sizecounter_out_0 = 0,
-       dns_sizecounter_out_16 = 1,
-       dns_sizecounter_out_32 = 2,
-       dns_sizecounter_out_48 = 3,
-       dns_sizecounter_out_64 = 4,
-       dns_sizecounter_out_80 = 5,
-       dns_sizecounter_out_96 = 6,
-       dns_sizecounter_out_112 = 7,
-       dns_sizecounter_out_128 = 8,
-       dns_sizecounter_out_144 = 9,
-       dns_sizecounter_out_160 = 10,
-       dns_sizecounter_out_176 = 11,
-       dns_sizecounter_out_192 = 12,
-       dns_sizecounter_out_208 = 13,
-       dns_sizecounter_out_224 = 14,
-       dns_sizecounter_out_240 = 15,
-       dns_sizecounter_out_256 = 16,
-       dns_sizecounter_out_272 = 17,
-       dns_sizecounter_out_288 = 18,
-       dns_sizecounter_out_304 = 19,
-       dns_sizecounter_out_320 = 20,
-       dns_sizecounter_out_336 = 21,
-       dns_sizecounter_out_352 = 22,
-       dns_sizecounter_out_368 = 23,
-       dns_sizecounter_out_384 = 24,
-       dns_sizecounter_out_400 = 25,
-       dns_sizecounter_out_416 = 26,
-       dns_sizecounter_out_432 = 27,
-       dns_sizecounter_out_448 = 28,
-       dns_sizecounter_out_464 = 29,
-       dns_sizecounter_out_480 = 30,
-       dns_sizecounter_out_496 = 31,
-       dns_sizecounter_out_512 = 32,
-       dns_sizecounter_out_528 = 33,
-       dns_sizecounter_out_544 = 34,
-       dns_sizecounter_out_560 = 35,
-       dns_sizecounter_out_576 = 36,
-       dns_sizecounter_out_592 = 37,
-       dns_sizecounter_out_608 = 38,
-       dns_sizecounter_out_624 = 39,
-       dns_sizecounter_out_640 = 40,
-       dns_sizecounter_out_656 = 41,
-       dns_sizecounter_out_672 = 42,
-       dns_sizecounter_out_688 = 43,
-       dns_sizecounter_out_704 = 44,
-       dns_sizecounter_out_720 = 45,
-       dns_sizecounter_out_736 = 46,
-       dns_sizecounter_out_752 = 47,
-       dns_sizecounter_out_768 = 48,
-       dns_sizecounter_out_784 = 49,
-       dns_sizecounter_out_800 = 50,
-       dns_sizecounter_out_816 = 51,
-       dns_sizecounter_out_832 = 52,
-       dns_sizecounter_out_848 = 53,
-       dns_sizecounter_out_864 = 54,
-       dns_sizecounter_out_880 = 55,
-       dns_sizecounter_out_896 = 56,
-       dns_sizecounter_out_912 = 57,
-       dns_sizecounter_out_928 = 58,
-       dns_sizecounter_out_944 = 59,
-       dns_sizecounter_out_960 = 60,
-       dns_sizecounter_out_976 = 61,
-       dns_sizecounter_out_992 = 62,
-       dns_sizecounter_out_1008 = 63,
-       dns_sizecounter_out_1024 = 64,
-       dns_sizecounter_out_1040 = 65,
-       dns_sizecounter_out_1056 = 66,
-       dns_sizecounter_out_1072 = 67,
-       dns_sizecounter_out_1088 = 68,
-       dns_sizecounter_out_1104 = 69,
-       dns_sizecounter_out_1120 = 70,
-       dns_sizecounter_out_1136 = 71,
-       dns_sizecounter_out_1152 = 72,
-       dns_sizecounter_out_1168 = 73,
-       dns_sizecounter_out_1184 = 74,
-       dns_sizecounter_out_1200 = 75,
-       dns_sizecounter_out_1216 = 76,
-       dns_sizecounter_out_1232 = 77,
-       dns_sizecounter_out_1248 = 78,
-       dns_sizecounter_out_1264 = 79,
-       dns_sizecounter_out_1280 = 80,
-       dns_sizecounter_out_1296 = 81,
-       dns_sizecounter_out_1312 = 82,
-       dns_sizecounter_out_1328 = 83,
-       dns_sizecounter_out_1344 = 84,
-       dns_sizecounter_out_1360 = 85,
-       dns_sizecounter_out_1376 = 86,
-       dns_sizecounter_out_1392 = 87,
-       dns_sizecounter_out_1408 = 88,
-       dns_sizecounter_out_1424 = 89,
-       dns_sizecounter_out_1440 = 90,
-       dns_sizecounter_out_1456 = 91,
-       dns_sizecounter_out_1472 = 92,
-       dns_sizecounter_out_1488 = 93,
-       dns_sizecounter_out_1504 = 94,
-       dns_sizecounter_out_1520 = 95,
-       dns_sizecounter_out_1536 = 96,
-       dns_sizecounter_out_1552 = 97,
-       dns_sizecounter_out_1568 = 98,
-       dns_sizecounter_out_1584 = 99,
-       dns_sizecounter_out_1600 = 100,
-       dns_sizecounter_out_1616 = 101,
-       dns_sizecounter_out_1632 = 102,
-       dns_sizecounter_out_1648 = 103,
-       dns_sizecounter_out_1664 = 104,
-       dns_sizecounter_out_1680 = 105,
-       dns_sizecounter_out_1696 = 106,
-       dns_sizecounter_out_1712 = 107,
-       dns_sizecounter_out_1728 = 108,
-       dns_sizecounter_out_1744 = 109,
-       dns_sizecounter_out_1760 = 110,
-       dns_sizecounter_out_1776 = 111,
-       dns_sizecounter_out_1792 = 112,
-       dns_sizecounter_out_1808 = 113,
-       dns_sizecounter_out_1824 = 114,
-       dns_sizecounter_out_1840 = 115,
-       dns_sizecounter_out_1856 = 116,
-       dns_sizecounter_out_1872 = 117,
-       dns_sizecounter_out_1888 = 118,
-       dns_sizecounter_out_1904 = 119,
-       dns_sizecounter_out_1920 = 120,
-       dns_sizecounter_out_1936 = 121,
-       dns_sizecounter_out_1952 = 122,
-       dns_sizecounter_out_1968 = 123,
-       dns_sizecounter_out_1984 = 124,
-       dns_sizecounter_out_2000 = 125,
-       dns_sizecounter_out_2016 = 126,
-       dns_sizecounter_out_2032 = 127,
-       dns_sizecounter_out_2048 = 128,
-       dns_sizecounter_out_2064 = 129,
-       dns_sizecounter_out_2080 = 130,
-       dns_sizecounter_out_2096 = 131,
-       dns_sizecounter_out_2112 = 132,
-       dns_sizecounter_out_2128 = 133,
-       dns_sizecounter_out_2144 = 134,
-       dns_sizecounter_out_2160 = 135,
-       dns_sizecounter_out_2176 = 136,
-       dns_sizecounter_out_2192 = 137,
-       dns_sizecounter_out_2208 = 138,
-       dns_sizecounter_out_2224 = 139,
-       dns_sizecounter_out_2240 = 140,
-       dns_sizecounter_out_2256 = 141,
-       dns_sizecounter_out_2272 = 142,
-       dns_sizecounter_out_2288 = 143,
-       dns_sizecounter_out_2304 = 144,
-       dns_sizecounter_out_2320 = 145,
-       dns_sizecounter_out_2336 = 146,
-       dns_sizecounter_out_2352 = 147,
-       dns_sizecounter_out_2368 = 148,
-       dns_sizecounter_out_2384 = 149,
-       dns_sizecounter_out_2400 = 150,
-       dns_sizecounter_out_2416 = 151,
-       dns_sizecounter_out_2432 = 152,
-       dns_sizecounter_out_2448 = 153,
-       dns_sizecounter_out_2464 = 154,
-       dns_sizecounter_out_2480 = 155,
-       dns_sizecounter_out_2496 = 156,
-       dns_sizecounter_out_2512 = 157,
-       dns_sizecounter_out_2528 = 158,
-       dns_sizecounter_out_2544 = 159,
-       dns_sizecounter_out_2560 = 160,
-       dns_sizecounter_out_2576 = 161,
-       dns_sizecounter_out_2592 = 162,
-       dns_sizecounter_out_2608 = 163,
-       dns_sizecounter_out_2624 = 164,
-       dns_sizecounter_out_2640 = 165,
-       dns_sizecounter_out_2656 = 166,
-       dns_sizecounter_out_2672 = 167,
-       dns_sizecounter_out_2688 = 168,
-       dns_sizecounter_out_2704 = 169,
-       dns_sizecounter_out_2720 = 170,
-       dns_sizecounter_out_2736 = 171,
-       dns_sizecounter_out_2752 = 172,
-       dns_sizecounter_out_2768 = 173,
-       dns_sizecounter_out_2784 = 174,
-       dns_sizecounter_out_2800 = 175,
-       dns_sizecounter_out_2816 = 176,
-       dns_sizecounter_out_2832 = 177,
-       dns_sizecounter_out_2848 = 178,
-       dns_sizecounter_out_2864 = 179,
-       dns_sizecounter_out_2880 = 180,
-       dns_sizecounter_out_2896 = 181,
-       dns_sizecounter_out_2912 = 182,
-       dns_sizecounter_out_2928 = 183,
-       dns_sizecounter_out_2944 = 184,
-       dns_sizecounter_out_2960 = 185,
-       dns_sizecounter_out_2976 = 186,
-       dns_sizecounter_out_2992 = 187,
-       dns_sizecounter_out_3008 = 188,
-       dns_sizecounter_out_3024 = 189,
-       dns_sizecounter_out_3040 = 190,
-       dns_sizecounter_out_3056 = 191,
-       dns_sizecounter_out_3072 = 192,
-       dns_sizecounter_out_3088 = 193,
-       dns_sizecounter_out_3104 = 194,
-       dns_sizecounter_out_3120 = 195,
-       dns_sizecounter_out_3136 = 196,
-       dns_sizecounter_out_3152 = 197,
-       dns_sizecounter_out_3168 = 198,
-       dns_sizecounter_out_3184 = 199,
-       dns_sizecounter_out_3200 = 200,
-       dns_sizecounter_out_3216 = 201,
-       dns_sizecounter_out_3232 = 202,
-       dns_sizecounter_out_3248 = 203,
-       dns_sizecounter_out_3264 = 204,
-       dns_sizecounter_out_3280 = 205,
-       dns_sizecounter_out_3296 = 206,
-       dns_sizecounter_out_3312 = 207,
-       dns_sizecounter_out_3328 = 208,
-       dns_sizecounter_out_3344 = 209,
-       dns_sizecounter_out_3360 = 210,
-       dns_sizecounter_out_3376 = 211,
-       dns_sizecounter_out_3392 = 212,
-       dns_sizecounter_out_3408 = 213,
-       dns_sizecounter_out_3424 = 214,
-       dns_sizecounter_out_3440 = 215,
-       dns_sizecounter_out_3456 = 216,
-       dns_sizecounter_out_3472 = 217,
-       dns_sizecounter_out_3488 = 218,
-       dns_sizecounter_out_3504 = 219,
-       dns_sizecounter_out_3520 = 220,
-       dns_sizecounter_out_3536 = 221,
-       dns_sizecounter_out_3552 = 222,
-       dns_sizecounter_out_3568 = 223,
-       dns_sizecounter_out_3584 = 224,
-       dns_sizecounter_out_3600 = 225,
-       dns_sizecounter_out_3616 = 226,
-       dns_sizecounter_out_3632 = 227,
-       dns_sizecounter_out_3648 = 228,
-       dns_sizecounter_out_3664 = 229,
-       dns_sizecounter_out_3680 = 230,
-       dns_sizecounter_out_3696 = 231,
-       dns_sizecounter_out_3712 = 232,
-       dns_sizecounter_out_3728 = 233,
-       dns_sizecounter_out_3744 = 234,
-       dns_sizecounter_out_3760 = 235,
-       dns_sizecounter_out_3776 = 236,
-       dns_sizecounter_out_3792 = 237,
-       dns_sizecounter_out_3808 = 238,
-       dns_sizecounter_out_3824 = 239,
-       dns_sizecounter_out_3840 = 240,
-       dns_sizecounter_out_3856 = 241,
-       dns_sizecounter_out_3872 = 242,
-       dns_sizecounter_out_3888 = 243,
-       dns_sizecounter_out_3904 = 244,
-       dns_sizecounter_out_3920 = 245,
-       dns_sizecounter_out_3936 = 246,
-       dns_sizecounter_out_3952 = 247,
-       dns_sizecounter_out_3968 = 248,
-       dns_sizecounter_out_3984 = 249,
-       dns_sizecounter_out_4000 = 250,
-       dns_sizecounter_out_4016 = 251,
-       dns_sizecounter_out_4032 = 252,
-       dns_sizecounter_out_4048 = 253,
-       dns_sizecounter_out_4064 = 254,
-       dns_sizecounter_out_4080 = 255,
-       dns_sizecounter_out_4096 = 256,
-
-       dns_sizecounter_out_max = 257
+       dns_sizecounter_in_max = DNS_SIZEHISTO_MAXIN + 1,
+       dns_sizecounter_out_max = DNS_SIZEHISTO_MAXOUT + 1,
 };
 
 /*%
index 65fe8da3249c53da1fdfc37e9aa84b47a0dea526..37a08b3210ff9f3e245050be1f9ad3468445c807 100644 (file)
@@ -655,12 +655,12 @@ renderend:
 
                switch (isc_sockaddr_pf(&client->peeraddr)) {
                case AF_INET:
-                       isc_stats_increment(client->manager->sctx->tcpoutstats4,
-                                           ISC_MIN((int)respsize / 16, 256));
+                       isc_histomulti_inc(client->manager->sctx->tcpoutstats4,
+                                          DNS_SIZEHISTO_BUCKETOUT(respsize));
                        break;
                case AF_INET6:
-                       isc_stats_increment(client->manager->sctx->tcpoutstats6,
-                                           ISC_MIN((int)respsize / 16, 256));
+                       isc_histomulti_inc(client->manager->sctx->tcpoutstats6,
+                                          DNS_SIZEHISTO_BUCKETOUT(respsize));
                        break;
                default:
                        UNREACHABLE();
@@ -684,12 +684,12 @@ renderend:
 
                switch (isc_sockaddr_pf(&client->peeraddr)) {
                case AF_INET:
-                       isc_stats_increment(client->manager->sctx->udpoutstats4,
-                                           ISC_MIN((int)respsize / 16, 256));
+                       isc_histomulti_inc(client->manager->sctx->udpoutstats4,
+                                          DNS_SIZEHISTO_BUCKETOUT(respsize));
                        break;
                case AF_INET6:
-                       isc_stats_increment(client->manager->sctx->udpoutstats6,
-                                           ISC_MIN((int)respsize / 16, 256));
+                       isc_histomulti_inc(client->manager->sctx->udpoutstats6,
+                                          DNS_SIZEHISTO_BUCKETOUT(respsize));
                        break;
                default:
                        UNREACHABLE();
@@ -1861,12 +1861,12 @@ ns_client_request(isc_nmhandle_t *handle, isc_result_t eresult,
                                   ns_statscounter_requesttcp);
                switch (isc_sockaddr_pf(&client->peeraddr)) {
                case AF_INET:
-                       isc_stats_increment(client->manager->sctx->tcpinstats4,
-                                           ISC_MIN((int)reqsize / 16, 18));
+                       isc_histomulti_inc(client->manager->sctx->tcpinstats4,
+                                          DNS_SIZEHISTO_BUCKETIN(reqsize));
                        break;
                case AF_INET6:
-                       isc_stats_increment(client->manager->sctx->tcpinstats6,
-                                           ISC_MIN((int)reqsize / 16, 18));
+                       isc_histomulti_inc(client->manager->sctx->tcpinstats6,
+                                          DNS_SIZEHISTO_BUCKETIN(reqsize));
                        break;
                default:
                        UNREACHABLE();
@@ -1874,12 +1874,12 @@ ns_client_request(isc_nmhandle_t *handle, isc_result_t eresult,
        } else {
                switch (isc_sockaddr_pf(&client->peeraddr)) {
                case AF_INET:
-                       isc_stats_increment(client->manager->sctx->udpinstats4,
-                                           ISC_MIN((int)reqsize / 16, 18));
+                       isc_histomulti_inc(client->manager->sctx->udpinstats4,
+                                          DNS_SIZEHISTO_BUCKETIN(reqsize));
                        break;
                case AF_INET6:
-                       isc_stats_increment(client->manager->sctx->udpinstats6,
-                                           ISC_MIN((int)reqsize / 16, 18));
+                       isc_histomulti_inc(client->manager->sctx->udpinstats6,
+                                          DNS_SIZEHISTO_BUCKETIN(reqsize));
                        break;
                default:
                        UNREACHABLE();
index b380de9eef89b07ef3ec0392ffccd76833e35971..41e8fc0d032465daf9778e3eaf42711adc073039 100644 (file)
@@ -19,6 +19,7 @@
 #include <stdbool.h>
 
 #include <isc/fuzz.h>
+#include <isc/histo.h>
 #include <isc/log.h>
 #include <isc/magic.h>
 #include <isc/quota.h>
@@ -113,15 +114,15 @@ struct ns_server {
        dns_stats_t *opcodestats;
        dns_stats_t *rcodestats;
 
-       isc_stats_t *udpinstats4;
-       isc_stats_t *udpoutstats4;
-       isc_stats_t *udpinstats6;
-       isc_stats_t *udpoutstats6;
+       isc_histomulti_t *udpinstats4;
+       isc_histomulti_t *udpoutstats4;
+       isc_histomulti_t *udpinstats6;
+       isc_histomulti_t *udpoutstats6;
 
-       isc_stats_t *tcpinstats4;
-       isc_stats_t *tcpoutstats4;
-       isc_stats_t *tcpinstats6;
-       isc_stats_t *tcpoutstats6;
+       isc_histomulti_t *tcpinstats4;
+       isc_histomulti_t *tcpoutstats4;
+       isc_histomulti_t *tcpinstats6;
+       isc_histomulti_t *tcpoutstats6;
 };
 
 struct ns_altsecret {
index 1cc7864a85d658a91c66e58584a148460bba414f..857de2121bb45641c114fb05e36cefa3b4d36b16 100644 (file)
@@ -75,29 +75,29 @@ ns_server_create(isc_mem_t *mctx, ns_matchview_t matchingview,
 
        CHECKFATAL(dns_rcodestats_create(mctx, &sctx->rcodestats));
 
-       CHECKFATAL(isc_stats_create(mctx, &sctx->udpinstats4,
-                                   dns_sizecounter_in_max));
+       isc_histomulti_create(mctx, DNS_SIZEHISTO_SIGBITSIN,
+                             &sctx->udpinstats4);
 
-       CHECKFATAL(isc_stats_create(mctx, &sctx->udpoutstats4,
-                                   dns_sizecounter_out_max));
+       isc_histomulti_create(mctx, DNS_SIZEHISTO_SIGBITSOUT,
+                             &sctx->udpoutstats4);
 
-       CHECKFATAL(isc_stats_create(mctx, &sctx->udpinstats6,
-                                   dns_sizecounter_in_max));
+       isc_histomulti_create(mctx, DNS_SIZEHISTO_SIGBITSIN,
+                             &sctx->udpinstats6);
 
-       CHECKFATAL(isc_stats_create(mctx, &sctx->udpoutstats6,
-                                   dns_sizecounter_out_max));
+       isc_histomulti_create(mctx, DNS_SIZEHISTO_SIGBITSOUT,
+                             &sctx->udpoutstats6);
 
-       CHECKFATAL(isc_stats_create(mctx, &sctx->tcpinstats4,
-                                   dns_sizecounter_in_max));
+       isc_histomulti_create(mctx, DNS_SIZEHISTO_SIGBITSIN,
+                             &sctx->tcpinstats4);
 
-       CHECKFATAL(isc_stats_create(mctx, &sctx->tcpoutstats4,
-                                   dns_sizecounter_out_max));
+       isc_histomulti_create(mctx, DNS_SIZEHISTO_SIGBITSOUT,
+                             &sctx->tcpoutstats4);
 
-       CHECKFATAL(isc_stats_create(mctx, &sctx->tcpinstats6,
-                                   dns_sizecounter_in_max));
+       isc_histomulti_create(mctx, DNS_SIZEHISTO_SIGBITSIN,
+                             &sctx->tcpinstats6);
 
-       CHECKFATAL(isc_stats_create(mctx, &sctx->tcpoutstats6,
-                                   dns_sizecounter_out_max));
+       isc_histomulti_create(mctx, DNS_SIZEHISTO_SIGBITSOUT,
+                             &sctx->tcpoutstats6);
 
        ISC_LIST_INIT(sctx->altsecrets);
 
@@ -178,29 +178,29 @@ ns_server_detach(ns_server_t **sctxp) {
                }
 
                if (sctx->udpinstats4 != NULL) {
-                       isc_stats_detach(&sctx->udpinstats4);
+                       isc_histomulti_destroy(&sctx->udpinstats4);
                }
                if (sctx->tcpinstats4 != NULL) {
-                       isc_stats_detach(&sctx->tcpinstats4);
+                       isc_histomulti_destroy(&sctx->tcpinstats4);
                }
                if (sctx->udpoutstats4 != NULL) {
-                       isc_stats_detach(&sctx->udpoutstats4);
+                       isc_histomulti_destroy(&sctx->udpoutstats4);
                }
                if (sctx->tcpoutstats4 != NULL) {
-                       isc_stats_detach(&sctx->tcpoutstats4);
+                       isc_histomulti_destroy(&sctx->tcpoutstats4);
                }
 
                if (sctx->udpinstats6 != NULL) {
-                       isc_stats_detach(&sctx->udpinstats6);
+                       isc_histomulti_destroy(&sctx->udpinstats6);
                }
                if (sctx->tcpinstats6 != NULL) {
-                       isc_stats_detach(&sctx->tcpinstats6);
+                       isc_histomulti_destroy(&sctx->tcpinstats6);
                }
                if (sctx->udpoutstats6 != NULL) {
-                       isc_stats_detach(&sctx->udpoutstats6);
+                       isc_histomulti_destroy(&sctx->udpoutstats6);
                }
                if (sctx->tcpoutstats6 != NULL) {
-                       isc_stats_detach(&sctx->tcpoutstats6);
+                       isc_histomulti_destroy(&sctx->tcpoutstats6);
                }
 
                sctx->magic = 0;