Commit Graph

75 Commits

Author SHA1 Message Date
Brian Gesiak
34c9c2c196 [cmpcodesize] Move script into dir to package-ify
The cmpcodesize script is a little unwieldy--the same file contains
command-line argument parsing, otool invocation, and result
output formatting.

To split the script into several files, we'll need to turn it into a
Python package. In order to do so, we first move it into its own
directory.

Note that to invoke the script, you'll now need to run
`utils/cmpcodesize/cmpcodesize`. That additional path component is
inconvenient for now, but things will get better soon.
2015-12-16 18:56:43 -05:00
Brian Gesiak
954f109e30 [cmpcodesize] Use join instead of Unix separator
Use `os.path.join` instead of using Unix file separator--just in case
this is run on other platforms some day.
2015-12-16 18:56:42 -05:00
Brian Gesiak
0aaeca1de9 [cmpcodesize] Reuse shortcuts as global constant
Two parts of the code reference the shorthand for specified PerfTests_*
directories. Promote them to a constant and reuse them.
2015-12-16 18:56:42 -05:00
Brian Gesiak
9c3c25e39c [cmpcodesize] Assert env vars set properly
`$SWIFT_OLD_BUILDDIR` and `$SWIFT_NEW_BUILDDIR` are only necessary when
not using `--` to delineate two sets of files.

1. Only grab them from the environment when `--` is *not* used.
2. Assert if they're not present in that codepath. Print what *is*
   specified in the environment, in order to help the user correct
   their mistake.
2015-12-16 18:56:42 -05:00
Brian Gesiak
9e951f524a [cmpcodesize] Assert early for bad use of --list
We can detect improper use of --list very early in the script's
execution. Favor doing so to warn the user earlier. Also, add
documentation for proper use of --list.
2015-12-16 18:56:17 -05:00
Brian Gesiak
8d7e7c7288 [cmpcodesize] Remove superfluous variables
The values are already stored on the parsed arguments, so remove the
variables and clear up the variable namespace a little.

Also, use snake_case, which is more Pythonic. This commit doesn't
change all variable names in the interest of keeping changes minimal.
2015-12-16 18:56:16 -05:00
Brian Gesiak
02fb3ea264 [cmpcodesize] Assert improper use of --list
We can detect improper combinations of --list and
--additional-sections/--category very soon when executing the script.
Assert in those cases. This used to be a warning.
2015-12-16 18:56:16 -05:00
Brian Gesiak
95f22eddcb [cmpcodesize] Use Python indices for separator
Because of the way Python uses references for lists, the logic around
`oldFileArgs`, `newFileArgs`, and `curFiles` is difficult to follow.
Use a less efficient algorithm to find and split the elements based on
the '--' separator.

Although its performance is negligibly worse O(2n) as opposed to O(n), it's
easier to understand and uses one less imperative loop. Also, it's not as if
we'll ever encounter input that makes the performance difference
matter, so :shipit:!
2015-12-16 18:56:16 -05:00
Brian Gesiak
75bf127431 [cmpcodesize] Use argparse
Rather than manually parse the arguments passed to cmpcodesize, use the
Python stdlib. By doing so, we can eliminate a lot of redundant code.

One problem: argparse can't handle positional arguments of the string
'--', since it misinterprets them as optional arguments. We replace
that stirng with a special token.
2015-12-16 18:56:16 -05:00
Brian Gesiak
c7e8eaf7e9 [cmpcodesize] Prevent execution when importing
In order to prevent the Python interpreter from running code that is
meant to be executed directly, the convention is to check the context
in which the code is being interpreted.

Add a check for the context stored in the `__name__` variable, and only
execute the cmpcodesize script if it is being run as a command-line
script (that is, `__main__`).
2015-12-16 18:56:16 -05:00
practicalswift
143134a81e Fix NameError bug: die(…) is Perl, sys.exit(…) is Python :-) 2015-12-14 23:09:56 +01:00
Brian
f04eb91777 Corrected typo: separatly -> separately 2015-12-03 22:29:01 -08:00
Brian
74107034d7 Fixed typos 2015-12-03 21:33:51 -08:00
Roman Levenstein
76fafd94ac Add more detailed statistics to object file comparisons.
Swift SVN r32281
2015-09-28 21:08:18 +00:00
Roman Levenstein
23bb1b8760 Do not count the size of bound generic functions as unbound generic functions.
Swift SVN r32016
2015-09-16 22:36:47 +00:00
Roman Levenstein
9a81de0b44 Compute the code size of Swift generic functions as a separate category.
Swift SVN r32011
2015-09-16 21:23:58 +00:00
Roman Levenstein
ea7678c47e Produce separate code size stats for C++ and ObjC.
Swift SVN r32010
2015-09-16 21:23:57 +00:00
Roman Levenstein
1aa261242b Properly handle cases where an object file contains code for multiple architectures.
Swift SVN r31465
2015-08-26 00:47:21 +00:00
Roman Levenstein
cdc5590efb Distinguish between generic specializations and function signature specializations.
Swift SVN r31461
2015-08-25 23:33:52 +00:00
Roman Levenstein
64b531e27c Allow for upper-case hexadecimals.
Swift SVN r31460
2015-08-25 23:33:52 +00:00
Roman Levenstein
1977b9e957 Better handle object files generated from Objective-C sources.
Swift SVN r31459
2015-08-25 23:33:50 +00:00
Erik Eckstein
af36f6f035 Improvements for the cmpcodesize script.
*) also scan the __textcoal_nt section in addition to the __text section
*) ability so sum the sizes of multiple files



Swift SVN r25781
2015-03-05 13:21:40 +00:00
Erik Eckstein
d99d079905 Fix error message text in cmpcodesize script
Swift SVN r25685
2015-03-02 17:09:14 +00:00
Erik Eckstein
610b2a68e4 Convert cmpcodesize script to python.
Swift SVN r25532
2015-02-25 19:27:58 +00:00
Erik Eckstein
f7a27ae508 Script for comparing code size.
This script can:
*) Compare sizes of text sections (or other sections)
*) Compare sizes of function categories (Swift functions, Protocol Witnesses, Specializations, etc.)
*) Provide a detailed list or comparison of all functions

Use cmpcodesize -h to get info on the usage.

I copied the internals of Nadav's analyzeDylibSize script (Thanks!).
As the function of the analyzeDylibSize is now covered by this new script I deleted the old script.

Sorry that I implemented in ruby and not in python (I know ruby much better than python).



Swift SVN r25501
2015-02-24 15:49:49 +00:00