logging: Cleanup in the internal headers
Added log_internal.h for internal APIs. Move functions out of log_core.h. Log_core.h shall have only macros and functions related to logging message creation. Log_core.h is included by log.h thus number of dependencies in that headers must be limited to minimum to allow including without risk of circular dependencies. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
parent
8d20e8d5bc
commit
03165c914b
|
@ -7,7 +7,7 @@
|
|||
#define ZEPHYR_INCLUDE_LOGGING_LOG_CORE_H_
|
||||
|
||||
#include <logging/log_msg.h>
|
||||
#include <logging/log_core2.h>
|
||||
#include <logging/log_msg2.h>
|
||||
#include <logging/log_instance.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
@ -15,6 +15,9 @@
|
|||
#include <syscall.h>
|
||||
#include <sys/util.h>
|
||||
|
||||
/* This header file keeps all macros and functions needed for creating logging
|
||||
* messages (macros like @ref LOG_ERR).
|
||||
*/
|
||||
#define LOG_LEVEL_NONE 0U
|
||||
#define LOG_LEVEL_ERR 1U
|
||||
#define LOG_LEVEL_WRN 2U
|
||||
|
@ -481,27 +484,6 @@ enum log_strdup_action {
|
|||
LOG_LEVEL_INTERNAL_RAW_STRING, NULL, 0, __VA_ARGS__);\
|
||||
} while (0)
|
||||
|
||||
|
||||
/** @brief Get name of the log source.
|
||||
*
|
||||
* @param source_id Source ID.
|
||||
* @return Name.
|
||||
*/
|
||||
static inline const char *log_name_get(uint32_t source_id)
|
||||
{
|
||||
return __log_const_start[source_id].name;
|
||||
}
|
||||
|
||||
/** @brief Get compiled level of the log source.
|
||||
*
|
||||
* @param source_id Source ID.
|
||||
* @return Level.
|
||||
*/
|
||||
static inline uint8_t log_compiled_level_get(uint32_t source_id)
|
||||
{
|
||||
return __log_const_start[source_id].level;
|
||||
}
|
||||
|
||||
/** @brief Get index of the log source based on the address of the constant data
|
||||
* associated with the source.
|
||||
*
|
||||
|
@ -516,12 +498,6 @@ static inline uint32_t log_const_source_id(
|
|||
sizeof(struct log_source_const_data);
|
||||
}
|
||||
|
||||
/** @brief Get number of registered sources. */
|
||||
static inline uint32_t log_sources_count(void)
|
||||
{
|
||||
return log_const_source_id(__log_const_end);
|
||||
}
|
||||
|
||||
extern struct log_source_dynamic_data __log_dynamic_start[];
|
||||
extern struct log_source_dynamic_data __log_dynamic_end[];
|
||||
|
||||
|
@ -534,17 +510,6 @@ extern struct log_source_dynamic_data __log_dynamic_end[];
|
|||
#define LOG_INSTANCE_DYNAMIC_DATA(_module_name, _inst) \
|
||||
LOG_ITEM_DYNAMIC_DATA(LOG_INSTANCE_FULL_NAME(_module_name, _inst))
|
||||
|
||||
/** @brief Get pointer to the filter set of the log source.
|
||||
*
|
||||
* @param source_id Source ID.
|
||||
*
|
||||
* @return Pointer to the filter set.
|
||||
*/
|
||||
static inline uint32_t *log_dynamic_filters_get(uint32_t source_id)
|
||||
{
|
||||
return &__log_dynamic_start[source_id].filters;
|
||||
}
|
||||
|
||||
/** @brief Get index of the log source based on the address of the dynamic data
|
||||
* associated with the source.
|
||||
*
|
||||
|
@ -558,12 +523,6 @@ static inline uint32_t log_dynamic_source_id(struct log_source_dynamic_data *dat
|
|||
sizeof(struct log_source_dynamic_data);
|
||||
}
|
||||
|
||||
/* Initialize runtime filters */
|
||||
void z_log_runtime_filters_init(void);
|
||||
|
||||
/* Notify log_core that a backend was enabled. */
|
||||
void z_log_notify_backend_enabled(void);
|
||||
|
||||
/** @brief Dummy function to trigger log messages arguments type checking. */
|
||||
static inline __printf_like(1, 2)
|
||||
void z_log_printf_arg_checker(const char *fmt, ...)
|
||||
|
@ -710,49 +669,6 @@ void log_generic_from_user(struct log_msg_ids src_level,
|
|||
*/
|
||||
bool log_is_strdup(const void *buf);
|
||||
|
||||
/** @brief Free allocated buffer.
|
||||
*
|
||||
* @param buf Buffer.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* Value can be used to determine pool size.
|
||||
*/
|
||||
uint32_t log_get_strdup_pool_utilization(void);
|
||||
|
||||
/**
|
||||
* @brief Get length of the longest string duplicated.
|
||||
*
|
||||
* Value can be used to determine buffer size in the string duplicates pool.
|
||||
*/
|
||||
uint32_t log_get_strdup_longest_string(void);
|
||||
|
||||
/** @brief Indicate to the log core that one log message has been dropped.
|
||||
*/
|
||||
void z_log_dropped(void);
|
||||
|
||||
/** @brief Read and clear current drop indications counter.
|
||||
*
|
||||
* @return Dropped count.
|
||||
*/
|
||||
uint32_t z_log_dropped_read_and_clear(void);
|
||||
|
||||
/** @brief Check if there are any pending drop notifications.
|
||||
*
|
||||
* @retval true Pending unreported drop indications.
|
||||
* @retval false No pending unreported drop indications.
|
||||
*/
|
||||
bool z_log_dropped_pending(void);
|
||||
|
||||
/** @brief Log a message from user mode context.
|
||||
*
|
||||
* @note This function is intended to be used internally
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef ZEPHYR_INCLUDE_LOGGING_LOG_CORE2_H_
|
||||
#define ZEPHYR_INCLUDE_LOGGING_LOG_CORE2_H_
|
||||
|
||||
#include <logging/log_msg2.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define Z_TRACING_LOG_TRACE(id) do { \
|
||||
Z_TRACING_LOG_HDR_INIT(_msg, id); \
|
||||
z_log_msg2_put_trace(_msg); \
|
||||
} while (0)
|
||||
|
||||
#define Z_TRACING_LOG_TRACE_PTR(id, ptr) do { \
|
||||
Z_TRACING_LOG_HDR_INIT(_msg, id); \
|
||||
z_log_msg2_put_trace_ptr(_msg, ptr); \
|
||||
} while (0)
|
||||
|
||||
void z_log_msg2_put_trace(struct log_msg2_trace trace);
|
||||
|
||||
void z_log_msg2_put_trace_ptr(struct log_msg2_trace hdr, void *data);
|
||||
|
||||
|
||||
/** @brief Initialize module for handling logging message. */
|
||||
void z_log_msg2_init(void);
|
||||
|
||||
/** @brief Allocate log message.
|
||||
*
|
||||
* @param wlen Length in 32 bit words.
|
||||
*
|
||||
* @return allocated space or null if cannot be allocated.
|
||||
*/
|
||||
struct log_msg2 *z_log_msg2_alloc(uint32_t wlen);
|
||||
|
||||
/** @brief Commit log message.
|
||||
*
|
||||
* @param msg Message.
|
||||
*/
|
||||
void z_log_msg2_commit(struct log_msg2 *msg);
|
||||
|
||||
/** @brief Get pending log message.
|
||||
*
|
||||
* @param[out] len Message length in bytes is written is @p len is not null.
|
||||
*
|
||||
* @param Message or null if no pending messages.
|
||||
*/
|
||||
union log_msg2_generic *z_log_msg2_claim(void);
|
||||
|
||||
/** @brief Free message.
|
||||
*
|
||||
* @param msg Message.
|
||||
*/
|
||||
void z_log_msg2_free(union log_msg2_generic *msg);
|
||||
|
||||
/** @brief Check if there are any message pending.
|
||||
*
|
||||
* @retval true if at least one message is pending.
|
||||
* @retval false if no message is pending.
|
||||
*/
|
||||
bool z_log_msg2_pending(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_LOGGING_LOG_CORE2_H_ */
|
|
@ -169,6 +169,26 @@ void log_backend_enable(struct log_backend const *const backend,
|
|||
*/
|
||||
void log_backend_disable(struct log_backend const *const backend);
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*
|
||||
* Value can be used to determine pool size.
|
||||
*/
|
||||
uint32_t log_get_strdup_pool_utilization(void);
|
||||
|
||||
/**
|
||||
* @brief Get length of the longest string duplicated.
|
||||
*
|
||||
* Value can be used to determine buffer size in the string duplicates pool.
|
||||
*/
|
||||
uint32_t log_get_strdup_longest_string(void);
|
||||
|
||||
#if defined(CONFIG_LOG) && !defined(CONFIG_LOG_MINIMAL)
|
||||
#define LOG_CORE_INIT() log_core_init()
|
||||
#define LOG_INIT() log_init()
|
||||
|
|
102
include/logging/log_internal.h
Normal file
102
include/logging/log_internal.h
Normal file
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef ZEPHYR_INCLUDE_LOGGING_LOG_INTERNAL_H_
|
||||
#define ZEPHYR_INCLUDE_LOGGING_LOG_INTERNAL_H_
|
||||
|
||||
#include <zephyr/types.h>
|
||||
#include <sys/__assert.h>
|
||||
#include <logging/log_core.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Header contains declarations of functions used internally in the logging,
|
||||
* shared between various portions of logging subsystem. Functions are internal
|
||||
* not intended to be used outside, including logging backends.
|
||||
*/
|
||||
|
||||
/** @brief Indicate to the log core that one log message has been dropped.
|
||||
*/
|
||||
void z_log_dropped(void);
|
||||
|
||||
/** @brief Read and clear current drop indications counter.
|
||||
*
|
||||
* @return Dropped count.
|
||||
*/
|
||||
uint32_t z_log_dropped_read_and_clear(void);
|
||||
|
||||
/** @brief Check if there are any pending drop notifications.
|
||||
*
|
||||
* @retval true Pending unreported drop indications.
|
||||
* @retval false No pending unreported drop indications.
|
||||
*/
|
||||
bool z_log_dropped_pending(void);
|
||||
|
||||
/** @brief Free allocated buffer.
|
||||
*
|
||||
* @param buf Buffer.
|
||||
*/
|
||||
void log_free(void *buf);
|
||||
|
||||
/* Initialize runtime filters */
|
||||
void z_log_runtime_filters_init(void);
|
||||
|
||||
/* Notify log_core that a backend was enabled. */
|
||||
void z_log_notify_backend_enabled(void);
|
||||
|
||||
/** @brief Get pointer to the filter set of the log source.
|
||||
*
|
||||
* @param source_id Source ID.
|
||||
*
|
||||
* @return Pointer to the filter set.
|
||||
*/
|
||||
static inline uint32_t *log_dynamic_filters_get(uint32_t source_id)
|
||||
{
|
||||
return &__log_dynamic_start[source_id].filters;
|
||||
}
|
||||
|
||||
/** @brief Get number of registered sources. */
|
||||
static inline uint32_t log_sources_count(void)
|
||||
{
|
||||
return log_const_source_id(__log_const_end);
|
||||
}
|
||||
|
||||
/** @brief Initialize module for handling logging message. */
|
||||
void z_log_msg2_init(void);
|
||||
|
||||
/** @brief Commit log message.
|
||||
*
|
||||
* @param msg Message.
|
||||
*/
|
||||
void z_log_msg2_commit(struct log_msg2 *msg);
|
||||
|
||||
/** @brief Get pending log message.
|
||||
*
|
||||
* @param[out] len Message length in bytes is written is @p len is not null.
|
||||
*
|
||||
* @param Message or null if no pending messages.
|
||||
*/
|
||||
union log_msg2_generic *z_log_msg2_claim(void);
|
||||
|
||||
/** @brief Free message.
|
||||
*
|
||||
* @param msg Message.
|
||||
*/
|
||||
void z_log_msg2_free(union log_msg2_generic *msg);
|
||||
|
||||
/** @brief Check if there are any message pending.
|
||||
*
|
||||
* @retval true if at least one message is pending.
|
||||
* @retval false if no message is pending.
|
||||
*/
|
||||
bool z_log_msg2_pending(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_LOGGING_LOG_INTERNAL_H_ */
|
|
@ -434,6 +434,14 @@ do { \
|
|||
} \
|
||||
}
|
||||
|
||||
/** @brief Allocate log message.
|
||||
*
|
||||
* @param wlen Length in 32 bit words.
|
||||
*
|
||||
* @return allocated space or null if cannot be allocated.
|
||||
*/
|
||||
struct log_msg2 *z_log_msg2_alloc(uint32_t wlen);
|
||||
|
||||
/** @brief Finalize message.
|
||||
*
|
||||
* Finalization includes setting source, copying data and timestamp in the
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <shell/shell.h>
|
||||
#include <logging/log_ctrl.h>
|
||||
#include <logging/log.h>
|
||||
#include <logging/log_internal.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef int (*log_backend_cmd_t)(const struct shell *shell,
|
||||
|
|
|
@ -9,8 +9,7 @@
|
|||
#include <logging/log_backend.h>
|
||||
#include <logging/log_ctrl.h>
|
||||
#include <logging/log_output.h>
|
||||
#include <logging/log_msg2.h>
|
||||
#include <logging/log_core2.h>
|
||||
#include <logging/log_internal.h>
|
||||
#include <sys/mpsc_pbuf.h>
|
||||
#include <sys/printk.h>
|
||||
#include <sys_clock.h>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include <logging/log_core.h>
|
||||
#include <logging/log_internal.h>
|
||||
#include <logging/log_ctrl.h>
|
||||
#include <syscall_handler.h>
|
||||
|
||||
|
@ -12,6 +12,16 @@
|
|||
* - controlling backends filtering
|
||||
*/
|
||||
|
||||
/** @brief Get compiled level of the log source.
|
||||
*
|
||||
* @param source_id Source ID.
|
||||
* @return Level.
|
||||
*/
|
||||
static inline uint8_t log_compiled_level_get(uint32_t source_id)
|
||||
{
|
||||
return __log_const_start[source_id].level;
|
||||
}
|
||||
|
||||
void z_log_runtime_filters_init(void)
|
||||
{
|
||||
/*
|
||||
|
@ -38,6 +48,16 @@ uint32_t log_src_cnt_get(uint32_t domain_id)
|
|||
return log_sources_count();
|
||||
}
|
||||
|
||||
/** @brief Get name of the log source.
|
||||
*
|
||||
* @param source_id Source ID.
|
||||
* @return Name.
|
||||
*/
|
||||
static inline const char *log_name_get(uint32_t source_id)
|
||||
{
|
||||
return __log_const_start[source_id].name;
|
||||
}
|
||||
|
||||
const char *log_source_name_get(uint32_t domain_id, uint32_t src_id)
|
||||
{
|
||||
return src_id < log_sources_count() ? log_name_get(src_id) : NULL;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <logging/log.h>
|
||||
#include <logging/log_msg.h>
|
||||
#include <logging/log_ctrl.h>
|
||||
#include <logging/log_core.h>
|
||||
#include <logging/log_internal.h>
|
||||
#include <sys/__assert.h>
|
||||
#include <string.h>
|
||||
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
*/
|
||||
#include <zephyr.h>
|
||||
#include <syscall_handler.h>
|
||||
#include <logging/log_msg2.h>
|
||||
#include <logging/log_core.h>
|
||||
#include <logging/log_internal.h>
|
||||
#include <logging/log_ctrl.h>
|
||||
|
||||
void z_log_msg2_finalize(struct log_msg2 *msg, const void *source,
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include "test_helpers.h"
|
||||
#include <logging/log_core.h>
|
||||
#include <logging/log_internal.h>
|
||||
#include <logging/log_ctrl.h>
|
||||
|
||||
|
||||
|
|
|
@ -10,9 +10,8 @@
|
|||
*/
|
||||
|
||||
#include <logging/log_msg2.h>
|
||||
#include <logging/log_core.h>
|
||||
#include <logging/log_internal.h>
|
||||
#include <logging/log_ctrl.h>
|
||||
#include <logging/log_instance.h>
|
||||
|
||||
#include <tc_util.h>
|
||||
#include <stdbool.h>
|
||||
|
|
Loading…
Reference in a new issue