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