Skip to content

Commit

Permalink
modules: memfault: Enable user-provided heartbeat collect
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
noahp committed Feb 2, 2024
1 parent 7e318ac commit 00051d2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
8 changes: 8 additions & 0 deletions include/memfault_ncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ extern "C" {
*/
int memfault_ncs_device_id_set(const char *device_id, size_t len);

/** @brief Trigger NCS metrics collection. Called by default from NCS
* memfault_metrics_heartbeat_collect_data(), but can instead be called
* from user's implementation of
* memfault_metrics_heartbeat_collect_data(), see
* CONFIG_MEMFAULT_NCS_IMPLEMENT_METRICS_COLLECTION Kconfig option.
*/
void memfault_ncs_metrics_collect_data(void);

#ifdef __cplusplus
}
#endif
Expand Down
8 changes: 8 additions & 0 deletions modules/memfault-firmware-sdk/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ config MEMFAULT_NCS_USE_DEFAULT_METRICS
select MEMFAULT_METRICS_EXTRA_DEFS_FILE
default y if (MEMFAULT_NCS_STACK_METRICS || MEMFAULT_NCS_LTE_METRICS || MEMFAULT_NCS_BT_METRICS)

config MEMFAULT_NCS_IMPLEMENT_METRICS_COLLECTION
bool "Implement metrics collection"
depends on MEMFAULT_NCS_USE_DEFAULT_METRICS
default y
help
Implement the Memfault 'memfault_metrics_heartbeat_collect_data()' function
for the selected metrics. Disable this to override the implementation.

config MEMFAULT_NCS_ETB_CAPTURE
bool "Enable ETB trace capture"
depends on ETB_TRACE
Expand Down
17 changes: 12 additions & 5 deletions modules/memfault-firmware-sdk/memfault_ncs_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@ int memfault_ncs_metrics_thread_add(struct memfault_ncs_metrics_thread *thread)
return 0;
}

/* Overriding weak implementation in Memfault SDK.
* The function is run on every heartbeat and can be used to get fresh updates
* of metrics.
*/
void memfault_metrics_heartbeat_collect_data(void)
void memfault_ncs_metrics_collect_data(void)
{
if (IS_ENABLED(CONFIG_MEMFAULT_NCS_STACK_METRICS)) {
k_thread_foreach_unlocked(stack_check, NULL);
Expand All @@ -111,6 +107,17 @@ void memfault_metrics_heartbeat_collect_data(void)
}
}

#if defined(CONFIG_MEMFAULT_NCS_IMPLEMENT_METRICS_COLLECTION)
/* Overriding weak implementation in Memfault SDK.
* The function is run on every heartbeat and can be used to get fresh updates
* of metrics.
*/
void memfault_metrics_heartbeat_collect_data(void)
{
memfault_ncs_metrics_collect_data();
}
#endif

void memfault_ncs_metrics_init(void)
{
if (IS_ENABLED(CONFIG_MEMFAULT_NCS_LTE_METRICS)) {
Expand Down

0 comments on commit 00051d2

Please sign in to comment.