2 * daemon/stats.h - collect runtime performance indicators.
4 * Copyright (c) 2007, NLnet Labs. All rights reserved.
6 * This software is open source.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
19 * Neither the name of the NLNET LABS nor the names of its contributors may
20 * be used to endorse or promote products derived from this software without
21 * specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 * This file describes the data structure used to collect runtime performance
40 * numbers. These 'statistics' may be of interest to the operator.
43 #ifndef DAEMON_STATS_H
44 #define DAEMON_STATS_H
45 #include "util/timehist.h"
54 #include "libunbound/unbound.h"
57 * Initialize server stats to 0.
58 * @param stats: what to init (this is alloced by the caller).
59 * @param cfg: with extended statistics option.
61 void server_stats_init(struct ub_server_stats* stats, struct config_file* cfg);
63 /** add query if it missed the cache */
64 void server_stats_querymiss(struct ub_server_stats* stats, struct worker* worker);
66 /** add query if was cached and also resulted in a prefetch */
67 void server_stats_prefetch(struct ub_server_stats* stats, struct worker* worker);
69 /** display the stats to the log */
70 void server_stats_log(struct ub_server_stats* stats, struct worker* worker,
74 * Obtain the stats info for a given thread. Uses pipe to communicate.
75 * @param worker: the worker that is executing (the first worker).
76 * @param who: on who to get the statistics info.
77 * @param s: the stats block to fill in.
78 * @param reset: if stats can be reset.
80 void server_stats_obtain(struct worker* worker, struct worker* who,
81 struct ub_stats_info* s, int reset);
84 * Compile stats into structure for this thread worker.
85 * Also clears the statistics counters (if that is set by config file).
86 * @param worker: the worker to compile stats for, also the executing worker.
87 * @param s: stats block.
88 * @param reset: if true, depending on config stats are reset.
89 * if false, statistics are not reset.
91 void server_stats_compile(struct worker* worker, struct ub_stats_info* s,
95 * Send stats over comm tube in reply to query cmd
96 * @param worker: this worker.
97 * @param reset: if true, depending on config stats are reset.
98 * if false, statistics are not reset.
100 void server_stats_reply(struct worker* worker, int reset);
104 * @param total: sum of the two entries.
105 * @param a: to add to it.
107 void server_stats_add(struct ub_stats_info* total, struct ub_stats_info* a);
110 * Add stats for this query
111 * @param stats: the stats
112 * @param c: commpoint with type and buffer.
113 * @param qtype: query type
114 * @param qclass: query class
115 * @param edns: edns record
116 * @param repinfo: reply info with remote address
118 void server_stats_insquery(struct ub_server_stats* stats, struct comm_point* c,
119 uint16_t qtype, uint16_t qclass, struct edns_data* edns,
120 struct comm_reply* repinfo);
123 * Add rcode for this query.
124 * @param stats: the stats
125 * @param buf: buffer with rcode. If buffer is length0: not counted.
127 void server_stats_insrcode(struct ub_server_stats* stats, struct sldns_buffer* buf);
129 #endif /* DAEMON_STATS_H */