Lines Matching refs:stats

34 #include <isc/stats.h>
79 * of the stats structure so that the dump operation won't fail due
91 isc_stats_t *stats;
96 stats = isc_mem_get(mctx, sizeof(*stats));
97 if (stats == NULL)
100 result = isc_mutex_init(&stats->lock);
104 stats->counters = isc_mem_get(mctx, sizeof(isc_stat_t) * ncounters);
105 if (stats->counters == NULL) {
109 stats->copiedcounters = isc_mem_get(mctx,
111 if (stats->copiedcounters == NULL) {
117 result = isc_rwlock_init(&stats->counterlock, 0, 0);
122 stats->references = 1;
123 memset(stats->counters, 0, sizeof(isc_stat_t) * ncounters);
124 stats->mctx = NULL;
125 isc_mem_attach(mctx, &stats->mctx);
126 stats->ncounters = ncounters;
127 stats->magic = ISC_STATS_MAGIC;
129 *statsp = stats;
134 isc_mem_put(mctx, stats->counters, sizeof(isc_stat_t) * ncounters);
138 isc_mem_put(mctx, stats->copiedcounters,
143 DESTROYLOCK(&stats->lock);
146 isc_mem_put(mctx, stats, sizeof(*stats));
152 isc_stats_attach(isc_stats_t *stats, isc_stats_t **statsp) {
153 REQUIRE(ISC_STATS_VALID(stats));
156 LOCK(&stats->lock);
157 stats->references++;
158 UNLOCK(&stats->lock);
160 *statsp = stats;
165 isc_stats_t *stats;
169 stats = *statsp;
172 LOCK(&stats->lock);
173 stats->references--;
174 UNLOCK(&stats->lock);
176 if (stats->references == 0) {
177 isc_mem_put(stats->mctx, stats->copiedcounters,
178 sizeof(isc_stat_t) * stats->ncounters);
179 isc_mem_put(stats->mctx, stats->counters,
180 sizeof(isc_stat_t) * stats->ncounters);
181 DESTROYLOCK(&stats->lock);
183 isc_rwlock_destroy(&stats->counterlock);
185 isc_mem_putanddetach(&stats->mctx, stats, sizeof(*stats));
190 isc_stats_ncounters(isc_stats_t *stats) {
191 REQUIRE(ISC_STATS_VALID(stats));
193 return (stats->ncounters);
197 incrementcounter(isc_stats_t *stats, int counter) {
206 isc_rwlock_lock(&stats->counterlock, isc_rwlocktype_read);
210 prev = isc_atomic_xadd((isc_int32_t *)&stats->counters[counter].lo, 1);
220 isc_atomic_xadd((isc_int32_t *)&stats->counters[counter].hi, 1);
223 isc_atomic_xaddq((isc_int64_t *)&stats->counters[counter], 1);
226 stats->counters[counter]++;
230 isc_rwlock_unlock(&stats->counterlock, isc_rwlocktype_read);
235 decrementcounter(isc_stats_t *stats, int counter) {
239 isc_rwlock_lock(&stats->counterlock, isc_rwlocktype_read);
243 prev = isc_atomic_xadd((isc_int32_t *)&stats->counters[counter].lo, -1);
245 isc_atomic_xadd((isc_int32_t *)&stats->counters[counter].hi,
249 isc_atomic_xaddq((isc_int64_t *)&stats->counters[counter], -1);
252 stats->counters[counter]--;
256 isc_rwlock_unlock(&stats->counterlock, isc_rwlocktype_read);
261 copy_counters(isc_stats_t *stats) {
269 isc_rwlock_lock(&stats->counterlock, isc_rwlocktype_write);
273 for (i = 0; i < stats->ncounters; i++) {
274 stats->copiedcounters[i] =
275 (isc_uint64_t)(stats->counters[i].hi) << 32 |
276 stats->counters[i].lo;
280 memcpy(stats->copiedcounters, stats->counters,
281 stats->ncounters * sizeof(isc_stat_t));
285 isc_rwlock_unlock(&stats->counterlock, isc_rwlocktype_write);
297 isc_stats_increment(isc_stats_t *stats, isc_statscounter_t counter) {
298 REQUIRE(ISC_STATS_VALID(stats));
299 REQUIRE(counter < stats->ncounters);
301 incrementcounter(stats, (int)counter);
305 isc_stats_decrement(isc_stats_t *stats, isc_statscounter_t counter) {
306 REQUIRE(ISC_STATS_VALID(stats));
307 REQUIRE(counter < stats->ncounters);
309 decrementcounter(stats, (int)counter);
313 isc_stats_dump(isc_stats_t *stats, isc_stats_dumper_t dump_fn,
318 REQUIRE(ISC_STATS_VALID(stats));
320 copy_counters(stats);
322 for (i = 0; i < stats->ncounters; i++) {
324 stats->copiedcounters[i] == 0)
326 dump_fn((isc_statscounter_t)i, stats->copiedcounters[i], arg);