Skip to content

Commit f4202c6

Browse files
committed
logging: add support for dictionary based logging
This adds dictionary based logging support. Dictionary based logging is binary based where one big difference is that static strings are stored as pointers instead of the whole string. This results in reduced space requirements for storing log messages in certain scenairos. Signed-off-by: Daniel Leung <[email protected]>
1 parent 6fd0a0a commit f4202c6

File tree

13 files changed

+1391
-0
lines changed

13 files changed

+1391
-0
lines changed

CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,24 @@ list(APPEND
13921392
${extra_post_build_byproducts}
13931393
)
13941394

1395+
if(CONFIG_LOG_DICTIONARY_SUPPORT)
1396+
set(LOG_DICT_DB_NAME ${PROJECT_BINARY_DIR}/log_dictionary.json)
1397+
1398+
list(APPEND
1399+
post_build_commands
1400+
COMMAND
1401+
${PYTHON_EXECUTABLE}
1402+
${ZEPHYR_BASE}/scripts/logging/dictionary/database_gen.py
1403+
${KERNEL_ELF_NAME}
1404+
${LOG_DICT_DB_NAME}
1405+
--build ${BUILD_VERSION}
1406+
)
1407+
list(APPEND
1408+
post_build_byproducts
1409+
${LOG_DICT_DB_NAME}
1410+
)
1411+
endif()
1412+
13951413
# Add post_build_commands to post-process the final .elf file produced by
13961414
# either the ZEPHYR_PREBUILT_EXECUTABLE or the KERNEL_ELF executable
13971415
# targets above.

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@
534534
/scripts/coccinelle/ @himanshujha199640 @JuliaLawall
535535
/scripts/coredump/ @dcpleung
536536
/scripts/kconfig/ @ulfalizer
537+
/scripts/logging/dictionary/ @dcpleung
537538
/scripts/pylib/twister/expr_parser.py @nashif
538539
/scripts/schemas/twister/ @nashif
539540
/scripts/gen_app_partitions.py @dcpleung @nashif

include/logging/log_output_dict.h

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright (c) 2018 Nordic Semiconductor ASA
3+
* Copyright (c) 2021 Intel Corporation
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
#ifndef ZEPHYR_INCLUDE_LOGGING_LOG_OUTPUT_DICT_H_
8+
#define ZEPHYR_INCLUDE_LOGGING_LOG_OUTPUT_DICT_H_
9+
10+
#include <logging/log_output.h>
11+
#include <logging/log_msg2.h>
12+
#include <stdarg.h>
13+
#include <toolchain.h>
14+
#include <sys/util.h>
15+
16+
#ifdef __cplusplus
17+
extern "C" {
18+
#endif
19+
20+
/**
21+
* Log message type
22+
*/
23+
enum log_dict_output_msg_type {
24+
MSG_NORMAL = 0,
25+
MSG_DROPPED_MSG = 1,
26+
};
27+
28+
/**
29+
* Output header for one dictionary based log message.
30+
*/
31+
struct log_dict_output_normal_msg_hdr_t {
32+
uint8_t type;
33+
uint32_t domain:3;
34+
uint32_t level:3;
35+
uint32_t package_len:10;
36+
uint32_t data_len:12;
37+
uintptr_t source;
38+
log_timestamp_t timestamp;
39+
} __packed;
40+
41+
/**
42+
* Output for one dictionary based log message about
43+
* dropped messages.
44+
*/
45+
struct log_dict_output_dropped_msg_t {
46+
uint8_t type;
47+
uint16_t num_dropped_messages;
48+
} __packed;
49+
50+
/** @brief Process log messages v2 for dictionary-basde logging.
51+
*
52+
* Function is using provided context with the buffer and output function to
53+
* process formatted string and output the data.
54+
*
55+
* @param log_output Pointer to the log output instance.
56+
* @param msg Log message.
57+
* @param flags Optional flags.
58+
*/
59+
void log_dict_output_msg2_process(const struct log_output *log_output,
60+
struct log_msg2 *msg, uint32_t flags);
61+
62+
/** @brief Process dropped messages indication for dictionary-based logging.
63+
*
64+
* Function prints error message indicating lost log messages.
65+
*
66+
* @param output Pointer to the log output instance.
67+
* @param cnt Number of dropped messages.
68+
*/
69+
void log_dict_output_dropped_process(const struct log_output *output, uint32_t cnt);
70+
71+
#ifdef __cplusplus
72+
}
73+
#endif
74+
75+
#endif /* ZEPHYR_INCLUDE_LOGGING_LOG_OUTPUT_DICT_H_ */

0 commit comments

Comments
 (0)