2021-06-05 01:09:47 +08:00
|
|
|
#!/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.
|
|
|
|
|
2022-03-17 05:07:43 +08:00
|
|
|
# The output shows which symbols increased and which decreased in size and
|
2021-06-05 01:09:47 +08:00
|
|
|
# also tracked added/remove symbols as well.
|
|
|
|
|
|
|
|
# Example:
|
|
|
|
# ./scripts/footprint/fpdiff.py ram1.json ram2.json
|
|
|
|
|
|
|
|
from anytree.importer import DictImporter
|
2023-11-28 08:57:56 +08:00
|
|
|
from anytree import PreOrderIter, AnyNode
|
2021-06-05 01:09:47 +08:00
|
|
|
from anytree.search import find
|
|
|
|
|
2022-05-23 18:15:23 +08:00
|
|
|
import colorama
|
2021-06-05 01:09:47 +08:00
|
|
|
from colorama import Fore
|
|
|
|
import json
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
importer = DictImporter()
|
|
|
|
|
|
|
|
def parse_args():
|
|
|
|
parser = argparse.ArgumentParser(
|
2023-01-05 00:08:36 +08:00
|
|
|
description="Compare footprint sizes of two builds.", allow_abbrev=False)
|
2021-06-05 01:09:47 +08:00
|
|
|
parser.add_argument("file1", help="First file")
|
|
|
|
parser.add_argument("file2", help="Second file")
|
|
|
|
|
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
def main():
|
2022-05-23 18:15:23 +08:00
|
|
|
colorama.init()
|
|
|
|
|
2021-06-05 01:09:47 +08:00
|
|
|
args = parse_args()
|
|
|
|
|
|
|
|
with open(args.file1, "r") as f:
|
2022-05-05 01:43:51 +08:00
|
|
|
data1 = json.load(f)
|
2021-06-05 01:09:47 +08:00
|
|
|
|
|
|
|
with open(args.file2, "r") as f:
|
2022-05-05 01:43:51 +08:00
|
|
|
data2 = json.load(f)
|
|
|
|
|
|
|
|
for idx, ch in enumerate(data1['symbols']['children']):
|
|
|
|
root1 = importer.import_(ch)
|
2023-11-28 08:57:56 +08:00
|
|
|
if idx >= len(data2['symbols']['children']):
|
|
|
|
root2 = AnyNode(identifier=None)
|
|
|
|
else:
|
|
|
|
root2 = importer.import_(data2['symbols']['children'][idx])
|
2022-05-05 01:43:51 +08:00
|
|
|
print(f"{root1.name}\n+++++++++++++++++++++")
|
|
|
|
|
|
|
|
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:
|
|
|
|
continue
|
|
|
|
if not n.children or not n.parent:
|
|
|
|
if diff < 0:
|
|
|
|
print(f"{n.identifier} -> {Fore.GREEN}{diff}{Fore.RESET}")
|
|
|
|
else:
|
|
|
|
print(f"{n.identifier} -> {Fore.RED}+{diff}{Fore.RESET}")
|
|
|
|
|
|
|
|
else:
|
|
|
|
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.")
|
2021-06-05 01:09:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|