Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sources/logger.c: add logger machine stats #726

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions sources/cron.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
23 changes: 23 additions & 0 deletions sources/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down