Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,18 @@ git clone https://github.com/FreeOpcUa/opcua-client-gui && cd opcua-client-gui
python3 -m pip install --upgrade pyopenssl
python3 -m pip install --upgrade .
```

### How-to-enable detailed heap/stack memory debugging information
* Edit [`variants/OPTA/conf/mbed_app.json`](https://github.com/arduino/ArduinoCore-mbed/blob/main/variants/OPTA/conf/mbed_app.json)
```diff
"target.macros_add": [
...
+ "MBED_HEAP_STATS_ENABLED=1",
+ "MBED_STACK_STATS_ENABLED=1",
+ "MBED_MEM_TRACING_ENABLED=1"
```
* Recompile `libmbed.a`
```bash
cd ArduinoCore-mbed
./mbed-os-to-arduino -a -g OPTA:OPTA
```
26 changes: 26 additions & 0 deletions examples/opcua_server/opcua_server.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
# define ARDUINO_OPEN62541_O1HEAP_DEBUG (0) /* Change to (1) if you want to see debug messages on Serial concerning o1heap memory calls. */
#endif

#if MBED_HEAP_STATS_ENABLED && MBED_MEM_TRACING_ENABLED && MBED_STACK_STATS_ENABLED
#include "mbed_mem_trace.h"
#endif

/**************************************************************************************
* GLUE CODE
**************************************************************************************/
Expand Down Expand Up @@ -277,6 +281,28 @@ void setup()
o1heapGetDiagnostics(o1heap_ins).allocated,
o1heapGetDiagnostics(o1heap_ins).peak_allocated);

#if MBED_HEAP_STATS_ENABLED && MBED_MEM_TRACING_ENABLED && MBED_STACK_STATS_ENABLED
/* Print stack/heap memory information. For information how to enable it
* see https://os.mbed.com/blog/entry/Tracking-memory-usage-with-Mbed-OS/
*/
size_t const num_thds = osThreadGetCount();
mbed_stats_stack_t *stack_stats = (mbed_stats_stack_t *) malloc(num_thds * sizeof(mbed_stats_stack_t));
mbed_stats_stack_get_each(stack_stats, num_thds);

mbed_stats_thread_t * thd_stats = (mbed_stats_thread_t *) malloc(num_thds * sizeof(mbed_stats_thread_t));
mbed_stats_thread_get_each(thd_stats, num_thds);

for (int i = 0; i < num_thds; i++)
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Thread: 0x%lX (\"%s\"), Stack size: %lu / %lu",
stack_stats[i].thread_id, thd_stats[i].name, stack_stats[i].max_size, stack_stats[i].reserved_size);
free(stack_stats);
free(thd_stats);

mbed_stats_heap_t heap_stats;
mbed_stats_heap_get(&heap_stats);
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Heap size: %lu / %lu bytes", heap_stats.current_size, heap_stats.reserved_size);
#endif

/* Run the server (until ctrl-c interrupt) */
UA_StatusCode const status = UA_Server_runUntilInterrupt(opc_ua_server);
});
Expand Down