how to get the heap size value? - android

How can I get the heap memory sizes of different processes running on emulator (or device) to my application (Activity) in Android?

Open a command prompt, type
adb shell dumpsys meminfo
or for jusr one process, either
adb shell dumpsys meminfo xxx
where xxx is the PID
or
adb shell dumpsys meminfo 'your apps package name'

Related

How to extract meminfo and cpuinfo of android App Programatically?

I analyze the memory and CPU utilization of my app from the terminal using the below commands
adb shell dumpsys cpuinfo
adb shell dumpsys meminfo com.company.packageName
The above approach is manual and would like to extract the data programmatically within my App. I assume android exposes SDK to fetch these values. Can you please suggest the way forward?

Adb Shell dumpheap for native not working

I need to take the native dump of the android process.
The cmd I am using is:
adb shell am dumpheap -n <pid> /data/local/tmp/dump.txt
The device is S8, Oreo OS.
Everytime I run this cmd, the 'dump.txt' is generated with the following content:
Native heap dump not available. To enable, run these commands
(requires root):$ adb shell setprop libc.debug.malloc 1 $ adb shell
stop $ adb shell start
Though I am doing it says and the phone is also rooted but it still gives the same content.
I am stuck. Any help would be appreciated.

android adb - how to set emulator to ac power

In an effort to test doze and standby mode im trying to change the battery level and also the set to ac etc using adb and a api 23 emulator.
But when i run the following bash command:
adb shell dumpsys battery set level [95]
i get the following error:
Bad value: [95]
also when i run :
adb shell dumpsys battery set [ac]
i get the following error:
Dump current battery state, or:
set [ac|usb|wireless|status|level|invalid] <value>
unplug
reset
i am assuming meaning it could not find the ac command. How can i change the emulator to ac and also update the battery level ?
update: there is a command adb shell dumpsys battery unplug
to unplug the emulator so should there not be a command to plug it in for AC power ?
there is a command adb shell dumpsys battery unplug to unplug the
emulator so should there not be a command to plug it in for AC power ?
Yes, the command is:
adb shell dumpsys battery set ac 1
To change the level of the battery you can use this command:
adb shell dumpsys battery set level 42
If you'd like to test Doze, I recommend trying the commands directly from the Developer Site here.
The commands to cycle through Doze modes are as follows:
$ adb shell dumpsys battery unplug
$ adb shell dumpsys deviceidle step
$ adb shell dumpsys deviceidle -h
And for testing App Standby:
To force your app into App Standby mode:
$ adb shell dumpsys battery unplug
$ adb shell am set-inactive <packageName> true
To simulate waking your app:
$ adb shell am set-inactive <packageName> false
$ adb shell am get-inactive <packageName>

Calling procrank doesn't work on real devices

according to a google io video about getting to know how much memory you app takes , you can use procrank and read the USS value of it.
i've tried it out on emulators (no matter which version i use - from 2.3.x to 4.1) and it works well , but running on an actual device , it didn't work (tested on galaxy s3 with android 4.0.4) . it's as if the command doesn't exist .
how could it be ? is there an alternative to get this USS value?
You can use dumpsys command
Steps:
issue command line: dumpsys meminfo packageName
The Private Dirty column is you wanted.
U can also use
adb shell dumpsys meminfo
or
adb shell dumpsys meminfo + pid
command
adb shell dumpsys meminfo [pid] (Private Dirty + Private Clean)
is same as
procrank (USS)
procrank and dumpsys meminfo is not the same command, because procrank can show more thread which is killed by accident.
First you shell get procrank, procmem, libpagemap.so from Google
Then do push like :
adb push procrank /system/xbin
adb push procmem /system/xbin
adb push libpagemap.so /system/lib
Last :
adb shell chmod 6755 /system/xbin/procrank
adb shell chmod 6755 /system/xbin/procmem
adb shell chmod 6755 /system/lib/libpagemap.so

How to dump android meminfo into a file?

I'm taking a detailed look into the resources of my apps. Unfortunatly when I execute the adb shell dumpsys meminfo, it overflows my terminal. Anyone know how I can instead of viewing the dump in terminal, have it print into a file so I can pull and view it in a text editor?
Redirect the output - adb shell dumpsys meminfo > meminfo.txt
Redirect it using > operator:
adb shell dumpsys meminfo >meminfo.txt
Alternatively, you can pipe it directly to a viewer such as less:
adb shell dumpsys meminfo | less
In addition to redirecting, you can just pipe it through more:
adb shell dumpsys meminfo | more
Then you can just page through the output.
Or, honestly, make your terminal buffer larger so you can scroll back through it. Having a terminal where you can't even scroll back through the output of this command seems pretty ghastly. :)
use dumpsys -l and check if power option is there. Its not possible that no power state is maintained.
either you dont have write permission in the directory you are trying to create on device.
better use adb shell dumpsys power and it comes out to your pc rather than on device memory

Categories

Resources