I have developed a code to run script on Android real device using Appium server.
Now i want to know android device battery usage during script execution.
Is there any api available in appium to get battery / disk / cpu / memory usage ?
You can use ADB to get all types of information about android device:
To check the status of usb charger and battery:
Adb shell cat /sys/class/power_supply/usb/*
Adb shell cat /sys/class/power_supply/battery/*
Get the current CPU operating speed:
Adb shell cat /sys/devices/system/cpu/<cpu#>/cpufreq/scaling_cur_freq
Get the free Memory:
adb shell vmstat
Reference :
https://sites.google.com/site/adbusefulcommands/
Related
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?
when I execute command line: dumpsys meminfo
in my android shell enviroment (Android 8.1)
I got the output: * SERVICE 'meminfo' DUMP TIMEOUT (10s) EXPIRED *
Does Anyone can tell me how to avoid the issue without rebooting the device?
Because I am developing a function that monitor the memories of all processes when the device is running
Henry.Woo says is right.
use:
adb shell dumpsys -t 60 meminfo
Iam trying to trigger low memory events using android studio's terminal:
To trigger your onTrimMemory callbacks:
adb shell am send-trim-memory
e.g. adb shell am send-trim-memory com.example.app MODERATE
but i get this message Unknown command 'send-trim-memory' . Iam using emulator on the latest android.
Thank you
I have some old shell scripts that needs to be executed on an android device but the command to fetch the total cpu, memory and swap usage is top. More specific it is:
top -m 1 -d 1.0 -n $duration
Now I have been looking to find a replacement for this and I found out that I can use dumpsys. The problem what I have is that I want to give a timeout like this:
dumpsys -t 20 cpuinfo
I checked this site: https://developer.android.com/studio/command-line/dumpsys.html but didn't find out why this doesn't work. Even when I try the help I get the same error
dumpsys --help
Can't find the service: --help
Does someone know what is going on? My current android version is 6.0.1 if this is important.
Thanks in advance!
It is true that dumpsys --help does not work. I think there is a mistake in their document. However, below works:
# adb shell dumpsys input
# adb shell dumpsys -l
Add permission on your manifest "android.permission.DUMP".or
There's another (hacky) way to access dumpsys without rooting your device - through adb shell.
This will require allowing USB debugging, and finding the port of the adb service.
Enable USB debugging on your device. This option is found under Settings -> Developer Options.
Connect your device to a PC, and run the following command from the PC's shell/command line: adb tcpip 12345. Then, from your devices shell, issue the command adb connect localhost:12345 from your application. You can now disconnect the device from USB. Alternatively, you can scan the ports on your device one by one without USB connection, using adb connect localhost: and find the port adb service is listening to.
Authorize USB debugging from the pop up confirmation dialog, if prompted. Check the "always" checkbox to do not require this step again.
Now, when you have access to the adb service, use adb shell dumpsys ... from your application code to get whatever service dump you need.
I am trying to find device RAM (512 MB or 1GB) using adb shell commands.
Following commands giving more details about the free,used & total memory. But how to find the device overall RAM?
adb shell "cat /proc/meminfo"
adb shell dumpsys meminfo
adb shell procrank
So it looks to me that MemTotal is probably the field you are looking for:
MemTotal — Total amount of physical RAM, in kilobytes.
While it is not the strictly Android, another Linux flavour CentOS provides the following page regarding /proc/meminfo. It seems that Red Hat, and other variants also describe it similarily.
Is there something that is making you suspect that this is not the physical RAM? On my device the value reported for MemTotal matches what I expect.
People who post answers often forget that Windows users don't have access to grep, cat, etc. Add shell to the beginning of your pipe.
.\adb.exe -s whichever-device shell "cat /proc/meminfo | grep MemTotal"
This is assuming you're connected to multiple devices. If you're only connected to one, you can remove -s whichever-device (usually the ip if you're connected by wifi or the device number from the device list if connected by wire.).