@@ -0,0 +1,2294 @@
+#!/usr/bin/env python3%0A# Copyright (c) 2021 Intel Corporation%0A#%0A# SPDX-License-Identifier: Apache-2.0%0A%0A# A script to diff between two ram or rom reports generated by%0A# size_report. When you call call the ram_report or rom_report targets you%0A# end up with a json file in the build directory that can be used as input%0A# for this script.%0A%0A# The output shows which symbols insreased and which decreased in size and%0A# also tracked added/remove symbols as well.%0A%0A# Example:%0A#    ./scripts/footprint/fpdiff.py ram1.json ram2.json%0A%0Afrom anytree.importer import DictImporter%0Afrom anytree import PreOrderIter%0Afrom anytree.search  import find%0A%0Afrom colorama import Fore%0Aimport json%0Aimport argparse%0A%0Aimporter = DictImporter()%0A%0Adef parse_args():%0A    parser = argparse.ArgumentParser(%0A                description=%22Compare footprint sizes of two builds.%22)%0A    parser.add_argument(%22file1%22, help=%22First file%22)%0A    parser.add_argument(%22file2%22, help=%22Second file%22)%0A%0A    return parser.parse_args()%0A%0Adef main():%0A    args = parse_args()%0A%0A    with open(args.file1, %22r%22) as f:%0A        data = json.load(f)%0A        root1 = importer.import_(data%5B'symbols'%5D)%0A%0A    with open(args.file2, %22r%22) as f:%0A        data = json.load(f)%0A        root2 = importer.import_(data%5B'symbols'%5D)%0A%0A    for node in PreOrderIter(root1):%0A        # pylint: disable=undefined-loop-variable%0A        n = find(root2, lambda node2: node2.identifier == node.identifier)%0A        if n:%0A            if n.size != node.size:%0A                diff = n.size - node.size%0A                if diff == 0:%0A                    continue%0A                if not n.children or not n.parent:%0A                    if diff %3C 0:%0A                        print(f%22%7Bn.identifier%7D -%3E %7BFore.GREEN%7D%7Bdiff%7D%7BFore.RESET%7D%22)%0A                    else:%0A                        print(f%22%7Bn.identifier%7D -%3E %7BFore.RED%7D+%7Bdiff%7D%7BFore.RESET%7D%22)%0A%0A        else:%0A            if not node.children:%0A                print(f%22%7Bnode.identifier%7D (%7BFore.GREEN%7D-%7Bnode.size%7D%7BFore.RESET%7D) disappeared.%22)%0A%0A    for node in PreOrderIter(root2):%0A        n = find(root1, lambda node2: node2.identifier == node.identifier)%0A        if not n:%0A            if not node.children and node.size != 0:%0A                print(f%22%7Bnode.identifier%7D (%7BFore.RED%7D+%7Bnode.size%7D%7BFore.RESET%7D) is new.%22)%0A%0A%0Aif __name__ == %22__main__%22:%0A    main()%0A

introduce footprint diffing