-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
logging: rpc: initial history support
Add initial code for supporting the log history, that is, the mode of nRF RPC logging library in which log messages are stored in a ring buffer, and nRF RPC commands can be used for configuring and fetching the log history. The rationale for supporting this mode is to reduce the nRF RPC traffic so that the bandwidth is available for higher priority tasks, while preserving the possibility to analyse the logs when an issue occurs. This commit adds the support for saving the log messages in the ring buffer. Fetching the logs is still incomplete though. Signed-off-by: Damian Krolik <[email protected]>
- Loading branch information
1 parent
b4851ab
commit bedfb9a
Showing
10 changed files
with
317 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright (c) 2024 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
#ifndef LOG_RPC_HISTORY_H_ | ||
#define LOG_RPC_HISTORY_H_ | ||
|
||
#include <zephyr/logging/log_msg.h> | ||
|
||
void log_rpc_history_init(void); | ||
|
||
void log_rpc_history_push(const union log_msg_generic *msg); | ||
|
||
const union log_msg_generic *log_rpc_history_pop(void); | ||
void log_rpc_history_free(const union log_msg_generic *msg); | ||
|
||
#endif /* LOG_RPC_HISTORY_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2024 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
#include "log_backend_rpc_history.h" | ||
|
||
#include <zephyr/sys/mpsc_pbuf.h> | ||
#include <zephyr/sys/util.h> | ||
|
||
#define HISTORY_WLEN (CONFIG_LOG_BACKEND_RPC_HISTORY_SIZE / sizeof(uint32_t)) | ||
|
||
static uint32_t __aligned(Z_LOG_MSG_ALIGNMENT) log_history_raw[HISTORY_WLEN]; | ||
static struct mpsc_pbuf_buffer log_history_pbuf; | ||
|
||
void log_rpc_history_init(void) | ||
{ | ||
const struct mpsc_pbuf_buffer_config log_history_config = { | ||
.buf = log_history_raw, | ||
.size = ARRAY_SIZE(log_history_raw), | ||
.get_wlen = log_msg_generic_get_wlen, | ||
.flags = MPSC_PBUF_MODE_OVERWRITE, | ||
}; | ||
|
||
mpsc_pbuf_init(&log_history_pbuf, &log_history_config); | ||
} | ||
|
||
void log_rpc_history_push(const union log_msg_generic *msg) | ||
{ | ||
uint32_t wlen; | ||
union log_msg_generic *copy; | ||
int len; | ||
|
||
wlen = log_msg_generic_get_wlen(&msg->buf); | ||
copy = (union log_msg_generic *)mpsc_pbuf_alloc(&log_history_pbuf, wlen, K_NO_WAIT); | ||
|
||
if (!copy) { | ||
return; | ||
} | ||
|
||
copy->log.hdr = msg->log.hdr; | ||
len = cbprintf_package_copy((void *)msg->log.data, msg->log.hdr.desc.package_len, | ||
copy->log.data, msg->log.hdr.desc.package_len, 0, NULL, 0); | ||
__ASSERT_NO_MSG(len == msg->log.hdr.desc.package_len); | ||
|
||
mpsc_pbuf_commit(&log_history_pbuf, ©->buf); | ||
} | ||
|
||
const union log_msg_generic *log_rpc_history_pop(void) | ||
{ | ||
return (const union log_msg_generic *)mpsc_pbuf_claim(&log_history_pbuf); | ||
} | ||
|
||
void log_rpc_history_free(const union log_msg_generic *msg) | ||
{ | ||
mpsc_pbuf_free(&log_history_pbuf, &msg->buf); | ||
} |
Oops, something went wrong.