I am trying to measure the cpu usage of an Android application through adb. I am approaching this by doing the following commands:
dumpsys cpuinfo packagename
adb shell top | grep packagename
I get different CPU usage stats from each one of these commands. What exactly is the difference between them and which would be more reliable if I am looking to create a graph of the cpu utilization of the application wrt the input provided.
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?
It is possible to dynamically query an Android device for the current CPU clock similar to what is mentioned in what follows.
adb shell "cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq"
However, it seems like there is not a similar option for GPU. I was wondering if there is a way, anything, to do the same for GPUs. Any help is greatly appreciated.
(CPU/GPU frequencies are not good indicators of speed. I mainly need them for some study on DVFS)
How I found the GPU freq and % for Android Galaxy S5 on OSX/Linux
Attach your phone for debugging.
In terminal: ./adb -s shell dumpsys SurfaceFlinger
Find the line with "GLES:"
The GPU name is there. For the galaxy s5 it is "Mali-T628"
./adb shell find "/sys/" -type f
Search through and find the "mali" folder
use adb shell cat to investigate what the files contain
Used ./adb shell cat /sys/devices/11800000.mali/utilization, which lists the gpu used % as an integer
Used ./adb shell cat /sys/devices/11800000.mali/clock, which lists the gpu freq as an integer
Use those integers in your perf reporting
As Amin mentioned, the best solution is using the profiler. I used Android profiler (like) to measure the performance.
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.).
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/
I am new for android programming.How can we get CPU usage per application in android?
your help will be more helpful
Use adb Commands:
adb shell top -m 10
Source:
Technique for indentifying android app CPU usage
Linux:
adb shell top -m 10 | grep packagename
Windows:
adb shell top -m 10 | FINDSTR packagename
Go to Settings -> Developer Tools -> Show CPU Usage
Then run the app
EDIT: This has to be done in the app. If you are reading this in 2019, use CPU Profiler
two approaches:
adb shell "top -n 1"
adb shell dumpsys cpuinfo
Using the new Android Studio 3.0 profiler you can achieve a higher information about the CPU usage and CPU inspection of your APP.
there are a few ways.
the first one is to open the CPU usage in the Jelly Bean developer options.
the second option is to run the adb shell top -m 10 function in your windows Android SDK folder or ./adb shell top -m 10 in your Mac/Linux.
This let's you monitor in a more top-esque manner
watch -n 0.5 adb shell top -n 1
0.5 is the polling interval
You can use app to access these kinds of information. Such as Simple System Monitor, Simple System Monitor.