code_size_compare: add --markdown to show result in a markdown table
The option --markdown supports to only show the files that have changed in a markdown table between two commits. Signed-off-by: Yanray Wang <yanray.wang@arm.com>
This commit is contained in:
parent
9b174e90d3
commit
b664cb7569
1 changed files with 54 additions and 28 deletions
|
@ -274,7 +274,8 @@ class CodeSizeGenerator:
|
||||||
self,
|
self,
|
||||||
old_rev: str,
|
old_rev: str,
|
||||||
new_rev: str,
|
new_rev: str,
|
||||||
output_stream
|
output_stream,
|
||||||
|
with_markdown=False
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Write a comparision result into a stream between two revisions.
|
"""Write a comparision result into a stream between two revisions.
|
||||||
|
|
||||||
|
@ -282,6 +283,8 @@ class CodeSizeGenerator:
|
||||||
new_rev: new git revision to compared with.
|
new_rev: new git revision to compared with.
|
||||||
output_stream: stream which the code size record is written to.
|
output_stream: stream which the code size record is written to.
|
||||||
(E.g: file / sys.stdout)
|
(E.g: file / sys.stdout)
|
||||||
|
with_markdown: write comparision result in a markdown table.
|
||||||
|
(Default: False)
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@ -359,11 +362,13 @@ class CodeSizeGeneratorWithSize(CodeSizeGenerator):
|
||||||
def _size_reader_helper(
|
def _size_reader_helper(
|
||||||
self,
|
self,
|
||||||
revision: str,
|
revision: str,
|
||||||
output: typing_util.Writable
|
output: typing_util.Writable,
|
||||||
|
with_markdown=False
|
||||||
) -> typing.Iterator[tuple]:
|
) -> typing.Iterator[tuple]:
|
||||||
"""A helper function to peel code_size based on revision."""
|
"""A helper function to peel code_size based on revision."""
|
||||||
for mod, file_size in self.code_size[revision].items():
|
for mod, file_size in self.code_size[revision].items():
|
||||||
output.write("\n" + mod + "\n")
|
if not with_markdown:
|
||||||
|
output.write("\n" + mod + "\n")
|
||||||
for fname, size_entry in file_size.items():
|
for fname, size_entry in file_size.items():
|
||||||
yield mod, fname, size_entry
|
yield mod, fname, size_entry
|
||||||
|
|
||||||
|
@ -376,18 +381,20 @@ class CodeSizeGeneratorWithSize(CodeSizeGenerator):
|
||||||
|
|
||||||
Writing Format: file_name text data bss total(dec)
|
Writing Format: file_name text data bss total(dec)
|
||||||
"""
|
"""
|
||||||
output.write("{:<30} {:>7} {:>7} {:>7} {:>7}\n"
|
format_string = "{:<30} {:>7} {:>7} {:>7} {:>7}\n"
|
||||||
.format("filename", "text", "data", "bss", "total"))
|
output.write(format_string.format("filename",
|
||||||
|
"text", "data", "bss", "total"))
|
||||||
for _, fname, size_entry in self._size_reader_helper(revision, output):
|
for _, fname, size_entry in self._size_reader_helper(revision, output):
|
||||||
output.write("{:<30} {:>7} {:>7} {:>7} {:>7}\n"
|
output.write(format_string.format(fname,
|
||||||
.format(fname, size_entry.text, size_entry.data,\
|
size_entry.text, size_entry.data,
|
||||||
size_entry.bss, size_entry.total))
|
size_entry.bss, size_entry.total))
|
||||||
|
|
||||||
def write_comparison(
|
def write_comparison(
|
||||||
self,
|
self,
|
||||||
old_rev: str,
|
old_rev: str,
|
||||||
new_rev: str,
|
new_rev: str,
|
||||||
output: typing_util.Writable
|
output: typing_util.Writable,
|
||||||
|
with_markdown: bool
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Write comparison result into a file.
|
"""Write comparison result into a file.
|
||||||
|
|
||||||
|
@ -409,25 +416,38 @@ class CodeSizeGeneratorWithSize(CodeSizeGenerator):
|
||||||
else:
|
else:
|
||||||
return [new_size]
|
return [new_size]
|
||||||
|
|
||||||
output.write("{:<30} {:<18} {:<14} {:<17} {:<18}\n"
|
if with_markdown:
|
||||||
.format("filename", "current(text,data)", "old(text,data)",\
|
format_string = "| {:<30} | {:<18} | {:<14} | {:<17} | {:<18} |\n"
|
||||||
"change(text,data)", "change%(text,data)"))
|
else:
|
||||||
for mod, fname, size_entry in self._size_reader_helper(new_rev, output):
|
format_string = "{:<30} {:<18} {:<14} {:<17} {:<18}\n"
|
||||||
text_vari = cal_size_section_variation(mod, fname, size_entry, 'text')
|
|
||||||
data_vari = cal_size_section_variation(mod, fname, size_entry, 'data')
|
output.write(format_string.format("filename", "current(text,data)",\
|
||||||
|
"old(text,data)", "change(text,data)", "change%(text,data)"))
|
||||||
|
if with_markdown:
|
||||||
|
output.write(format_string
|
||||||
|
.format("----:", "----:", "----:", "----:", "----:"))
|
||||||
|
|
||||||
|
for mod, fname, size_entry in\
|
||||||
|
self._size_reader_helper(new_rev, output, with_markdown):
|
||||||
|
text_vari = cal_size_section_variation(mod, fname,
|
||||||
|
size_entry, 'text')
|
||||||
|
data_vari = cal_size_section_variation(mod, fname,
|
||||||
|
size_entry, 'data')
|
||||||
|
|
||||||
if len(text_vari) != 1:
|
if len(text_vari) != 1:
|
||||||
output.write("{:<30} {:<18} {:<14} {:<17} {:<18}\n"
|
# skip the files that haven't changed in code size if we write
|
||||||
.format(fname,\
|
# comparison result in a markdown table.
|
||||||
str(text_vari[0]) + "," + str(data_vari[0]),\
|
if with_markdown and text_vari[2] == 0 and data_vari[2] == 0:
|
||||||
str(text_vari[1]) + "," + str(data_vari[1]),\
|
continue
|
||||||
str(text_vari[2]) + "," + str(data_vari[2]),\
|
output.write(format_string.format(fname,\
|
||||||
"{:.2%}".format(text_vari[3]) + "," +\
|
str(text_vari[0]) + "," + str(data_vari[0]),\
|
||||||
"{:.2%}".format(data_vari[3])))
|
str(text_vari[1]) + "," + str(data_vari[1]),\
|
||||||
|
str(text_vari[2]) + "," + str(data_vari[2]),\
|
||||||
|
"{:.2%}".format(text_vari[3]) + "," +\
|
||||||
|
"{:.2%}".format(data_vari[3])))
|
||||||
else:
|
else:
|
||||||
output.write("{:<30} {:<18}\n"
|
output.write("{:<30} {:<18}\n".format(fname,\
|
||||||
.format(fname,\
|
str(text_vari[0]) + "," + str(data_vari[0])))
|
||||||
str(text_vari[0]) + "," + str(data_vari[0])))
|
|
||||||
|
|
||||||
def size_generator_write_record(
|
def size_generator_write_record(
|
||||||
self,
|
self,
|
||||||
|
@ -448,11 +468,12 @@ class CodeSizeGeneratorWithSize(CodeSizeGenerator):
|
||||||
self,
|
self,
|
||||||
old_rev: str,
|
old_rev: str,
|
||||||
new_rev: str,
|
new_rev: str,
|
||||||
output_stream
|
output_stream,
|
||||||
|
with_markdown=False
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Write a comparision result into a stream between two revisions."""
|
"""Write a comparision result into a stream between two revisions."""
|
||||||
output = open(output_stream, "w")
|
output = open(output_stream, "w")
|
||||||
self.write_comparison(old_rev, new_rev, output)
|
self.write_comparison(old_rev, new_rev, output, with_markdown)
|
||||||
|
|
||||||
|
|
||||||
class CodeSizeComparison:
|
class CodeSizeComparison:
|
||||||
|
@ -545,7 +566,7 @@ class CodeSizeComparison:
|
||||||
self.old_size_version.revision, "and", self.new_size_version.revision)
|
self.old_size_version.revision, "and", self.new_size_version.revision)
|
||||||
self.code_size_generator.size_generator_write_comparison(\
|
self.code_size_generator.size_generator_write_comparison(\
|
||||||
self.old_size_version.revision, self.new_size_version.revision,\
|
self.old_size_version.revision, self.new_size_version.revision,\
|
||||||
output_file)
|
output_file, self.code_size_common.with_markdown)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def get_comparision_results(self) -> int:
|
def get_comparision_results(self) -> int:
|
||||||
|
@ -587,6 +608,10 @@ def main():
|
||||||
choices=list(map(lambda s: s.value, SupportedConfig)),
|
choices=list(map(lambda s: s.value, SupportedConfig)),
|
||||||
help="specify configuration type for code size comparison,\
|
help="specify configuration type for code size comparison,\
|
||||||
default is the current MbedTLS configuration.")
|
default is the current MbedTLS configuration.")
|
||||||
|
group_optional.add_argument(
|
||||||
|
'--markdown', action='store_true', dest='markdown',
|
||||||
|
help="Show comparision of code size in a markdown table\
|
||||||
|
(only show the files that have changed).")
|
||||||
comp_args = parser.parse_args()
|
comp_args = parser.parse_args()
|
||||||
|
|
||||||
if os.path.isfile(comp_args.result_dir):
|
if os.path.isfile(comp_args.result_dir):
|
||||||
|
@ -619,6 +644,7 @@ def main():
|
||||||
code_size_common = SimpleNamespace(
|
code_size_common = SimpleNamespace(
|
||||||
host_arch=detect_arch(),
|
host_arch=detect_arch(),
|
||||||
measure_cmd='size -t',
|
measure_cmd='size -t',
|
||||||
|
with_markdown=comp_args.markdown
|
||||||
)
|
)
|
||||||
|
|
||||||
size_compare = CodeSizeComparison(old_size_version, new_size_version,\
|
size_compare = CodeSizeComparison(old_size_version, new_size_version,\
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue