diff --git a/sources/cron.c b/sources/cron.c index 2e0944e6..a62831f1 100644 --- a/sources/cron.c +++ b/sources/cron.c @@ -94,6 +94,28 @@ static int od_cron_stat_cb(od_route_t *route, od_stat_t *current, return 0; } +static inline void send_msg_stat(machine_channel_t *chan) +{ + machine_msg_t *msg; + msg = machine_msg_create(0); + machine_msg_set_type(msg, OD_MSG_STAT); + machine_channel_write(chan, msg); +} + +static inline void request_logger_stats(od_logger_t *logger) +{ + send_msg_stat(logger->task_channel); +} + +static inline void request_worker_stats(od_worker_pool_t *worker_pool) +{ + uint32_t i; + for (i = 0; i < worker_pool->count; i++) { + od_worker_t *worker = &worker_pool->pool[i]; + send_msg_stat(worker->task_channel); + } +} + static inline void od_cron_stat(od_cron_t *cron) { od_router_t *router = cron->global->router; @@ -138,14 +160,9 @@ static inline void od_cron_stat(od_cron_t *cron) startup_errors); /* request stats per worker */ - uint32_t i; - for (i = 0; i < worker_pool->count; i++) { - od_worker_t *worker = &worker_pool->pool[i]; - machine_msg_t *msg; - msg = machine_msg_create(0); - machine_msg_set_type(msg, OD_MSG_STAT); - machine_channel_write(worker->task_channel, msg); - } + request_worker_stats(worker_pool); + + request_logger_stats(&instance->logger); od_log(&instance->logger, "stats", NULL, NULL, "clients %d", od_atomic_u32_of(&router->clients)); diff --git a/sources/logger.c b/sources/logger.c index 7b720434..7fd22e65 100644 --- a/sources/logger.c +++ b/sources/logger.c @@ -446,6 +446,25 @@ static inline void _od_logger_write(od_logger_t *l, char *data, int len, (void)rc; } +static inline void log_machine_stats(od_logger_t *logger) +{ + uint64_t count_coroutine = 0; + uint64_t count_coroutine_cache = 0; + uint64_t msg_allocated = 0; + uint64_t msg_cache_count = 0; + uint64_t msg_cache_gc_count = 0; + uint64_t msg_cache_size = 0; + machine_stat(&count_coroutine, &count_coroutine_cache, &msg_allocated, + &msg_cache_count, &msg_cache_gc_count, &msg_cache_size); + + od_log(logger, "stats", NULL, NULL, + "logger: msg (%" PRIu64 " allocated, %" PRIu64 + " cached, %" PRIu64 " freed, %" PRIu64 " cache_size), " + "coroutines (%" PRIu64 " active, %" PRIu64 " cached)", + msg_allocated, msg_cache_count, msg_cache_gc_count, + msg_cache_size, count_coroutine, count_coroutine_cache); +} + static inline void od_logger(void *arg) { od_logger_t *logger = arg; @@ -465,6 +484,10 @@ static inline void od_logger(void *arg) _od_logger_write(logger, le->msg, len, le->lvl); } break; + case OD_MSG_STAT: { + log_machine_stats(logger); + break; + } default: { assert(0); } break;