From f41d776d9b2dd5c2d015ab23b192557226ad98cc Mon Sep 17 00:00:00 2001 From: Brad Campbell Date: Fri, 15 Oct 2021 15:16:56 -0400 Subject: [PATCH] tools: add script to track size at each merge --- tools/get_text_sizes_merges.py | 68 ++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 tools/get_text_sizes_merges.py diff --git a/tools/get_text_sizes_merges.py b/tools/get_text_sizes_merges.py new file mode 100755 index 0000000000..c785e0361b --- /dev/null +++ b/tools/get_text_sizes_merges.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 + + +MERGES_GIT_CMD = "log --merges --oneline HEAD~{}..HEAD" + +OUTFILE = "sizes.data" + +from sh import make +from sh import git + + +with open(OUTFILE, "w") as f: + f.write("commit_hash pr_number text_size data_size bss_size\n") + + +commits = git(MERGES_GIT_CMD.format(50).split(), _tty_out=False) + + +print(commits) + + +for commit in commits: + # Each commit looks like: + # 33e464c7d Merge #2821 + # 5cd230d09 Merge pull request #2869 from saki-osive/master + fields = commit.split() + # Commit hash comes first + commit_hash = fields[0] + # Extract PR number + pr_number = "" + for field in fields[1:]: + if field[0] == "#": + pr_number = field + + # Checkout commit + git.checkout(commit_hash) + + print("on hash {}".format(commit_hash)) + + make_output = make() + + text_size = 0 + data_size = 0 + bss_size = 0 + next_line_is_sizes = False + for make_output_line in make_output: + fields = make_output_line.split() + if next_line_is_sizes == True: + # Last line we found "text", so the first item on this line is the + # size of the text section. + text_size = int(fields[0]) + data_size = int(fields[1]) + bss_size = int(fields[2]) + break + if fields[0] == "text": + next_line_is_sizes = True + + display = "{}\t{}\t{}\t{}\t{}".format( + commit_hash, pr_number, text_size, data_size, bss_size + ) + print(display) + + with open(OUTFILE, "a") as f: + f.write(display) + f.write("\n") + +# Go back to master, I guess +git.checkout("master")