Skip to content

Commit e2d89ee

Browse files
noahpcvinayak
authored andcommitted
modules: memfault: Enable user-provided heartbeat collect
Permit overriding the built-in NCS `memfault_metrics_heartbeat_collect_data()` with a custom version. Application will need to select `CONFIG_MEMFAULT_NCS_IMPLEMENT_METRICS_COLLECTION=n`, then implement the function elsewhere. Expose the `memfault_ncs_metrics_collect_data()` data collection function so a user can run that in addition to their own metrics. Signed-off-by: Noah Pendleton <noah.pendleton@gmail.com>
1 parent 13ccf71 commit e2d89ee

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

include/memfault_ncs.h

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ extern "C" {
3636
*/
3737
int memfault_ncs_device_id_set(const char *device_id, size_t len);
3838

39+
/** @brief Trigger NCS metrics collection. Called by default from NCS
40+
* memfault_metrics_heartbeat_collect_data(), but can instead be called
41+
* from user's implementation of
42+
* memfault_metrics_heartbeat_collect_data(), see
43+
* CONFIG_MEMFAULT_NCS_IMPLEMENT_METRICS_COLLECTION Kconfig option.
44+
*/
45+
void memfault_ncs_metrics_collect_data(void);
46+
3947
#ifdef __cplusplus
4048
}
4149
#endif

modules/memfault-firmware-sdk/Kconfig

+8
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@ config MEMFAULT_NCS_USE_DEFAULT_METRICS
169169
select MEMFAULT_METRICS_EXTRA_DEFS_FILE
170170
default y if (MEMFAULT_NCS_STACK_METRICS || MEMFAULT_NCS_LTE_METRICS || MEMFAULT_NCS_BT_METRICS)
171171

172+
config MEMFAULT_NCS_IMPLEMENT_METRICS_COLLECTION
173+
bool "Implement metrics collection"
174+
depends on MEMFAULT_NCS_USE_DEFAULT_METRICS
175+
default y
176+
help
177+
Implement the Memfault 'memfault_metrics_heartbeat_collect_data()' function
178+
for the selected metrics. Disable this to override the implementation.
179+
172180
config MEMFAULT_NCS_ETB_CAPTURE
173181
bool "Enable ETB trace capture"
174182
depends on ETB_TRACE

modules/memfault-firmware-sdk/memfault_ncs_metrics.c

+12-5
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,7 @@ int memfault_ncs_metrics_thread_add(struct memfault_ncs_metrics_thread *thread)
9292
return 0;
9393
}
9494

95-
/* Overriding weak implementation in Memfault SDK.
96-
* The function is run on every heartbeat and can be used to get fresh updates
97-
* of metrics.
98-
*/
99-
void memfault_metrics_heartbeat_collect_data(void)
95+
void memfault_ncs_metrics_collect_data(void)
10096
{
10197
if (IS_ENABLED(CONFIG_MEMFAULT_NCS_STACK_METRICS)) {
10298
k_thread_foreach_unlocked(stack_check, NULL);
@@ -111,6 +107,17 @@ void memfault_metrics_heartbeat_collect_data(void)
111107
}
112108
}
113109

110+
#if defined(CONFIG_MEMFAULT_NCS_IMPLEMENT_METRICS_COLLECTION)
111+
/* Overriding weak implementation in Memfault SDK.
112+
* The function is run on every heartbeat and can be used to get fresh updates
113+
* of metrics.
114+
*/
115+
void memfault_metrics_heartbeat_collect_data(void)
116+
{
117+
memfault_ncs_metrics_collect_data();
118+
}
119+
#endif
120+
114121
void memfault_ncs_metrics_init(void)
115122
{
116123
if (IS_ENABLED(CONFIG_MEMFAULT_NCS_LTE_METRICS)) {

0 commit comments

Comments
 (0)