]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add functions for collecting high-water counters
authorDiego Fronza <diego@isc.org>
Tue, 5 Nov 2019 20:48:47 +0000 (17:48 -0300)
committerOndřej Surý <ondrej@sury.org>
Wed, 6 Nov 2019 10:26:22 +0000 (11:26 +0100)
Add {isc,ns}_stats_{update_if_greater,get_counter}() functions that
are used to set and collect high-water type of statistics.

(cherry picked from commit a544e2e3006cf426b4125a892ae828137d692e6b)

lib/isc/include/isc/stats.h
lib/isc/stats.c
lib/isc/win32/libisc.def.in
lib/ns/include/ns/stats.h
lib/ns/stats.c
lib/ns/win32/libns.def

index 8f41bb95aa867b4c6a0af4b2c188c6d7a748ba8a..2c6f811785e297290e2f204db7873252e8d89fbb 100644 (file)
@@ -132,6 +132,31 @@ isc_stats_set(isc_stats_t *stats, uint64_t val,
  *\li  'stats' is a valid isc_stats_t.
  */
 
+void isc_stats_update_if_greater(isc_stats_t *stats,
+                                isc_statscounter_t counter,
+                                isc_statscounter_t value);
+/*%<
+* Atomically assigns 'value' to 'counter' if value > counter.
+*
+* Requires:
+*\li   'stats' is a valid isc_stats_t.
+*
+*\li   counter is less than the maximum available ID for the stats specified
+*      on creation.
+*/
+
+isc_statscounter_t
+isc_stats_get_counter(isc_stats_t *stats, isc_statscounter_t counter);
+/*%<
+ * Returns value currently stored in counter.
+ *
+ * Requires:
+ *\li  'stats' is a valid isc_stats_t.
+ *
+ *\li  counter is less than the maximum available ID for the stats specified
+ *     on creation.
+ */
+
 ISC_LANG_ENDDECLS
 
 #endif /* ISC_STATS_H */
index e9d81e0573e33320f4939a1dd726e0fc4d767c60..a74b8488d88e7239ca7df756d8c9f5976b771cfd 100644 (file)
@@ -151,3 +151,34 @@ isc_stats_set(isc_stats_t *stats, uint64_t val,
        atomic_store_explicit(&stats->counters[counter], val,
                              memory_order_relaxed);
 }
+
+void isc_stats_update_if_greater(isc_stats_t *stats,
+                                isc_statscounter_t counter,
+                                isc_statscounter_t value)
+{
+       REQUIRE(ISC_STATS_VALID(stats));
+       REQUIRE(counter < stats->ncounters);
+
+       isc_statscounter_t curr_value;
+
+       do {
+               curr_value = atomic_load_explicit(&stats->counters[counter],
+                                                 memory_order_relaxed);
+               if (curr_value >= value) {
+                       break;
+               }
+
+       } while (!atomic_compare_exchange_strong(&stats->counters[counter],
+                                                &curr_value,
+                                                value));
+}
+
+isc_statscounter_t
+isc_stats_get_counter(isc_stats_t *stats, isc_statscounter_t counter)
+{
+       REQUIRE(ISC_STATS_VALID(stats));
+       REQUIRE(counter < stats->ncounters);
+
+       return (atomic_load_explicit(&stats->counters[counter],
+                                   memory_order_relaxed));
+}
index 82a5c2b619473702617e177b054c899a6436cc4e..de3e535ee13f9e141455b15b9ef639d7305602ca 100644 (file)
@@ -539,9 +539,11 @@ isc_stats_create
 isc_stats_decrement
 isc_stats_detach
 isc_stats_dump
+isc_stats_get_counter
 isc_stats_increment
 isc_stats_ncounters
 isc_stats_set
+isc_stats_update_if_greater
 isc_stdio_close
 isc_stdio_flush
 isc_stdio_open
index 4765cae2995e2b461c8a1b32771f0389c226cf2c..f456a971b0a2b112b329dc45071e98aea31c544a 100644 (file)
@@ -123,4 +123,11 @@ ns_stats_decrement(ns_stats_t *stats, isc_statscounter_t counter);
 isc_stats_t *
 ns_stats_get(ns_stats_t *stats);
 
+void ns_stats_update_if_greater(ns_stats_t *stats,
+                               isc_statscounter_t counter,
+                               isc_statscounter_t value);
+
+isc_statscounter_t
+ns_stats_get_counter(ns_stats_t *stats, isc_statscounter_t counter);
+
 #endif /* NS_STATS_H */
index d34ce9bd88881f64f0cc85f5482e8c19e367221b..d9fb69445996b410bc7420bf37e4b4dd5c3f4c79 100644 (file)
@@ -123,3 +123,20 @@ ns_stats_get(ns_stats_t *stats) {
 
        return (stats->counters);
 }
+
+void ns_stats_update_if_greater(ns_stats_t *stats,
+                            isc_statscounter_t counter,
+                            isc_statscounter_t value)
+{
+       REQUIRE(NS_STATS_VALID(stats));
+
+       isc_stats_update_if_greater(stats->counters, counter, value);
+}
+
+isc_statscounter_t
+ns_stats_get_counter(ns_stats_t *stats, isc_statscounter_t counter)
+{
+       REQUIRE(NS_STATS_VALID(stats));
+
+       return (isc_stats_get_counter(stats->counters, counter));
+}
index d47deaa6d5318cc3784ba1c870b58a805a4c4b40..d221b0d5b2e16763681ee572bb3b8bac664bd496 100644 (file)
@@ -102,6 +102,8 @@ ns_stats_create
 ns_stats_decrement
 ns_stats_detach
 ns_stats_get
+ns_stats_get_counter
 ns_stats_increment
+ns_stats_update_if_greater
 ns_update_start
 ns_xfr_start