Lines Matching refs:stats

32 #include <isc/stats.h>
77 * of the stats structure so that the dump operation won't fail due
89 isc_stats_t *stats;
94 stats = isc_mem_get(mctx, sizeof(*stats));
95 if (stats == NULL)
98 result = isc_mutex_init(&stats->lock);
102 stats->counters = isc_mem_get(mctx, sizeof(isc_stat_t) * ncounters);
103 if (stats->counters == NULL) {
107 stats->copiedcounters = isc_mem_get(mctx,
109 if (stats->copiedcounters == NULL) {
115 result = isc_rwlock_init(&stats->counterlock, 0, 0);
120 stats->references = 1;
121 memset(stats->counters, 0, sizeof(isc_stat_t) * ncounters);
122 stats->mctx = NULL;
123 isc_mem_attach(mctx, &stats->mctx);
124 stats->ncounters = ncounters;
125 stats->magic = ISC_STATS_MAGIC;
127 *statsp = stats;
132 isc_mem_put(mctx, stats->counters, sizeof(isc_stat_t) * ncounters);
136 isc_mem_put(mctx, stats->copiedcounters,
141 DESTROYLOCK(&stats->lock);
144 isc_mem_put(mctx, stats, sizeof(*stats));
150 isc_stats_attach(isc_stats_t *stats, isc_stats_t **statsp) {
151 REQUIRE(ISC_STATS_VALID(stats));
154 LOCK(&stats->lock);
155 stats->references++;
156 UNLOCK(&stats->lock);
158 *statsp = stats;
163 isc_stats_t *stats;
167 stats = *statsp;
170 LOCK(&stats->lock);
171 stats->references--;
172 UNLOCK(&stats->lock);
174 if (stats->references == 0) {
175 isc_mem_put(stats->mctx, stats->copiedcounters,
176 sizeof(isc_stat_t) * stats->ncounters);
177 isc_mem_put(stats->mctx, stats->counters,
178 sizeof(isc_stat_t) * stats->ncounters);
179 DESTROYLOCK(&stats->lock);
181 isc_rwlock_destroy(&stats->counterlock);
183 isc_mem_putanddetach(&stats->mctx, stats, sizeof(*stats));
188 isc_stats_ncounters(isc_stats_t *stats) {
189 REQUIRE(ISC_STATS_VALID(stats));
191 return (stats->ncounters);
195 incrementcounter(isc_stats_t *stats, int counter) {
204 isc_rwlock_lock(&stats->counterlock, isc_rwlocktype_read);
208 prev = isc_atomic_xadd((isc_int32_t *)&stats->counters[counter].lo, 1);
218 isc_atomic_xadd((isc_int32_t *)&stats->counters[counter].hi, 1);
221 isc_atomic_xaddq((isc_int64_t *)&stats->counters[counter], 1);
224 stats->counters[counter]++;
228 isc_rwlock_unlock(&stats->counterlock, isc_rwlocktype_read);
233 decrementcounter(isc_stats_t *stats, int counter) {
237 isc_rwlock_lock(&stats->counterlock, isc_rwlocktype_read);
241 prev = isc_atomic_xadd((isc_int32_t *)&stats->counters[counter].lo, -1);
243 isc_atomic_xadd((isc_int32_t *)&stats->counters[counter].hi,
247 isc_atomic_xaddq((isc_int64_t *)&stats->counters[counter], -1);
250 stats->counters[counter]--;
254 isc_rwlock_unlock(&stats->counterlock, isc_rwlocktype_read);
259 copy_counters(isc_stats_t *stats) {
267 isc_rwlock_lock(&stats->counterlock, isc_rwlocktype_write);
271 for (i = 0; i < stats->ncounters; i++) {
272 stats->copiedcounters[i] =
273 (isc_uint64_t)(stats->counters[i].hi) << 32 |
274 stats->counters[i].lo;
278 memmove(stats->copiedcounters, stats->counters,
279 stats->ncounters * sizeof(isc_stat_t));
283 isc_rwlock_unlock(&stats->counterlock, isc_rwlocktype_write);
295 isc_stats_increment(isc_stats_t *stats, isc_statscounter_t counter) {
296 REQUIRE(ISC_STATS_VALID(stats));
297 REQUIRE(counter < stats->ncounters);
299 incrementcounter(stats, (int)counter);
303 isc_stats_decrement(isc_stats_t *stats, isc_statscounter_t counter) {
304 REQUIRE(ISC_STATS_VALID(stats));
305 REQUIRE(counter < stats->ncounters);
307 decrementcounter(stats, (int)counter);
311 isc_stats_dump(isc_stats_t *stats, isc_stats_dumper_t dump_fn,
316 REQUIRE(ISC_STATS_VALID(stats));
318 copy_counters(stats);
320 for (i = 0; i < stats->ncounters; i++) {
322 stats->copiedcounters[i] == 0)
324 dump_fn((isc_statscounter_t)i, stats->copiedcounters[i], arg);