From: Vsevolod Stakhov Date: Thu, 12 Dec 2019 20:27:03 +0000 (+0000) Subject: [Minor] Add ability to log mempool usage for a task X-Git-Tag: 2.3~218 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f3587ce1bebb7fcaf529f796dbcec6e436253c05;p=rspamd.git [Minor] Add ability to log mempool usage for a task --- diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index fbddd9096..8e1ce2c42 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -262,6 +262,8 @@ enum rspamd_log_format_type { RSPAMD_LOG_SETTINGS_ID, RSPAMD_LOG_GROUPS, RSPAMD_LOG_PUBLIC_GROUPS, + RSPAMD_LOG_MEMPOOL_SIZE, + RSPAMD_LOG_MEMPOOL_WASTE, }; enum rspamd_log_format_flags { diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index 857f7a0ac..76731eec4 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -518,6 +518,12 @@ rspamd_config_process_var (struct rspamd_config *cfg, const rspamd_ftok_t *var, else if (rspamd_ftok_cstr_equal (&tok, "settings_id", TRUE)) { type = RSPAMD_LOG_SETTINGS_ID; } + else if (rspamd_ftok_cstr_equal (&tok, "mempool_size", TRUE)) { + type = RSPAMD_LOG_MEMPOOL_SIZE; + } + else if (rspamd_ftok_cstr_equal (&tok, "mempool_waste", TRUE)) { + type = RSPAMD_LOG_MEMPOOL_WASTE; + } else { msg_err_config ("unknown log variable: %T", &tok); return FALSE; diff --git a/src/libserver/task.c b/src/libserver/task.c index 2fb9bf1d9..7cdce32f3 100644 --- a/src/libserver/task.c +++ b/src/libserver/task.c @@ -1544,6 +1544,18 @@ rspamd_task_log_variable (struct rspamd_task *task, var.len = sizeof (undef) - 1; } break; + case RSPAMD_LOG_MEMPOOL_SIZE: + var.len = rspamd_snprintf (numbuf, sizeof (numbuf), + "%Hz", + task->task_pool->used_memory); + var.begin = numbuf; + break; + case RSPAMD_LOG_MEMPOOL_WASTE: + var.len = rspamd_snprintf (numbuf, sizeof (numbuf), + "%Hz", + task->task_pool->wasted_memory); + var.begin = numbuf; + break; default: var = rspamd_task_log_metric_res (task, lf); break;