Track dex file size in supersize |
|||||||||
Issue descriptionIdeally .size files would contain entries that cover every byte that makes up Chrome.apk. This bug covers tracking the bytes that go into classes.dex. I'm currently thinking that the easiest way to get this information is: Parse dexdump -d: - Gives addresses of methods - Tells you where strings are used - Doesn't really capture all the bytes of a .dex though We'll need to slurp in proguard .mapping file to record unobfuscated names. 1) We should start by storing one symbol for each method (or class?). 2) Then add in symbols for strings (where each usage of a string is a symbol, and identical strings get grouped as aliases) 3) Then think about added entries for types (e.g. per-class overhead not covered by methods / strings) Question 2: What exactly should we store: name = "org.chromium.Foo.barMethod" full_name = "org.chromium.Foo.barMethod(int a)" size = size_of_instructions section_name = ".dex.method" object_path = "path/to/target_java.jar" source_path = "path/to/file.java" name = "org.chromium.Foo.barMethod$str1" full_name = "org.chromium.Foo.field(int a)$str1" size = size_of_string section_name = ".dex.str" object_path = "path/to/target_java.jar" source_path = "path/to/file.java" aliases = [other_symbols_referencing_string] name = "org.chromium.Foo" full_name = "org.chromium.Foo" size = size_of_type_overhead section_name = ".dex.class" object_path = "path/to/target_java.jar" source_path = "path/to/file.java" Note: there is already some code for doing deobfuscation of .mapping files at: https://cs.chromium.org/chromium/src/tools/android/dexdiffer/dexdiffer.py
,
Jan 15 2018
,
Jan 15 2018
,
Jan 25 2018
Maybe more favorable than parsing dexdump output: Looks like //third_party/android_tools/sdk/tools/bin/apkanalyzer uses dexlib2.jar for its disassemble command. This library is here: https://github.com/JesusFreke/smali/tree/master/dexlib2 And it has methods for iterating dex files and getting the file sizes of classes / methods. You can iterate DexBackedMethodImplementation of a class, and from there iterate instructions and extract all DexBackedStringReference. Also supports parsing odex and vdex files (on-device optimized dex), although I doubt that will be applicable to supersize.
,
Jan 25 2018
,
Jan 25 2018
This is the output of: third_party/android_tools/sdk/tools/bin/apkanalyzer --human-readable dex packages --defined-only out/Debug/apks/ChromePublic.apk > ~/Downloads/packages
,
Jan 26 2018
Woo! I somehow missed that there was already a command for this! Seems like a perfect match for what we want :)
,
Feb 8 2018
This seems to give us proguard mappings. Some libraries we include were already proguarded so they can't really be consistent across releases anyways, assuming we have symbol names corresponding to package/class/method/field names in that order. Any suggestions on how to reliably find proguard mappings from supersize? We could always add those to out/Release/size-info but they are kind of big (order of ~10mbs each). third_party/android_tools/sdk/tools/bin/apkanalyzer dex packages --defined-only --proguard-mappings out/Release/gen/chrome/android/chrome_public_apk/chrome_public_apk.proguard.jar.mapping out/Release/apks/ChromePublic.apk > ~/tmp/packages
,
Feb 9 2018
There's a copy of the mappings under apks/ChromePublic.apk.mapping (same for all apks). So you can just derive it from --apk-path
,
Feb 12 2018
Great! This command seems to do the trick: third_party/android_tools/sdk/tools/bin/apkanalyzer dex packages --defined-only --proguard-mappings out/Release/apks/ChromePublic.apk.mapping out/Release/apks/ChromePublic.apk
,
Feb 14 2018
,
Mar 19 2018
,
Mar 21 2018
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/4b911364babec06672df8fb03e3faa0bfd7c2724 commit 4b911364babec06672df8fb03e3faa0bfd7c2724 Author: Peter Wen <wnwen@chromium.org> Date: Wed Mar 21 19:08:01 2018 Supersize: Add .dex symbols Use apk analyzer to parse dex files in apks. Make use of .jar.info files to attribute size to source files. Bug: 723820 Change-Id: I5cdbff6000d585d7903a40bccaaf95ead0370b34 Reviewed-on: https://chromium-review.googlesource.com/949452 Commit-Queue: Peter Wen <wnwen@chromium.org> Reviewed-by: agrieve <agrieve@chromium.org> Cr-Commit-Position: refs/heads/master@{#544792} [add] https://crrev.com/4b911364babec06672df8fb03e3faa0bfd7c2724/tools/binary_size/libsupersize/apkanalyzer.py [add] https://crrev.com/4b911364babec06672df8fb03e3faa0bfd7c2724/tools/binary_size/libsupersize/apkanalyzer_test.py [modify] https://crrev.com/4b911364babec06672df8fb03e3faa0bfd7c2724/tools/binary_size/libsupersize/archive.py [modify] https://crrev.com/4b911364babec06672df8fb03e3faa0bfd7c2724/tools/binary_size/libsupersize/models.py [modify] https://crrev.com/4b911364babec06672df8fb03e3faa0bfd7c2724/tools/binary_size/libsupersize/path_util.py [modify] https://crrev.com/4b911364babec06672df8fb03e3faa0bfd7c2724/tools/binary_size/libsupersize/template/D3SymbolTreeMap.js [modify] https://crrev.com/4b911364babec06672df8fb03e3faa0bfd7c2724/tools/binary_size/libsupersize/template/index.html [modify] https://crrev.com/4b911364babec06672df8fb03e3faa0bfd7c2724/tools/binary_size/libsupersize/testdata/Console.golden
,
Mar 26 2018
Only ~200 KiB of unattributed dex size. Calling this done. |
|||||||||
►
Sign in to add a comment |
|||||||||
Comment 1 by agrieve@chromium.org
, May 17 2017