code_size_compare: add a parser to generate code size with size tool
This commit splits CodeSizeBase as a separate class to prepare a parser as CodeSizeGenerator. The benefit is we can extend the tool of code size measurement in order to generate more types of code size record. Signed-off-by: Yanray Wang <yanray.wang@arm.com>
This commit is contained in:
parent
5647d06be8
commit
fc6ed4ddad
1 changed files with 20 additions and 15 deletions
|
@ -125,7 +125,11 @@ class CodeSizeInfo: # pylint: disable=too-few-public-methods
|
||||||
print(comb)
|
print(comb)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
class SizeEntry: # pylint: disable=too-few-public-methods
|
|
||||||
|
class CodeSizeGeneratorWithSize:
|
||||||
|
"""Code Size Base Class for size record saving and writing."""
|
||||||
|
|
||||||
|
class SizeEntry: # pylint: disable=too-few-public-methods
|
||||||
"""Data Structure to only store information of code size."""
|
"""Data Structure to only store information of code size."""
|
||||||
def __init__(self, text, data, bss, dec):
|
def __init__(self, text, data, bss, dec):
|
||||||
self.text = text
|
self.text = text
|
||||||
|
@ -133,9 +137,6 @@ class SizeEntry: # pylint: disable=too-few-public-methods
|
||||||
self.bss = bss
|
self.bss = bss
|
||||||
self.total = dec # total <=> dec
|
self.total = dec # total <=> dec
|
||||||
|
|
||||||
class CodeSizeBase:
|
|
||||||
"""Code Size Base Class for size record saving and writing."""
|
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
""" Variable code_size is used to store size info for any revisions.
|
""" Variable code_size is used to store size info for any revisions.
|
||||||
code_size: (data format)
|
code_size: (data format)
|
||||||
|
@ -157,7 +158,8 @@ class CodeSizeBase:
|
||||||
size_record = {}
|
size_record = {}
|
||||||
for line in size_text.splitlines()[1:]:
|
for line in size_text.splitlines()[1:]:
|
||||||
data = line.split()
|
data = line.split()
|
||||||
size_record[data[5]] = SizeEntry(data[0], data[1], data[2], data[3])
|
size_record[data[5]] = CodeSizeGeneratorWithSize.SizeEntry(\
|
||||||
|
data[0], data[1], data[2], data[3])
|
||||||
if revision in self.code_size:
|
if revision in self.code_size:
|
||||||
self.code_size[revision].update({mod: size_record})
|
self.code_size[revision].update({mod: size_record})
|
||||||
else:
|
else:
|
||||||
|
@ -180,7 +182,8 @@ class CodeSizeBase:
|
||||||
|
|
||||||
if mod:
|
if mod:
|
||||||
size_record[data[0]] = \
|
size_record[data[0]] = \
|
||||||
SizeEntry(data[1], data[2], data[3], data[4])
|
CodeSizeGeneratorWithSize.SizeEntry(\
|
||||||
|
data[1], data[2], data[3], data[4])
|
||||||
|
|
||||||
# check if we hit record for the end of a module
|
# check if we hit record for the end of a module
|
||||||
m = re.match(r'.?TOTALS', line)
|
m = re.match(r'.?TOTALS', line)
|
||||||
|
@ -247,7 +250,7 @@ class CodeSizeBase:
|
||||||
output.write("{} {}\n".format(fname, new_size))
|
output.write("{} {}\n".format(fname, new_size))
|
||||||
|
|
||||||
|
|
||||||
class CodeSizeComparison(CodeSizeBase):
|
class CodeSizeComparison:
|
||||||
"""Compare code size between two Git revisions."""
|
"""Compare code size between two Git revisions."""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
@ -278,6 +281,7 @@ class CodeSizeComparison(CodeSizeBase):
|
||||||
self.make_command = code_size_info.make_command
|
self.make_command = code_size_info.make_command
|
||||||
self.fname_suffix = "-" + code_size_info.arch + "-" +\
|
self.fname_suffix = "-" + code_size_info.arch + "-" +\
|
||||||
code_size_info.config
|
code_size_info.config
|
||||||
|
self.code_size_generator = CodeSizeGeneratorWithSize()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def validate_revision(revision: str) -> bytes:
|
def validate_revision(revision: str) -> bytes:
|
||||||
|
@ -336,12 +340,12 @@ class CodeSizeComparison(CodeSizeBase):
|
||||||
self._handle_called_process_error(e, git_worktree_path)
|
self._handle_called_process_error(e, git_worktree_path)
|
||||||
size_text = result.decode("utf-8")
|
size_text = result.decode("utf-8")
|
||||||
|
|
||||||
self.set_size_record(revision, mod, size_text)
|
self.code_size_generator.set_size_record(revision, mod, size_text)
|
||||||
|
|
||||||
print("Generating code size csv for", revision)
|
print("Generating code size csv for", revision)
|
||||||
csv_file = open(os.path.join(self.csv_dir, revision +
|
csv_file = open(os.path.join(self.csv_dir, revision +
|
||||||
self.fname_suffix + ".csv"), "w")
|
self.fname_suffix + ".csv"), "w")
|
||||||
self.write_size_record(revision, csv_file)
|
self.code_size_generator.write_size_record(revision, csv_file)
|
||||||
|
|
||||||
def _remove_worktree(self, git_worktree_path: str) -> None:
|
def _remove_worktree(self, git_worktree_path: str) -> None:
|
||||||
"""Remove temporary worktree."""
|
"""Remove temporary worktree."""
|
||||||
|
@ -361,7 +365,8 @@ class CodeSizeComparison(CodeSizeBase):
|
||||||
if (revision != "current") and \
|
if (revision != "current") and \
|
||||||
os.path.exists(os.path.join(self.csv_dir, csv_fname)):
|
os.path.exists(os.path.join(self.csv_dir, csv_fname)):
|
||||||
print("Code size csv file for", revision, "already exists.")
|
print("Code size csv file for", revision, "already exists.")
|
||||||
self.read_size_record(revision, os.path.join(self.csv_dir, csv_fname))
|
self.code_size_generator.read_size_record(revision,\
|
||||||
|
os.path.join(self.csv_dir, csv_fname))
|
||||||
else:
|
else:
|
||||||
git_worktree_path = self._create_git_worktree(revision)
|
git_worktree_path = self._create_git_worktree(revision)
|
||||||
self._build_libraries(git_worktree_path)
|
self._build_libraries(git_worktree_path)
|
||||||
|
@ -380,7 +385,7 @@ class CodeSizeComparison(CodeSizeBase):
|
||||||
|
|
||||||
print("\nGenerating comparison results between",\
|
print("\nGenerating comparison results between",\
|
||||||
self.old_rev, "and", self.new_rev)
|
self.old_rev, "and", self.new_rev)
|
||||||
self.write_comparison(self.old_rev, self.new_rev, res_file)
|
self.code_size_generator.write_comparison(self.old_rev, self.new_rev, res_file)
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue