Introduction#
We’ll focus on two useful tools:
- Size Analysis: Understand and manage your application’s memory footprint.
- Core Dump: Capture the system state after a crash for detailed post-mortem debugging.
Let’s take a closer look at each.
Size Analysis#
What Is Size Analysis?#
Size analysis is the process of examining how much flash and RAM your firmware consumes. This helps ensure the application fits within the target hardware and leaves enough memory available for runtime operations such as task scheduling, buffer management, and peripheral interaction.
Performing Size Analysis#
When building a project with ESP-IDF, the build system automatically provides a memory usage summary. After running:
ESP-IDF: Build Your Project
You’ll see output like this:
Total sizes:
DRAM .data size: 1234 bytes
DRAM .bss size: 5678 bytes
IRAM size: 9101 bytes
Flash code size: 11213 bytes
Flash rodata size: 1415 bytes
This breakdown gives insight into where your application is consuming resources. For deeper analysis, ESP-IDF offers additional commands:
idf.py size
: Provides a summary of statically-allocated memory usage.idf.py size-components
: Shows per-component memory usage.idf.py size-files
: Breaks down usage by source file.idf.py size-symbols
: Lists symbol-level memory usage (useful for pinpointing heavy functions or variables).
These tools help identify memory hotspots and guide you in optimizing your codebase.
Once you know the memory usage of your firmware, you can begin pruning both the configuration and code to reduce it. After making your changes, test the memory usage again to see how much impact they had.
Core Dumps#
What Is a Core Dump?#
A core dump is a snapshot of the device’s memory and processor state at the time of a crash. It includes:
- Call stacks of all tasks
- CPU register contents
- Relevant memory regions
This data allows developers to analyze what went wrong, even after the device resets, making core dumps an invaluable tool for diagnosing hard-to-reproduce bugs.
Enabling and Using Core Dumps#
To enable core dumps on an Espressif device using ESP-IDF, you need to
Enable the core dump in the
menuconfig
Trigger and Analyze the Core Dump When a crash occurs, the Espressif chip saves the core dump to flash or shows it in UART. You can analyze it using:
idf.py coredump-info
These commands decode the core dump and present a readable backtrace, variable states, and register values. This makes it easier to identify the root cause of a failure.
Core dumps are an invaluable tool to be used alongside debugging.
Conclusion#
Mastering size analysis and core dumps is extremely useful for embedded developers. Size analysis helps ensure your application remains within resource limits and runs efficiently, while core dumps provide a powerful mechanism for post-crash diagnostics.
By integrating these tools into your development workflow, you’ll be better prepared to build robust, high-performance applications.
Next step: assignment 3.1