Skip to content

Commit cf8d490

Browse files
MarekPorwiszrlubos
authored andcommitted
rpc: Add possibility to measure command execution time
Added measuring the command execution time. The time is printed as an INFO log level after the command is complete. Signed-off-by: Marek Porwisz <[email protected]>
1 parent 994e3c6 commit cf8d490

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

nrf_rpc/CHANGELOG.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ Changelog
99

1010
All the notable changes to this project are documented on this page.
1111

12+
nRF Connect SDK v3.1.99
13+
***********************
14+
15+
Added
16+
=====
17+
18+
* Added the possibility to measure command execution time.
19+
You can enable this feature with the :kconfig:option:`CONFIG_NRF_RPC_COMMAND_TIME_MEASURE` Kconfig option.
20+
You must also implement the :c:func:`nrf_rpc_os_timestamp_get_now` function, which returns the current timestamp expressed in milliseconds.
21+
1222
nRF Connect SDK v3.1.0
1323
**********************
1424

nrf_rpc/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,11 @@ config NRF_RPC_THREAD_POOL_SIZE
7070
the remote side. If there is no available threads then remote side
7171
will wait.
7272

73+
config NRF_RPC_COMMAND_TIME_MEASURE
74+
bool "Measure command execution time"
75+
help
76+
Measure the time between sending the command and receiving the response
77+
and log the value. Time measured includes the transmission and reception
78+
time. Log level for the time measurement is CONFIG_NRF_RPC_LOG_LEVEL_INF.
79+
7380
endif # NRF_RPC

nrf_rpc/nrf_rpc.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,7 @@ int nrf_rpc_cmd_common(const struct nrf_rpc_group *group, uint32_t cmd,
944944
const uint8_t **rsp_packet = NULL;
945945
size_t *rsp_len = NULL;
946946
struct nrf_rpc_cmd_ctx *cmd_ctx;
947+
uint64_t processing_time;
947948

948949
NRF_RPC_ASSERT(group != NULL);
949950
NRF_RPC_ASSERT((cmd & 0xFF) != NRF_RPC_ID_UNKNOWN);
@@ -984,13 +985,25 @@ int nrf_rpc_cmd_common(const struct nrf_rpc_group *group, uint32_t cmd,
984985

985986
NRF_RPC_DBG("Sending command 0x%02X from group 0x%02X", cmd,
986987
group->data->src_group_id);
988+
if(IS_ENABLED(CONFIG_NRF_RPC_COMMAND_TIME_MEASURE)) {
989+
processing_time = nrf_rpc_os_timestamp_get_now();
990+
}
987991

988992
err = send(group, full_packet, len + NRF_RPC_HEADER_SIZE);
989993

990994
if (err >= 0) {
991995
err = wait_for_response(group, cmd_ctx, rsp_packet, rsp_len);
992996
}
993997

998+
if(IS_ENABLED(CONFIG_NRF_RPC_COMMAND_TIME_MEASURE)) {
999+
processing_time = nrf_rpc_os_timestamp_get_now() - processing_time;
1000+
NRF_RPC_INF("Command 0x%02X from group 0x%02X execution time %llums", cmd,
1001+
group->data->src_group_id, processing_time);
1002+
}
1003+
else {
1004+
(void)processing_time;
1005+
}
1006+
9941007
cmd_ctx->handler = old_handler;
9951008
cmd_ctx->handler_data = old_handler_data;
9961009

nrf_rpc/template/nrf_rpc_os_tmpl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ void* nrf_rpc_os_tls_get(void);
169169
*/
170170
void nrf_rpc_os_tls_set(void *data);
171171

172+
/** @brief Get the current timestamp value.
173+
*
174+
* @return Current timestamp in milliseconds.
175+
*/
176+
uint64_t nrf_rpc_os_timestamp_get_now(void);
177+
172178
/** @brief Reserve one context from command context pool.
173179
*
174180
* If there is no available context then this function waits for it.

0 commit comments

Comments
 (0)