blob: 6f62fc63c908949529e515fbad7d125865afc196 [file] [log] [blame]
#!/usr/bin/env python3
# Copyright (c) 2021 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
# A script to diff between two ram or rom reports generated by
# size_report. When you call call the ram_report or rom_report targets you
# end up with a json file in the build directory that can be used as input
# for this script.
# The output shows which symbols increased and which decreased in size and
# also tracked added/remove symbols as well.
# Example:
# ./scripts/footprint/ ram1.json ram2.json
from anytree.importer import DictImporter
from anytree import PreOrderIter
from import find
import colorama
from colorama import Fore
import json
import argparse
importer = DictImporter()
def parse_args():
parser = argparse.ArgumentParser(
description="Compare footprint sizes of two builds.")
parser.add_argument("file1", help="First file")
parser.add_argument("file2", help="Second file")
return parser.parse_args()
def main():
args = parse_args()
with open(args.file1, "r") as f:
data1 = json.load(f)
with open(args.file2, "r") as f:
data2 = json.load(f)
for idx, ch in enumerate(data1['symbols']['children']):
root1 = importer.import_(ch)
root2 = importer.import_(data2['symbols']['children'][idx])
for node in PreOrderIter(root1):
# pylint: disable=undefined-loop-variable
n = find(root2, lambda node2: node2.identifier == node.identifier)
if n:
if n.size != node.size:
diff = n.size - node.size
if diff == 0:
if not n.children or not n.parent:
if diff < 0:
print(f"{n.identifier} -> {Fore.GREEN}{diff}{Fore.RESET}")
print(f"{n.identifier} -> {Fore.RED}+{diff}{Fore.RESET}")
if not node.children:
print(f"{node.identifier} ({Fore.GREEN}-{node.size}{Fore.RESET}) disappeared.")
for node in PreOrderIter(root2):
n = find(root1, lambda node2: node2.identifier == node.identifier)
if not n:
if not node.children and node.size != 0:
print(f"{node.identifier} ({Fore.RED}+{node.size}{Fore.RESET}) is new.")
if __name__ == "__main__":