Skip to content

Commit a5ab1a7

Browse files
dcpleungcarlescufi
authored andcommitted
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 2c6da98 commit a5ab1a7

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
@@ -1524,6 +1524,24 @@ list(APPEND
15241524
${extra_post_build_byproducts}
15251525
)
15261526

1527+
if(CONFIG_LOG_DICTIONARY_SUPPORT)
1528+
set(LOG_DICT_DB_NAME ${PROJECT_BINARY_DIR}/log_dictionary.json)
1529+
1530+
list(APPEND
1531+
post_build_commands
1532+
COMMAND
1533+
${PYTHON_EXECUTABLE}
1534+
${ZEPHYR_BASE}/scripts/logging/dictionary/database_gen.py
1535+
${KERNEL_ELF_NAME}
1536+
${LOG_DICT_DB_NAME}
1537+
--build ${BUILD_VERSION}
1538+
)
1539+
list(APPEND
1540+
post_build_byproducts
1541+
${LOG_DICT_DB_NAME}
1542+
)
1543+
endif()
1544+
15271545
# Add post_build_commands to post-process the final .elf file produced by
15281546
# either the ZEPHYR_PREBUILT_EXECUTABLE or the KERNEL_ELF executable
15291547
# targets above.

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@
537537
/scripts/coccinelle/ @himanshujha199640 @JuliaLawall
538538
/scripts/coredump/ @dcpleung
539539
/scripts/kconfig/ @ulfalizer
540+
/scripts/logging/dictionary/ @dcpleung
540541
/scripts/pylib/twister/expr_parser.py @nashif
541542
/scripts/schemas/twister/ @nashif
542543
/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)