Skip to content

Commit 929038a

Browse files
committed
Merge branch 'feat/enable_memory_check_on_cli' into 'main'
cli: support to print memory usage See merge request espressif/esp-zigbee-sdk!203
2 parents 4cab73f + 27374ef commit 929038a

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

components/esp-zigbee-console/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ For specific type of argument, correct format should be provided so that it can
5252
- [`iperf`](#iperf): Iperf over Zigbee.
5353
- [`linkkey`](#linkkey): Link Key Configuration.
5454
- [`macfilter`](#macfilter): Zigbee stack mac filter management.
55+
- [`memdiag`](#memdiag): Diagnose memory usages.
5556
- [`neighbor`](#neighbor): Neighbor information.
5657
- [`network`](#network): Network configuration.
5758
- [`panid`](#panid): Get/Set the (extended) PAN ID of the node.
@@ -553,6 +554,24 @@ esp> macfilter clear
553554
```
554555
555556
557+
### memdiag
558+
Diagnose memory usages
559+
560+
Get the minimum remaining stack space of zigbee_main task
561+
```bash
562+
esp> memdiag stack
563+
Min Free Stack: 2004 bytes
564+
```
565+
566+
Get the amount of free heap memory remaining
567+
```bash
568+
esp> memdiag heap
569+
Cur Free Heap: 181344 bytes
570+
Min Free Heap: 177744 bytes
571+
Max Free Heap: 236352 bytes
572+
```
573+
574+
556575
### neighbor
557576
Neighbor information.
558577

components/esp-zigbee-console/src/cli_cmd_misc.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,46 @@ static esp_err_t cli_route_table(esp_zb_cli_cmd_t *self, int argc, char **argv)
198198
return ESP_OK;
199199
}
200200

201+
static esp_err_t cli_memory_diag(esp_zb_cli_cmd_t *self, int argc, char **argv)
202+
{
203+
struct {
204+
arg_str_t *memory_type;
205+
arg_end_t *end;
206+
} argtable = {
207+
.memory_type = arg_strn(NULL, NULL, "<heap|stack>", 1, 1, "Memory type"),
208+
.end = arg_end(2),
209+
};
210+
esp_err_t ret = ESP_OK;
211+
212+
/* Parse command line arguments */
213+
EXIT_ON_FALSE(argc > 1, ESP_OK, arg_print_help((void**)&argtable, argv[0]));
214+
int nerrors = arg_parse(argc, argv, (void**)&argtable);
215+
EXIT_ON_FALSE(nerrors == 0, ESP_ERR_INVALID_ARG, arg_print_errors(stdout, argtable.end, argv[0]));
216+
217+
if (!strcmp(argtable.memory_type->sval[0], "heap")) {
218+
cli_output("Cur Free Heap: %d bytes\n", heap_caps_get_free_size(MALLOC_CAP_DEFAULT));
219+
cli_output("Min Free Heap: %d bytes\n", heap_caps_get_minimum_free_size(MALLOC_CAP_DEFAULT));
220+
cli_output("Max Free Heap: %d bytes\n", heap_caps_get_total_size(MALLOC_CAP_DEFAULT));
221+
} else if (!strcmp(argtable.memory_type->sval[0], "stack")) {
222+
const char *task_name = "Zigbee_main";
223+
TaskHandle_t task_handle;
224+
EXIT_ON_FALSE((task_handle = xTaskGetHandle(task_name)) != NULL, ESP_ERR_NOT_FOUND);
225+
cli_output("Min Free Stack: %d bytes\n", uxTaskGetStackHighWaterMark(task_handle));
226+
} else {
227+
EXIT_ON_ERROR(ESP_ERR_INVALID_ARG);
228+
}
229+
230+
exit:
231+
ESP_ZB_CLI_FREE_ARGSTRUCT(&argtable);
232+
return ret;
233+
}
234+
201235
DECLARE_ESP_ZB_CLI_CMD(factoryreset, cli_factoryreset,, "Reset the device to factory new immediately");
202236
DECLARE_ESP_ZB_CLI_CMD(reboot, cli_reboot,, "Reboot the device immediately");
203237
DECLARE_ESP_ZB_CLI_CMD(radio, cli_radio,, "Enable/Disable the radio");
204238
DECLARE_ESP_ZB_CLI_CMD(start, cli_start,, "Start Zigbee stack");
205239
DECLARE_ESP_ZB_CLI_CMD(trace, cli_trace,, "Configure Zigbee stack trace log");
240+
DECLARE_ESP_ZB_CLI_CMD(memdiag, cli_memory_diag,, "Diagnose memory usages");
206241
DECLARE_ESP_ZB_CLI_CMD_WITH_SUB(macfilter, "Zigbee stack mac filter management",
207242
ESP_ZB_CLI_SUBCMD(add, cli_macfilter_add, "Add device ieee addr for filter in"),
208243
ESP_ZB_CLI_SUBCMD(clear, cli_macfilter_clear, "Clear all entries in the filter"),

0 commit comments

Comments
 (0)