The main function. Return: The process return code.
()
| 143 | |
| 144 | |
| 145 | def main() -> int: |
| 146 | ''' |
| 147 | The main function. |
| 148 | |
| 149 | Return: |
| 150 | The process return code. |
| 151 | ''' |
| 152 | args = parse_command_line() |
| 153 | |
| 154 | # Preflight - check that size exists |
| 155 | path = shutil.which('size') |
| 156 | if not path: |
| 157 | print('ERROR: The size utility is not installed') |
| 158 | return 1 |
| 159 | |
| 160 | # Pick an appropriate implementation based on host OS |
| 161 | run_size = run_size_linux |
| 162 | if platform.system() == 'Darwin': |
| 163 | run_size = run_size_macos |
| 164 | |
| 165 | # Collect the data |
| 166 | try: |
| 167 | ref_dat = None |
| 168 | if args.ref_bin: |
| 169 | ref_dat = run_size(args.ref_bin.name) |
| 170 | |
| 171 | new_dat = run_size(args.bin.name) |
| 172 | |
| 173 | except sp.CalledProcessError as ex: |
| 174 | print('ERROR: The size utility failed') |
| 175 | print(ex.stderr.strip()) |
| 176 | return 1 |
| 177 | |
| 178 | # Common header |
| 179 | print(' Code RO ZI') |
| 180 | |
| 181 | # One binary, no reference comparison |
| 182 | if not ref_dat: |
| 183 | print(f' New{new_dat[0]:>10}{new_dat[1]:>10}{new_dat[2]:>10}') |
| 184 | |
| 185 | # Two binaries with reference comparison |
| 186 | else: |
| 187 | print(f' Ref{ref_dat[0]:>10}{ref_dat[1]:>10}{ref_dat[2]:>10}') |
| 188 | print(f' New{new_dat[0]:>10}{new_dat[1]:>10}{new_dat[2]:>10}') |
| 189 | |
| 190 | df_a = [y - x for (x, y) in zip(ref_dat, new_dat)] |
| 191 | df_r = [((y - x) / x) * 100.0 for (x, y) in zip(ref_dat, new_dat)] |
| 192 | |
| 193 | print(f'Diff abs{df_a[0]:>+10}{df_a[1]:>+10}{df_a[2]:>+10}') |
| 194 | print(f'Diff rel{df_r[0]:>+10.2f}%{df_r[1]:>+9.2f}%{df_r[2]:>+9.2f}%') |
| 195 | |
| 196 | return 0 |
| 197 | |
| 198 | |
| 199 | if __name__ == '__main__': |
no test coverage detected