Skip to content

Commit 4cbf8f4

Browse files
author
Memfault Inc
committed
Memfault Firmware SDK 1.8.0 (Build 7456)
1 parent 0174f3e commit 4cbf8f4

File tree

10 files changed

+97
-19
lines changed

10 files changed

+97
-19
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to
77
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

9+
## [1.8.0] - 2024-04-17
10+
11+
### :chart_with_upwards_trend: Improvements
12+
13+
- General:
14+
- Scale values now fully supported. This metric metadata will scale down
15+
metric values by the specified factor. Metrics with no specified scale value
16+
will not be scaled
17+
- Fix a :bug: that would reset metric values after running a session start
18+
callback. This prevented setting metrics at the start of a session.
19+
- Zephyr:
20+
- Add a metric using a scale value to our Zephyr QEMU example. This metric
21+
measures CPU usage (in permille, 0.0-100.0%) of the main thread.
22+
923
## [1.7.7] - 2024-04-15
1024

1125
- FreeRTOS:

VERSION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
BUILD ID: 7396
2-
GIT COMMIT: 4b94654821
3-
VERSION: 1.7.7
1+
BUILD ID: 7456
2+
GIT COMMIT: 69ebc0be9a
3+
VERSION: 1.8.0

components/include/memfault/version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ typedef struct {
1919
uint8_t patch;
2020
} sMfltSdkVersion;
2121

22-
#define MEMFAULT_SDK_VERSION { .major = 1, .minor = 7, .patch = 7 }
23-
#define MEMFAULT_SDK_VERSION_STR "1.7.7"
22+
#define MEMFAULT_SDK_VERSION { .major = 1, .minor = 8, .patch = 0 }
23+
#define MEMFAULT_SDK_VERSION_STR "1.8.0"
2424

2525
#ifdef __cplusplus
2626
}

components/metrics/src/memfault_metrics.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,11 +1017,6 @@ int memfault_metrics_heartbeat_read_string(MemfaultMetricId key, char *read_val,
10171017
}
10181018

10191019
int memfault_metrics_session_start(eMfltMetricsSessionIndex session_key) {
1020-
MemfaultMetricsSessionStartCb session_start_cb = s_session_start_cbs[session_key];
1021-
if (session_start_cb != NULL) {
1022-
session_start_cb();
1023-
}
1024-
10251020
int rv;
10261021
memfault_lock();
10271022
{
@@ -1034,6 +1029,11 @@ int memfault_metrics_session_start(eMfltMetricsSessionIndex session_key) {
10341029
}
10351030
memfault_unlock();
10361031

1032+
MemfaultMetricsSessionStartCb session_start_cb = s_session_start_cbs[session_key];
1033+
if (session_start_cb != NULL) {
1034+
session_start_cb();
1035+
}
1036+
10371037
return rv;
10381038
}
10391039

examples/zephyr/qemu/qemu-app/Kconfig

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ config ZEPHYR_MEMFAULT_EXAMPLE_THREAD_TOGGLE
1010
Enables creating and aborting an example thread every 10 seconds in the
1111
example app
1212

13-
config ZEPHYR_MEMFAULT_EXAMPLE_MEMORY_METRICS
14-
bool "Use metrics to monitor memory usage in the example app"
13+
config ZEPHYR_MEMFAULT_EXAMPLE_METRICS
14+
bool "Use metrics to monitor memory usage and execution time in the example app"
1515
default y
16-
depends on MEMFAULT && MEMFAULT_HEAP_STATS && THREAD_STACK_INFO
16+
depends on MEMFAULT && MEMFAULT_HEAP_STATS
17+
depends on THREAD_STACK_INFO
18+
depends on THREAD_RUNTIME_STATS
1719

1820
config ZEPHYR_MEMFAULT_EXAMPLE_SOFTWARE_VERSION
1921
string "Software Version"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
MEMFAULT_METRICS_KEY_DEFINE(MainStack_MinBytesFree, kMemfaultMetricType_Unsigned)
2+
// This example metric demonstrates a permille integer with a range of 0-1000 to be translated into
3+
// a percentage 0.0-100.0%
4+
MEMFAULT_METRICS_KEY_DEFINE_WITH_SCALE_VALUE(main_thread_cpu_time_permille, kMemfaultMetricType_Unsigned, 10)

examples/zephyr/qemu/qemu-app/prj.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ CONFIG_MEMFAULT_SHELL_SELF_TEST_COREDUMP_STORAGE=y
5757

5858
# Enable warnings as errors
5959
CONFIG_COMPILER_WARNINGS_AS_ERRORS=y
60+
61+
# Enable Thread run-time stats
62+
CONFIG_THREAD_RUNTIME_STATS=y

examples/zephyr/qemu/qemu-app/src/main.c

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
LOG_MODULE_REGISTER(main, LOG_LEVEL_INF);
2424

25-
#if CONFIG_ZEPHYR_MEMFAULT_EXAMPLE_MEMORY_METRICS
25+
#if CONFIG_ZEPHYR_MEMFAULT_EXAMPLE_METRICS
2626
//! Size of memory to allocate on main stack
2727
//! This requires a larger allocation due to the method used to measure stack usage
2828
#define STACK_ALLOCATION_SIZE (CONFIG_MAIN_STACK_SIZE >> 2)
@@ -36,7 +36,7 @@ static void *heap_ptrs[4] = { NULL };
3636

3737
//! Keep a reference to the main thread for stack info
3838
static struct k_thread *s_main_thread = NULL;
39-
#endif // CONFIG_ZEPHYR_MEMFAULT_EXAMPLE_MEMORY_METRICS
39+
#endif // CONFIG_ZEPHYR_MEMFAULT_EXAMPLE_METRICS
4040

4141
// Blink code taken from the zephyr/samples/basic/blinky example.
4242
static void blink_forever(void) {
@@ -122,7 +122,7 @@ static void prv_init_test_thread_timer(void) {
122122
static void prv_init_test_thread_timer(void) { }
123123
#endif // CONFIG_ZEPHYR_MEMFAULT_EXAMPLE_THREAD_TOGGLE
124124

125-
#if CONFIG_ZEPHYR_MEMFAULT_EXAMPLE_MEMORY_METRICS
125+
#if CONFIG_ZEPHYR_MEMFAULT_EXAMPLE_METRICS
126126

127127
//! Helper function to collect metric value on main thread stack usage.
128128
static void prv_collect_main_thread_stack_free(void) {
@@ -142,6 +142,35 @@ static void prv_collect_main_thread_stack_free(void) {
142142
}
143143
}
144144

145+
static void prv_collect_main_thread_run_stats(void) {
146+
static uint64_t s_prev_main_thread_cycles = 0;
147+
static uint64_t s_prev_cpu_all_cycles = 0;
148+
149+
if (s_main_thread == NULL) {
150+
return;
151+
}
152+
153+
k_thread_runtime_stats_t rt_stats_main = { 0 };
154+
k_thread_runtime_stats_t rt_stats_all = { 0 };
155+
156+
k_thread_runtime_stats_get(s_main_thread, &rt_stats_main);
157+
k_thread_runtime_stats_all_get(&rt_stats_all);
158+
159+
// Calculate difference since last heartbeat
160+
uint64_t current_main_thread_cycles = rt_stats_main.execution_cycles - s_prev_main_thread_cycles;
161+
// Note: execution_cycles = idle + non-idle, total_cycles = non-idle
162+
uint64_t current_cpu_total_cycles = rt_stats_all.execution_cycles - s_prev_cpu_all_cycles;
163+
164+
// Calculate permille of main thread execution vs total CPU time
165+
// Multiply permille factor first to avoid truncating lower bits after integer division
166+
uint32_t main_thread_cpu_time = (current_main_thread_cycles * 1000) / current_cpu_total_cycles;
167+
MEMFAULT_METRIC_SET_UNSIGNED(main_thread_cpu_time_permille, main_thread_cpu_time);
168+
169+
// Update previous values
170+
s_prev_main_thread_cycles = current_main_thread_cycles;
171+
s_prev_cpu_all_cycles = current_cpu_total_cycles;
172+
}
173+
145174
//! Shell function to exercise example memory metrics
146175
//!
147176
//! This function demonstrates the change in stack and heap memory metrics
@@ -185,6 +214,7 @@ SHELL_CMD_REGISTER(memory_metrics, NULL, "Collects runtime memory metrics from a
185214
// and print current metric values
186215
void memfault_metrics_heartbeat_collect_data(void) {
187216
prv_collect_main_thread_stack_free();
217+
prv_collect_main_thread_run_stats();
188218
memfault_metrics_heartbeat_debug_print();
189219
}
190220

@@ -193,7 +223,7 @@ static void prv_run_stack_metrics_example(void) {
193223
volatile uint8_t stack_array[STACK_ALLOCATION_SIZE];
194224
memset((uint8_t *)stack_array, 0, STACK_ALLOCATION_SIZE);
195225
}
196-
#endif // CONFIG_ZEPHYR_MEMFAULT_EXAMPLE_MEMORY_METRICS
226+
#endif // CONFIG_ZEPHYR_MEMFAULT_EXAMPLE_METRICS
197227

198228
#if defined(CONFIG_MEMFAULT_FAULT_HANDLER_RETURN)
199229
#include MEMFAULT_ZEPHYR_INCLUDE(fatal.h)
@@ -213,7 +243,7 @@ int main(void) {
213243
memfault_zephyr_collect_reset_info();
214244
#endif
215245

216-
#if CONFIG_ZEPHYR_MEMFAULT_EXAMPLE_MEMORY_METRICS
246+
#if CONFIG_ZEPHYR_MEMFAULT_EXAMPLE_METRICS
217247
s_main_thread = k_current_get();
218248

219249
// @warning This code uses `memfault_metrics_heartbeat_debug_trigger` which is not intended

scripts/memfault_gdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ def _create_http_connection(base_uri):
808808
else:
809809
conn_class = HTTPSConnection
810810
default_port = 443
811-
port = url.port if url.port else default_port
811+
port = url.port or default_port
812812
return conn_class(url.hostname, port=port)
813813

814814

tests/src/test_memfault_session_metrics.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ static void session_end_cb(void) {
5656
}
5757

5858
static void session_start_cb(void) {
59+
// Set a metric value to ensure that metrics are reset before session_start_cb
60+
memfault_metrics_heartbeat_set_unsigned(MEMFAULT_METRICS_KEY(test_session_key_unsigned), 1);
5961
mock().actualCall(__func__);
6062
}
6163

@@ -141,10 +143,34 @@ TEST(MemfaultSessionMetrics, Test_RegisterSessionStartCb) {
141143
mock().expectOneCall("memfault_metrics_session_serialize");
142144
mock().expectOneCall("session_start_cb");
143145

146+
// Check that a session metric is unset before the session starts
147+
uint32_t val = 0;
148+
int rv =
149+
memfault_metrics_heartbeat_read_unsigned(MEMFAULT_METRICS_KEY(test_session_key_unsigned), &val);
150+
151+
LONGS_EQUAL(-7, rv);
152+
LONGS_EQUAL(0, val);
153+
144154
memfault_metrics_session_register_start_cb(MEMFAULT_METRICS_SESSION_KEY(test_key_session),
145155
session_start_cb);
146156
MEMFAULT_METRICS_SESSION_START(test_key_session);
157+
158+
// Check that the metric is set after the session starts. Metric is set within the start callback
159+
rv =
160+
memfault_metrics_heartbeat_read_unsigned(MEMFAULT_METRICS_KEY(test_session_key_unsigned), &val);
161+
162+
LONGS_EQUAL(0, rv);
163+
LONGS_EQUAL(1, val);
164+
147165
MEMFAULT_METRICS_SESSION_END(test_key_session);
166+
167+
// Check that the metric is set after the session ends. Metrics are reset at session start, not
168+
// end
169+
rv =
170+
memfault_metrics_heartbeat_read_unsigned(MEMFAULT_METRICS_KEY(test_session_key_unsigned), &val);
171+
172+
LONGS_EQUAL(0, rv);
173+
LONGS_EQUAL(1, val);
148174
}
149175

150176
TEST(MemfaultSessionMetrics, Test_RegisterSessionEndCb) {

0 commit comments

Comments
 (0)