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