1 /* 2 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 3 * 4 * This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, you can obtain one at https://mozilla.org/MPL/2.0/. 7 * 8 * See the COPYRIGHT file distributed with this work for additional 9 * information regarding copyright ownership. 10 */ 11 12 #ifndef ISC_STATS_H 13 #define ISC_STATS_H 1 14 15 /*! \file isc/stats.h */ 16 17 #include <inttypes.h> 18 19 #include <isc/types.h> 20 21 /*% 22 * Statistics counters. Used as isc_statscounter_t values. 23 */ 24 enum { 25 /*% 26 * Socket statistics counters. 27 */ 28 isc_sockstatscounter_udp4open = 0, 29 isc_sockstatscounter_udp6open = 1, 30 isc_sockstatscounter_tcp4open = 2, 31 isc_sockstatscounter_tcp6open = 3, 32 isc_sockstatscounter_unixopen = 4, 33 34 isc_sockstatscounter_udp4openfail = 5, 35 isc_sockstatscounter_udp6openfail = 6, 36 isc_sockstatscounter_tcp4openfail = 7, 37 isc_sockstatscounter_tcp6openfail = 8, 38 isc_sockstatscounter_unixopenfail = 9, 39 40 isc_sockstatscounter_udp4close = 10, 41 isc_sockstatscounter_udp6close = 11, 42 isc_sockstatscounter_tcp4close = 12, 43 isc_sockstatscounter_tcp6close = 13, 44 isc_sockstatscounter_unixclose = 14, 45 isc_sockstatscounter_fdwatchclose = 15, 46 47 isc_sockstatscounter_udp4bindfail = 16, 48 isc_sockstatscounter_udp6bindfail = 17, 49 isc_sockstatscounter_tcp4bindfail = 18, 50 isc_sockstatscounter_tcp6bindfail = 19, 51 isc_sockstatscounter_unixbindfail = 20, 52 isc_sockstatscounter_fdwatchbindfail = 21, 53 54 isc_sockstatscounter_udp4connect = 22, 55 isc_sockstatscounter_udp6connect = 23, 56 isc_sockstatscounter_tcp4connect = 24, 57 isc_sockstatscounter_tcp6connect = 25, 58 isc_sockstatscounter_unixconnect = 26, 59 isc_sockstatscounter_fdwatchconnect = 27, 60 61 isc_sockstatscounter_udp4connectfail = 28, 62 isc_sockstatscounter_udp6connectfail = 29, 63 isc_sockstatscounter_tcp4connectfail = 30, 64 isc_sockstatscounter_tcp6connectfail = 31, 65 isc_sockstatscounter_unixconnectfail = 32, 66 isc_sockstatscounter_fdwatchconnectfail = 33, 67 68 isc_sockstatscounter_tcp4accept = 34, 69 isc_sockstatscounter_tcp6accept = 35, 70 isc_sockstatscounter_unixaccept = 36, 71 72 isc_sockstatscounter_tcp4acceptfail = 37, 73 isc_sockstatscounter_tcp6acceptfail = 38, 74 isc_sockstatscounter_unixacceptfail = 39, 75 76 isc_sockstatscounter_udp4sendfail = 40, 77 isc_sockstatscounter_udp6sendfail = 41, 78 isc_sockstatscounter_tcp4sendfail = 42, 79 isc_sockstatscounter_tcp6sendfail = 43, 80 isc_sockstatscounter_unixsendfail = 44, 81 isc_sockstatscounter_fdwatchsendfail = 45, 82 83 isc_sockstatscounter_udp4recvfail = 46, 84 isc_sockstatscounter_udp6recvfail = 47, 85 isc_sockstatscounter_tcp4recvfail = 48, 86 isc_sockstatscounter_tcp6recvfail = 49, 87 isc_sockstatscounter_unixrecvfail = 50, 88 isc_sockstatscounter_fdwatchrecvfail = 51, 89 90 isc_sockstatscounter_udp4active = 52, 91 isc_sockstatscounter_udp6active = 53, 92 isc_sockstatscounter_tcp4active = 54, 93 isc_sockstatscounter_tcp6active = 55, 94 isc_sockstatscounter_unixactive = 56, 95 96 isc_sockstatscounter_rawopen = 57, 97 isc_sockstatscounter_rawopenfail = 58, 98 isc_sockstatscounter_rawclose = 59, 99 isc_sockstatscounter_rawrecvfail = 60, 100 isc_sockstatscounter_rawactive = 61, 101 102 isc_sockstatscounter_max = 62 103 }; 104 105 ISC_LANG_BEGINDECLS 106 107 /*%< 108 * Flag(s) for isc_stats_dump(). 109 */ 110 #define ISC_STATSDUMP_VERBOSE 0x00000001 /*%< dump 0-value counters */ 111 112 /*%< 113 * Dump callback type. 114 */ 115 typedef void (*isc_stats_dumper_t)(isc_statscounter_t, uint64_t, void *); 116 117 isc_result_t 118 isc_stats_create(isc_mem_t *mctx, isc_stats_t **statsp, int ncounters); 119 /*%< 120 * Create a statistics counter structure of general type. It counts a general 121 * set of counters indexed by an ID between 0 and ncounters -1. 122 * 123 * Requires: 124 *\li 'mctx' must be a valid memory context. 125 * 126 *\li 'statsp' != NULL && '*statsp' == NULL. 127 * 128 * Returns: 129 *\li ISC_R_SUCCESS -- all ok 130 * 131 *\li anything else -- failure 132 */ 133 134 void 135 isc_stats_attach(isc_stats_t *stats, isc_stats_t **statsp); 136 /*%< 137 * Attach to a statistics set. 138 * 139 * Requires: 140 *\li 'stats' is a valid isc_stats_t. 141 * 142 *\li 'statsp' != NULL && '*statsp' == NULL 143 */ 144 145 void 146 isc_stats_detach(isc_stats_t **statsp); 147 /*%< 148 * Detaches from the statistics set. 149 * 150 * Requires: 151 *\li 'statsp' != NULL and '*statsp' is a valid isc_stats_t. 152 */ 153 154 int 155 isc_stats_ncounters(isc_stats_t *stats); 156 /*%< 157 * Returns the number of counters contained in stats. 158 * 159 * Requires: 160 *\li 'stats' is a valid isc_stats_t. 161 * 162 */ 163 164 void 165 isc_stats_increment(isc_stats_t *stats, isc_statscounter_t counter); 166 /*%< 167 * Increment the counter-th counter of stats. 168 * 169 * Requires: 170 *\li 'stats' is a valid isc_stats_t. 171 * 172 *\li counter is less than the maximum available ID for the stats specified 173 * on creation. 174 */ 175 176 void 177 isc_stats_decrement(isc_stats_t *stats, isc_statscounter_t counter); 178 /*%< 179 * Decrement the counter-th counter of stats. 180 * 181 * Requires: 182 *\li 'stats' is a valid isc_stats_t. 183 */ 184 185 void 186 isc_stats_dump(isc_stats_t *stats, isc_stats_dumper_t dump_fn, void *arg, 187 unsigned int options); 188 /*%< 189 * Dump the current statistics counters in a specified way. For each counter 190 * in stats, dump_fn is called with its current value and the given argument 191 * arg. By default counters that have a value of 0 is skipped; if options has 192 * the ISC_STATSDUMP_VERBOSE flag, even such counters are dumped. 193 * 194 * Requires: 195 *\li 'stats' is a valid isc_stats_t. 196 */ 197 198 void 199 isc_stats_set(isc_stats_t *stats, uint64_t val, isc_statscounter_t counter); 200 /*%< 201 * Set the given counter to the specified value. 202 * 203 * Requires: 204 *\li 'stats' is a valid isc_stats_t. 205 */ 206 207 void 208 isc_stats_set(isc_stats_t *stats, uint64_t val, isc_statscounter_t counter); 209 /*%< 210 * Set the given counter to the specified value. 211 * 212 * Requires: 213 *\li 'stats' is a valid isc_stats_t. 214 */ 215 216 void 217 isc_stats_update_if_greater(isc_stats_t *stats, isc_statscounter_t counter, 218 isc_statscounter_t value); 219 /*%< 220 * Atomically assigns 'value' to 'counter' if value > counter. 221 * 222 * Requires: 223 *\li 'stats' is a valid isc_stats_t. 224 * 225 *\li counter is less than the maximum available ID for the stats specified 226 * on creation. 227 */ 228 229 isc_statscounter_t 230 isc_stats_get_counter(isc_stats_t *stats, isc_statscounter_t counter); 231 /*%< 232 * Returns value currently stored in counter. 233 * 234 * Requires: 235 *\li 'stats' is a valid isc_stats_t. 236 * 237 *\li counter is less than the maximum available ID for the stats specified 238 * on creation. 239 */ 240 241 void 242 isc_stats_resize(isc_stats_t **stats, int ncounters); 243 /*%< 244 * Resize a statistics counter structure of general type. The new set of 245 * counters are indexed by an ID between 0 and ncounters -1. 246 * 247 * Requires: 248 *\li 'stats' is a valid isc_stats_t. 249 *\li 'ncounters' is a non-zero positive number. 250 */ 251 252 ISC_LANG_ENDDECLS 253 254 #endif /* ISC_STATS_H */ 255