From: Alan T. DeKok Date: Fri, 20 Jul 2018 15:34:17 +0000 (-0400) Subject: add fr_io_stats to network && workers X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e586e1cb6fab646e5a39ab4e20cccb9815dac193;p=thirdparty%2Ffreeradius-server.git add fr_io_stats to network && workers along with export functions --- diff --git a/src/lib/io/network.c b/src/lib/io/network.c index f066873d65d..fa26a011cdd 100644 --- a/src/lib/io/network.c +++ b/src/lib/io/network.c @@ -1456,3 +1456,19 @@ int fr_network_listen_inject(fr_network_t *nr, fr_listen_t *listen, uint8_t cons return fr_control_message_send(nr->control, rb, FR_CONTROL_ID_INJECT, &my_inject, sizeof(my_inject)); } + +int fr_network_stats(fr_network_t const *nr, int num, uint64_t *stats) +{ + if (num < 0) return -1; + if (num == 0) return 0; + + if (num >= 1) stats[0] = nr->stats.in; + if (num >= 2) stats[1] = nr->stats.out; + if (num >= 3) stats[2] = nr->stats.dup; + if (num >= 4) stats[3] = nr->stats.dropped; + if (num >= 5) stats[4] = nr->num_workers; + + if (num <= 5) return num; + + return 5; +} diff --git a/src/lib/io/network.h b/src/lib/io/network.h index 1f47fa78c95..ba4757c9b96 100644 --- a/src/lib/io/network.h +++ b/src/lib/io/network.h @@ -44,6 +44,7 @@ int fr_network_directory_add(fr_network_t *nr, fr_listen_t const *listen) CC_HIN int fr_network_worker_add(fr_network_t *nr, fr_worker_t *worker) CC_HINT(nonnull); void fr_network_listen_read(fr_network_t *nr, fr_listen_t const *listen) CC_HINT(nonnull); int fr_network_listen_inject(fr_network_t *nr, fr_listen_t *listen, uint8_t const *packet, size_t packet_len, fr_time_t recv_time); +int fr_network_stats(fr_network_t const *nr, int num, uint64_t *stats) CC_HINT(nonnull); #ifdef __cplusplus } diff --git a/src/lib/io/worker.c b/src/lib/io/worker.c index 3044588ca64..27a12d5c1c2 100644 --- a/src/lib/io/worker.c +++ b/src/lib/io/worker.c @@ -144,9 +144,9 @@ struct fr_worker_t { fr_io_stats_t stats; - int num_decoded; //!< number of messages which have been decoded - int num_timeouts; //!< number of messages which timed out - int num_active; //!< number of active requests + uint64_t num_decoded; //!< number of messages which have been decoded + uint64_t num_timeouts; //!< number of messages which timed out + uint64_t num_active; //!< number of active requests fr_time_tracking_t tracking; //!< how much time the worker has spent doing things. @@ -617,7 +617,7 @@ static void fr_worker_max_request_time(UNUSED fr_event_list_t *el, UNUSED struct REQUEST *request; fr_worker_t *worker = talloc_get_type_abort(uctx, fr_worker_t); - DEBUG2("TIMER - worker max_request_time - %d active requests", worker->num_active); + DEBUG2("TIMER - worker max_request_time - %" PRIu64 " active requests", worker->num_active); /* * Look at the oldest requests, and see if they need to @@ -1105,7 +1105,7 @@ static int fr_worker_pre_event(void *ctx, struct timeval *wake) fr_heap_num_elements(worker->runnable), fr_heap_num_elements(worker->localized.heap), fr_heap_num_elements(worker->to_decode.heap)); - DEBUG3("\t%srequests %" PRIu64 ", decoded %d, replied %" PRIu64 " active %d", + DEBUG3("\t%srequests %" PRIu64 ", decoded %" PRIu64 ", replied %" PRIu64 " active %" PRIu64 "", worker->name, worker->stats.in, worker->num_decoded, worker->stats.out, worker->num_active); @@ -1604,3 +1604,21 @@ static void fr_worker_verify(fr_worker_t *worker) } } #endif + +int fr_worker_stats(fr_worker_t const *worker, int num, uint64_t *stats) +{ + if (num < 0) return -1; + if (num == 0) return 0; + + if (num >= 1) stats[0] = worker->stats.in; + if (num >= 2) stats[1] = worker->stats.out; + if (num >= 3) stats[2] = worker->stats.dup; + if (num >= 4) stats[3] = worker->stats.dropped; + if (num >= 5) stats[4] = worker->num_decoded; + if (num >= 6) stats[5] = worker->num_timeouts; + if (num >= 7) stats[6] = worker->num_active; + + if (num <= 7) return num; + + return 7; +} diff --git a/src/lib/io/worker.h b/src/lib/io/worker.h index ae56f5ea0b1..054e4ef6d70 100644 --- a/src/lib/io/worker.h +++ b/src/lib/io/worker.h @@ -53,6 +53,7 @@ void fr_worker_exit(fr_worker_t *worker) CC_HINT(nonnull); void fr_worker_debug(fr_worker_t *worker, FILE *fp) CC_HINT(nonnull); void fr_worker_name(fr_worker_t *worker, char const *name) CC_HINT(nonnull); fr_channel_t *fr_worker_channel_create(fr_worker_t *worker, TALLOC_CTX *ctx, fr_control_t *master) CC_HINT(nonnull); +int fr_worker_stats(fr_worker_t const *worker, int num, uint64_t *stats) CC_HINT(nonnull); #ifdef __cplusplus }