Skip to content

Commit 7065ca2

Browse files
committed
settings: performance: add delete operation
To measure the performance, add a delete operation after each write. Signed-off-by: Riadh Ghaddab <[email protected]>
1 parent 6ca11e0 commit 7065ca2

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

tests/subsys/settings/performance/settings_test_perf.c

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ static struct k_work_q settings_work_q;
1919
static K_THREAD_STACK_DEFINE(settings_work_stack, 2024);
2020
static struct k_work_delayable pending_store;
2121

22-
#define TEST_SETTINGS_COUNT (128)
23-
#define TEST_STORE_ITR (5)
24-
#define TEST_TIMEOUT_SEC (60)
22+
#define TEST_SETTINGS_COUNT (128)
23+
#define TEST_STORE_ITR (5)
24+
#define TEST_TIMEOUT_SEC (60)
2525
#define TEST_SETTINGS_WORKQ_PRIO (1)
2626

2727
static void bt_scan_cb(const bt_addr_le_t *addr, int8_t rssi, uint8_t adv_type,
28-
struct net_buf_simple *buf)
28+
struct net_buf_simple *buf)
2929
{
3030
printk("len %u\n", buf->len);
3131
}
@@ -48,11 +48,10 @@ static void store_pending(struct k_work *work)
4848
} stats = {0, 0, 0, UINT32_MAX};
4949

5050
int64_t ts1 = k_uptime_get();
51-
5251
/* benchmark storage performance */
5352
for (int j = 0; j < TEST_STORE_ITR; j++) {
5453
for (int i = 0; i < TEST_SETTINGS_COUNT; i++) {
55-
test_settings[i].val = TEST_SETTINGS_COUNT*j + i;
54+
test_settings[i].val = TEST_SETTINGS_COUNT * j + i;
5655

5756
int64_t ts2 = k_uptime_get();
5857

@@ -73,15 +72,35 @@ static void store_pending(struct k_work *work)
7372
}
7473
}
7574

75+
for (int i = 0; i < TEST_SETTINGS_COUNT; i++) {
76+
int64_t ts2 = k_uptime_get();
77+
78+
snprintk(path, sizeof(path), "ab/cdef/ghi/%04x", i);
79+
err = settings_load_subtree(path);
80+
zassert_equal(err, 0, "settings_load subtree failed %d", err);
81+
82+
err = settings_delete(path);
83+
zassert_equal(err, 0, "settings_delete failed %d", err);
84+
85+
int64_t delta2 = k_uptime_delta(&ts2);
86+
87+
if (stats.single_entry_max < delta2) {
88+
stats.single_entry_max = delta2;
89+
}
90+
if (stats.single_entry_min > delta2) {
91+
stats.single_entry_min = delta2;
92+
}
93+
stats.total_calculated += delta2;
94+
}
95+
7696
int64_t delta1 = k_uptime_delta(&ts1);
7797

7898
stats.total_measured = delta1;
7999

80100
printk("*** storing of %u entries completed ***\n", ARRAY_SIZE(test_settings));
81101
printk("total calculated: %u, total measured: %u\n", stats.total_calculated,
82102
stats.total_measured);
83-
printk("entry max: %u, entry min: %u\n", stats.single_entry_max,
84-
stats.single_entry_min);
103+
printk("entry max: %u, entry min: %u\n", stats.single_entry_max, stats.single_entry_min);
85104

86105
k_sem_give(&waitfor_work);
87106
}
@@ -99,8 +118,8 @@ ZTEST(settings_perf, test_performance)
99118
}
100119

101120
k_work_queue_start(&settings_work_q, settings_work_stack,
102-
K_THREAD_STACK_SIZEOF(settings_work_stack),
103-
K_PRIO_COOP(TEST_SETTINGS_WORKQ_PRIO), NULL);
121+
K_THREAD_STACK_SIZEOF(settings_work_stack),
122+
K_PRIO_COOP(TEST_SETTINGS_WORKQ_PRIO), NULL);
104123
k_thread_name_set(&settings_work_q.thread, "Settings workq");
105124
k_work_init_delayable(&pending_store, store_pending);
106125

0 commit comments

Comments
 (0)