Find memory use order in Android NDK JNI so file - android

Nearby I noticed that my Android app often crash because of OOM.
I use Android Studio 3.2.3 Profiler, so I find that native heap are up to 300M.
I want to find the memeory use by every C++ so files, BUT I can not find a tool to accomplish my work.
Any advice is appreciated
adb shell dumpsys mypackage
App Summary
Pss(KB)
------
Java Heap: 11568
Native Heap: 202176
Code: 18576
Stack: 2716
Graphics: 84772
Private Other: 11300
System: 43414
TOTAL USS: 331108
TOTAL: 343727 TOTAL SWAP PSS: 30795

Related

Can't save core dump when using LLDB in android studio (osx)?

When using LLDB to debug an android project that uses native libraries, i'm unable to export the core dump.
I run my application and get a SIGSEGV in the debugger. Then I open the LLDB console in Android Studio and get the following when i try to export the core dump.
(lldb) process save-core ./core-20180730-174318
error: Failed to save core file for process: no ObjectFile plugins were able to save a core for this process
Currently SaveCore is only implemented for the MachO and PECOFF file formats, but not for ELF. Feel free to file a request for this with bugs.llvm.org and somebody will get around to it at some point. Or if you are interested in hacking on the debugger, you can have a go at implementing it yourself! The people on the lldb-dev (lldb-dev#lists.llvm.org) list would be more than happy to help you out if you want to try your hand at this.

Android build fails in Ubuntu Docker container when Gradle runs transformClasses

My Android project gets built fine on a Windows dev machine with lots of RAM. But in a simple Docker container (FROM ubuntu:xenial + Android SDK) gradle build (./gradlew assembleTrunkDebug) fails on 58% while executing the task:
transformClassesWithPreJackPackagedLibrariesForTrunkDebug
Even with --stacktrace --debug the most I get from the error is:
Gradle build daemon disappeared unexpectedly (it may have been killed or may have crashed)
There are several strange thing that I have noticed:
It doesn't matter what memory arguments I'm passing to the docker container instantiation. It always shows me the same memory stats.
Tasks: 2 total, 1 running, 1 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 1019776 total, 860604 free, 88840 used, 70332 buff/cache
KiB Swap: 1168688 total, 853640 free, 315048 used. 824484 avail Mem
I'm usually doing something like:
docker run -it --volume=/Users/MyUser/code/localDebugRepo:/localDebugRepo --workdir="/localDebugRepo" --memory="2048m" --memory-swap="2048m" 66b48030ee34 /bin/bash
But I have also tried to pass less memory and the same memory-swap or more total memory, but it always shows me Mem: 1019776 and Swap: 1168688.
I also noticed in the task manager that VBoxHeadless.exe uses only 41MB of RAM. While the misfortunate task is running (which takes a long time before crashing), the RAM usage doesn't change, but the Disk transfer is huge and only consumes more and more (since it's on SSD drive).
Android suggests the new build tool Jack and Jill used for the latest sdks has to be allowed to use at least 1536m memory. But the Docker image should run with max of 2048m and having in mind that I wasn't able to shrink the swap, I have the feeling something goes wrong there.
So any thoughts what might have caused this consistent error?

Where to find source code of Android DDMS tool -- Alocation Tracker?

can anybody tell me where to find the source code of Allocation Tracker, the memory trace tool in Android DDMS?(http://grepcode.com/file/repo1.maven.org/maven2/com.android.ddmlib/ddmlib/r16/com/android/ddmlib/Client.java#Client.requestAllocationDetails%28%29)
Or, are there any other ways to analysis the memory allocation and find out how much memory each class uses within an Android app/process?

Troubleshooting android app memory usage problems

I would like to know how I can troubleshoot high memory usage problems of my app on Android. I've search the internet and found out that the DDMS plugin is useful in taking a memory dump of the heap for my app. This however has been useless.
The app "Usage Timelines Free" is showing 94 MBs of memory used, while the DDMS heap dump shows me a total of 8.4 MBs, with the suspected leaks being the resource files.
When I generate a dump from adb (dumpsys meminfo), I get:
Shared Private Heap Heap Heap
Pss Dirty Dirty Size Alloc Free
------ ------ ------ ------ ------ ------
Native 20 8 20 54588 39431 1892
Dalvik 6732 9952 6396 10756 10028 728
Cursor 0 0 0
Ashmem 184 0 184
Other dev 11462 1172 11384
.so mmap 2467 2072 1156
.jar mmap 0 0 0
.apk mmap 48 0 0
.ttf mmap 2 0 0
.dex mmap 1037 0 0
Other mmap 41 16 32
Unknown 46352 292 46348
TOTAL 68345 13512 65520 65344 49459 2620
How can I know what is behind this huge memory consumption. My app is a foreground monitor service which runs forever, with a few activities which are accessed a few times per day.
Thanks.
Minimize your android data usage. Check the link :http://engineroots.games4punk.com/minimize-your-android-data-usage/
DDMS and got a heap memory dump. It only showed 8.4 MBs being used!
Then you are only using 8.4MB of heap space after a complete garbage collection (a net effect of creating the heap dump).
Note that if you ran this on Android 1.x/2.x, MAT will not report space consumed by bitmaps. Always try to dump the heap from an Android 3.0+ device or emulator.
When I generate a dump from adb (dumpsys meminfo), I get:
My guess is that you are running this on an Android 1.x/2.x device or emulator, and you have a lot of bitmap memory. Try running your heap dump and other tests on an Android 3.0+ environment.
Also, bear in mind that adb dumpsys meminfo does not perform a complete garbage collection, whereas dumping the HPROF file does. The Android garbage collector is optimized to minimize CPU utilization and therefore does not attempt to perform a complete garbage collection. Hence, at runtime, the heap is usually filled with garbage that will be reclaimed, as needed, by the GC engine.
You might also wish to read Dianne Hackborn's essay on this subject.

dalvikvm is not showing LOGD messages of JIT Options

I have made some minor changes to /dalvik/vm/interp/Jit.cpp
(wrote some LOGD messages) and built dalvikvm using
$make dalvikvm
and the build was successful and got the executable in /out/
target/product/generic/system/bin/dalvikvm.
Now i started an emulator and pushed dalvikvm into /data and
executed a sample java program (with some 30 loops) using
$/data/dalvikvm -Xbootclasspath:/system/
framework/core.jar -classpath /data/CmdLine.jar TestAppActivity
(created CmdLine.jar from sample program by following
instructions given in http://davanum.wordpress.com/2007/12/04/command-line-java-on-dalvikvm/
)
now when i check the logcat there is no messages which i have
written using LOGD is displayed. Do we need to add any option to
dalvikvm command line to enable JIT? what could be the problem here?
Thanks
Jit is enabled by default if you are using android version above 2.2 i suppose. Your problem is the profiling of JIT has to be enabled in dvm. This can be don by looking into dalvikvm --help .... I think dalvikvm -Xjitprofile -Xjitverbose should do and before that export your environment variable to log the message too.
Try exporting the logs before running the dalvikvm something like this
export ANDROID_LOG_TAGS="ActivityManager:I MyApp:D *:S" the variables D -Debug S: lowest level V - verbose which is the level of log you need the application to be logged.
dalvikvm is just the starter binary. The important stuff lives in libdvm.so so you have to build and replace this rather than dalvikvm.

Categories

Resources