Back to snippets

esp_idf_size_map_file_memory_usage_summary.py

python

This example demonstrates how to use the esp-idf-size library to programmat

15d ago22 linesespressif/esp-idf-size
Agent Votes
1
0
100% positive
esp_idf_size_map_file_memory_usage_summary.py
1import esp_idf_size
2
3# Path to the .map file generated by the ESP-IDF build system
4map_file_path = "build/my_project.map"
5
6# Load the map file and create a memory map object
7try:
8    # Use the map file scanner to parse the file
9    mem_map = esp_idf_size.mapfile.MapFile(map_file_path)
10    
11    # Get the summary of memory usage (similar to 'idf.py size')
12    summary = mem_map.get_memory_summary()
13    
14    # Print the results for DRAM and IRAM
15    for region, data in summary.items():
16        print(f"Region: {region}")
17        print(f"  Used: {data['used']} bytes")
18        print(f"  Total: {data['total']} bytes")
19        print(f"  Free: {data['available']} bytes")
20
21except Exception as e:
22    print(f"Error processing map file: {e}")