script: add ram and rom total size to json file
It's easier and safer to parse json file rather than extract total size from stdout Now the .json file has two keys: { "symbols": { "children": [ ... ], "identifier": ":", "name": "root", "size": 2220 }, "total_size": 34272 } Signed-off-by: Jingru Wang <jingru@synopsys.com>
This commit is contained in:
parent
6af80f4675
commit
a3469a0497
1 changed files with 7 additions and 4 deletions
|
@ -12,6 +12,7 @@ import os
|
|||
import sys
|
||||
import re
|
||||
from pathlib import Path
|
||||
import json
|
||||
|
||||
from distutils.version import LooseVersion
|
||||
|
||||
|
@ -30,7 +31,7 @@ if LooseVersion(elftools.__version__) < LooseVersion('0.24'):
|
|||
from colorama import init, Fore
|
||||
|
||||
from anytree import RenderTree, NodeMixin, findall_by_attr
|
||||
from anytree.exporter import JsonExporter
|
||||
from anytree.exporter import DictExporter
|
||||
|
||||
|
||||
# ELF section flags
|
||||
|
@ -634,10 +635,12 @@ def main():
|
|||
print_any_tree(root, symsize, args.depth)
|
||||
|
||||
if args.json:
|
||||
exporter = JsonExporter(indent=2, sort_keys=True)
|
||||
data = exporter.export(root)
|
||||
exporter = DictExporter()
|
||||
data = dict()
|
||||
data["symbols"] = exporter.export(root)
|
||||
data["total_size"] = symsize
|
||||
with open(args.json, "w") as fp:
|
||||
fp.write(data)
|
||||
json.dump(data, fp, indent=4)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue