comparing code size vs source size
-
03-07-2019 - |
Question
There are plenty of script/tools for counting line of code, and some to count functions size in terms of line of code. But here I'm looking to a way to measure function size in terms of bytes of generated code.
Does anyone know a way/tools to extract this information from a .lib or a .dll?
For example, I know how to list function name from a .lib or .dll, and their start address, but I haven't found a way yet to get their memory footprint.
PS : I'm look for a solution on windows platform, but any answer on an alternative system is welcome.
Solution
I'm not sure it's quite what you're after, but you could try parsing the map file as per this tutorial.
Also, if you're after a paid-for solution, the ANTS profiler from Red-gate is reasonable.
OTHER TIPS
On Unix, the size
command gives you information about that:
Black JL: size /usr/lib/libc.so.1
909301 + 32017 + 6731 = 948049
Black JL: size ~/lib/libjl.a
/work1/jleffler/lib/libjl.a[affbak.o]: 4849 + 44 + 4 = 4897
/work1/jleffler/lib/libjl.a[affstd.o]: 5488 + 48 + 4 = 5540
/work1/jleffler/lib/libjl.a[base64.o]: 8772 + 9 + 320 = 9101
/work1/jleffler/lib/libjl.a[basedigit.o]: 841 + 0 + 0 = 841
/work1/jleffler/lib/libjl.a[basename.o]: 996 + 0 + 0 = 996
/work1/jleffler/lib/libjl.a[bitmap.o]: 3876 + 8 + 4096 = 7980
...lots of entries omitted...
Black JL: size ~/bin/sqlcmd.64
169694 + 17728 + 8280 = 195702
Black JL: size cc3e_*.o | so
cc3e_fixed_from_gregorian.o: 1906 + 0 + 0 = 1906
cc3e_gregorian_date.o: 684 + 0 + 0 = 684
cc3e_gregorian_epoch.o: 707 + 0 + 0 = 707
cc3e_gregorian_from_fixed.o: 1729 + 0 + 0 = 1729
cc3e_gregorian_year_from_fixed.o: 1625 + 0 + 0 = 1625
cc3e_last_kday.o: 742 + 0 + 0 = 742
cc3e_nth_kday.o: 1123 + 0 + 0 = 1123
Black JL:
Semi-random files from around my system - which is Sun SPARC running Solaris 10, using size
from /usr/ccs/bin
(not the GNU version, but it is likely to give similar info).
GNU size
under Cygwin says:
$ size libjl.a
text data bss dec hex filename
800 64 16 880 370 affbak.o (ex libjl.a)
1008 64 16 1088 440 affstd.o (ex libjl.a)
176 0 0 176 b0 basedigit.o (ex libjl.a)
208 0 0 208 d0 basename.o (ex libjl.a)
544 320 4096 4960 1360 bitmap.o (ex libjl.a)
816 0 16 832 340 block.o (ex libjl.a)
However, that may not help much - when run on a DLL (C:\WINDOWS\twain.dll), GNU size
says it doesn't recognize the file type. OTOH, it does seem to understand '.lib' files:
jleffler@IBM-027DF09B37F /cygdrive/c/notes/jvm/bin
$ size jawt.lib
text data bss dec hex filename
63 30 0 93 5d jawt.dll (ex jawt.lib)
63 20 0 83 53 jawt.dll (ex jawt.lib)
63 8 0 71 47 jawt.dll (ex jawt.lib)
8 26 0 34 22 jawt.dll (ex jawt.lib)
jleffler@IBM-027DF09B37F /cygdrive/c/notes/jvm/bin
$ ls -l jawt.lib
-rwxrwxrwx+ 1 jleffler None 1692 Oct 25 2007 jawt.lib