Commit Graph

7 Commits

Author SHA1 Message Date
Christopher Ferris
dfb5368b57 Refactor native heap viewer to add tests.
This only includes a few tests to start with.

Bug: 62492960

Test: Ran new unit tests.
Test: Ran with all different options and verified it produces the same
Test: output as the previous script.
Change-Id: Iad29a5f04f49986139c92030a3259cae512859af
2018-07-13 14:09:43 -07:00
Christopher Ferris
ad7d5fb378 Detect if num field is valid on v1.0 version.
In Android P, the version field did not get incremented properly in
all places. So if a file with a v1.0 version is found, do a further check
to verify if the num field is really valid.

Test: Verified that a file with v1.0 gets checked and the valid num field
Test: is set correctly.
Test: Verified that a file with v1.1 automatically gets num field set to
Test: valid.
Change-Id: I7f828294c833e334cad76a866bbaa1d78ac02cfb
Merged-In: I7f828294c833e334cad76a866bbaa1d78ac02cfb
(cherry picked from commit b558fe4d53)
2018-07-10 12:25:33 -07:00
Christopher Ferris
fbd84e9255 Add descriptive text describing html interaction.
Test: Ran and verified html output is viewable.
Change-Id: I54771bc9b536ff8fbc62dc7e5aac2caa22765e30
2018-06-05 08:46:23 -07:00
Christopher Ferris
bede9f3b3c Handle num fields that aren't one.
The new version of malloc debug supports using a num field that is more
than one. Modify the parser to handle this case.

Bug: 74361929

Test: Ran on a file that contained non-one numbers and verified the output.
Change-Id: I158922e51ce99afff88f20a80df414d653f95e65
2018-05-22 19:02:41 -07:00
Mathieu Chartier
9ae5ff4895 Fix potential divide by zero in display_html
When using logwrapper, there is only a zygote heap. This caused
a divide by zero for the app heap.

Test: native_heapdump_viewer.py --html art/native_heap.txt > test.html

Change-Id: I7defd94935d72ee9c4cb6e53d7a1a308a1030eb3
2017-06-13 11:00:26 -07:00
Christopher Ferris
f427655e47 Fix potential divide by zero.
If there are no bytes attributable to APP, then you get a divide
by zero. Modify the code to avoid doing a divide by zero.

This can happen when using logwrapper to enable malloc debug.

Test: Ran on a heap that had no APP bytest.
Change-Id: I48f0666a92b591e4537c493c56b136e517a36c25
2017-05-24 17:27:27 -07:00
Richard Uhler
a178732bcf Script to view native allocations prettily.
Usage:
1. Collect a native heap dump from the device. For example:
  $ adb shell stop
  $ adb shell setprop libc.debug.malloc.program app_process
  $ adb shell setprop libc.debug.malloc.options backtrace=64
  $ adb shell start
  (launch and use app)
  $ adb shell am dumpheap -n <pid> /data/local/tmp/native_heap.txt
  $ adb pull /data/local/tmp/native_heap.txt

2. Run the viewer:
$ python native_heapdump_viewer.py [options] native_heap.txt
  [--verbose]: verbose output
  [--html]: html output
  [--symbols SYMBOL_DIR]: SYMBOL_DIR is the directory containing the
  .so files with symbols. Defaults to $ANDROID_PRODUCT_OUT/symbols

This outputs a file with lines of the form:
5831776  29.09% 100.00%    10532     71b07bc0b0 /system/lib64/libandroid_runtime.so Typeface_createFromArray frameworks/base/core/jni/android/graphics/Typeface.cpp:68

5831776 is the total number of bytes allocated at this stack frame, which
is 29.09% of the total number of bytes allocated and 100.00% of the parent
frame's bytes allocated. 10532 is the total number of allocations at this
stack frame. 71b07bc0b0 is the address of the stack frame.

For generating interactive HTML output, use:
python native_heapdump_viewer.py --html [options] native_heap.txt > allocations.html
Then open allocations.html in a browser. Clicking on nodes will
expand the tree.

Test: Try script on an app following usage instructions.

Bug: 36457259
Change-Id: I18dfe9a00fc1d3e82673dbfb4b5be3dc10480cec
2017-05-23 10:23:29 -07:00