Commit b52ad8f3 authored by Andrew Hedin's avatar Andrew Hedin Committed by Christopher Friedt
Browse files

logging: Add strdup current use to shell cmd



Add the number of strdup buffers currently in use to the
`log strdup_utilization` shell command.

Signed-off-by: default avatarAndrew Hedin <andrew.hedin@lairdconnect.com>
parent 185545e9
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -716,6 +716,11 @@ bool log_is_strdup(const void *buf);
 */
void log_free(void *buf);

/**
 * @brief Get current number of allocated buffers for string duplicates.
 */
uint32_t log_get_strdup_pool_current_utilization(void);

/**
 * @brief Get maximal number of simultaneously allocated buffers for string
 *	  duplicates.
+4 −0
Original line number Diff line number Diff line
@@ -376,11 +376,15 @@ static int cmd_log_strdup_utilization(const struct shell *shell,
	#define CONFIG_LOG_STRDUP_MAX_STRING 0
	#endif

	uint32_t cur_cnt = log_get_strdup_pool_current_utilization();
	uint32_t buf_cnt = log_get_strdup_pool_utilization();
	uint32_t buf_size = log_get_strdup_longest_string();
	uint32_t percent = CONFIG_LOG_STRDUP_BUF_COUNT ?
			buf_cnt * 100U / CONFIG_LOG_STRDUP_BUF_COUNT : 0U;

	shell_print(shell, "Current utilization of the buffer pool: %d.",
		    cur_cnt);

	shell_print(shell,
		"Maximal utilization of the buffer pool: %d / %d (%d %%).",
		buf_cnt, CONFIG_LOG_STRDUP_BUF_COUNT, percent);
+7 −0
Original line number Diff line number Diff line
@@ -904,6 +904,13 @@ char *z_log_strdup(const char *str)
	return dup->buf;
}

uint32_t log_get_strdup_pool_current_utilization(void)
{
	return IS_ENABLED(CONFIG_LOG_STRDUP_POOL_PROFILING) ?
			log_strdup_in_use : 0;

}

uint32_t log_get_strdup_pool_utilization(void)
{
	return IS_ENABLED(CONFIG_LOG_STRDUP_POOL_PROFILING) ?