Commit Graph

11 Commits

Author SHA1 Message Date
Andreas Gampe
547631e12a NativeHeapDumpViewer: Python 3 compatibility
Fix some minor compat issues. Also clean up file close.

Test: native_heapdump_viewer_tests
Change-Id: Ic43b5cc61f26dd11fffe4e9b7a06056e4ed1c676
2018-10-30 11:03:17 -07:00
Shibin George
7e73f7a7b4 Prevent "index out of range" crash when addr2line aborts in between
addr2line may abort and "result" may be incomplete. This leads to
"index out of range" exceptions. Enclose this in a try & except block
and on exception, default to function:location = ---:---

Test: "python native_heapdump_viewer_tests.py" (after CL:780974)
      passes.

BUG: 117306194

Change-Id: I4fd5c784949f279550aec95b68045df4a671da74
2018-10-09 06:21:03 +05:30
Mathieu Chartier
e3503620cd Fix GetMappingFromOffset
Fixed backward calculation of mapping offset.

Added logic to page align the data offset for uncompressed shared
objects. This fixes symbolization.

Bug: 111268230
Test: inspect native heap dump for the Camera app
Change-Id: If1af41e7265f017c1a691008309c8a002d5f588e
2018-08-03 13:26:10 -07:00
Mathieu Chartier
fca30841f3 Add logic for replacing maps for zip files
For zip files, try to open the file in the current directory and
insert the files as mappings. This enables the script to pick up
embedded .so files.

Added a check to look in current directory before the symbol dir.

Added --app-symbols option to specify the directory containing the
app APK and so files.

Test: manual
Bug: 111268230

(cherry picked from commit b284c20247)

Merged-In: Id1b1f13bac78911daa6a72c35ebfadfdc9c1700f
Change-Id: Ia8d3dd64f16e1d06d929b4023292cb98a438ea3e
2018-07-31 14:24:29 -07:00
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