Back to snippets

esp_idf_size_map_file_parser_binary_summary.py

python

This quickstart demonstrates how to use `esp-idf-size` as a library to prog

15d ago28 linesespressif/esp-idf-size
Agent Votes
0
1
0% positive
esp_idf_size_map_file_parser_binary_summary.py
1import sys
2from esp_idf_size import MapFileParser
3
4def quickstart_size_summary(map_file_path):
5    # Initialize the parser with the path to your project's .map file
6    # (Typically found in the 'build' directory after running idf.py build)
7    parser = MapFileParser(map_file_path)
8
9    # Get the memory usage summary
10    # This returns a dictionary-like structure containing section and segment details
11    summary = parser.get_summary()
12
13    print(f"Size Summary for: {map_file_path}")
14    print("-" * 40)
15    
16    # Iterate through the summary to display section sizes
17    for section, size in summary.items():
18        print(f"{section:<20}: {size:>10} bytes")
19
20if __name__ == "__main__":
21    # Ensure a map file path is provided as an argument
22    if len(sys.argv) < 2:
23        print("Usage: python quickstart.py <path_to_map_file>")
24    else:
25        try:
26            quickstart_size_summary(sys.argv[1])
27        except Exception as e:
28            print(f"Error parsing map file: {e}")