Android - get USS memory allocation programmatically - android

I force this problem:
I need to know USS memory allocation (= how much RAM is allocated by your APP) for my app. I know, it is possible to get this info from "adb shell procrank", but I want to have it programmatically. Is there any way how to do it? Or any fully functional snippet? Up to know, I haven't been successfull and checking via adb shell is not comfortable and slow.

Related

Monitoring memory usage by application using adb

I am spawning a couple of apps for my use case and I want to analyze the performance impact of doing so in order to decide between various approaches. I use the adb shell top -m 10 command to monitor the CPU usage constantly.
Is there a similar adb command to recursively display the live system memory usage by application while I perform different operations on my device ?

What does actually Lost RAM mean in dumpsys meminfo

When i get memory information using adb shell dumpsys meminfo it shows something called LOST RAM. I know that this equals to TOTAL - FREE RAM - USED RAM but i need to know what this really means.
Is it just a calculation error/issue ? or
Do this amount(LOST RAM) is
really lost because of some hardware or other bug?.
If this is really a bug and not a calculation error so then should i go for a device with low LOST RAM when i'm buying an android device. and should i avoid devices with high LOST RAM value. Please provide me a clear answer for this.
Lost RAM is just RAM that is unaccounted for, it will take all the processes ram usage and add them up the difference between that value and the actual amount of ram left is known as lost ram because the OS can't account for what is using it. It's software related and from what I read can be from ION debug, or drivers that allocate and track their own ram. I don't think it should play any part in your consideration when buying a new android device though.

Memory monitor in Android Studio reports different RAM usage than the device

When investigating RAM usage in an app I am working on, I have been using the Memory Monitor tool in Android Studio (can be accessed in Android Studio by going to Tools>Android>Memory Monitor). I have noticed the RAM usage of my app that is reported in Memory Monitor, is always far lower than when viewing the RAM usage from the device (can be accessed by going to Settings>Apps>Running). As you can see in the screenshots below, Memory Monitor is reporting about 18MB of RAM usage (23MB if you include free space), but the device is reporting 43MB.
Why the difference and also is one more accurate than the other?
I suspect that the memory monitor tool is talking to the dalvik virtual machine about heap allocations made by Java code, and the device manager is showing what the entire process is using for memory. So the first does not include overhead or memory used by the virtual machine itself (or its text and libraries), or any off-heap allocations (sometimes native code can allocate memory that isn't directly visible to the VM).
See https://developer.android.com/tools/debugging/debugging-memory.html#ViewingAllocations and try running the command:
adb shell dumpsys meminfo <package_name>
to get a more precise breakdown of the run-time memory usage of your application.
I've tested the Android Studio's Memory Monitor's Allocated can be get this way programmatically:
long allocatedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
But this only works to get information of the current app.

How much memory should a typical android application use?

I have developed a file parsing application on the android platform. How do I check how much memory my application is actually using up ? I tried the adb shell cat /proc/meminfo command but this does not give me how much memory my application is using. it just gives general info about the overall memory. And how much memory should an application typically use up ? what is usual or unusual ? Any help is appreciated. Thanks !
Android apps are constrained to a certain amount of memory. As it's quite (insanely?) low, I think you shouldn't feel guilty about using all of it!
The limit is 16 MB on very old devices, 24 MB or 32 MB on newer ones. There doesn't seem to be much info on the size for different devices, and nobody seems to know why the limit is so small when modern phones have 1-2 GB of RAM.
http://blog.javia.org/how-to-work-around-androids-24-mb-memory-limit/
https://groups.google.com/forum/?fromgroups=#!topic/android-platform/7zKQlrDcypQ
Aha, I found some concrete numbers on the limit:
http://dubroy.com/memory_management_for_android_apps.pdf
G1: 16MB
Droid: 24MB
Nexus One: 32MB
Xoom: 48MB
You can use DDMS > Allocation Tracker to track memory usage and Heap Allocation for your app
http://developer.android.com/resources/articles/track-mem.html
To Track the overall memory of a PID you could use following two methods in ActivityManager
To get a PID of your app :
List<ActivityManager.RunningAppProcessInfo> getRunningAppProcesses ()
and then the MemoryInfo
MemoryInfo[] getProcessMemoryInfo (int[] pids)
you might want to take a look at this one. How do I discover memory usage of my application in Android? Or simply try
ActivityManager.getMemoryInfo()
you can check the application memory usage in application mananger, you can check it in the link
You can get the memory usage of your android application with the following command:
Assuming you have adb in PATH:
adb shell dumpsys meminfo com.<your.package>
To see live updation of memory in use, you can try
watch "adb shell dumpsys meminfo com.<your.package>"
Hope this helps

What does Asset Allocations mean in adb shell dumpsys meminfo

Can anybody tell me what does Asset Allocations mean in adb shell dumpsys meminfo Android?
I see this at start up my android device and I see my application's resources.arsc is consuming 516K even though my app is not running.
Thanks.
With resources.arsc, there are two things that can happen.
Normally, the file is stored in the .apk uncompressed. Android mmap()s the file and just reads from it as necessary, without loading the whole file into RAM.
If it's compressed however, direct random access into the file is no longer an option, so it gets decompressed and kept in memory for further operations (e.g. loading a string).
I'm not sure why this would be the case if the app is not running. Perhaps it's kept around as a background process?

Categories

Resources