As you can see in the picture below, with Firebase Monitoring SDK you can discover how much user time and system time your app consumes. Check it here
The picture is for an iPhone device, but the document says Android devices are supported too.
So I'm sure there is a way to get this data programmatically as Firebase does. I want to know how does Firebase discover this information.
Thanks in advance.
One way to calculate the CPU usage of a process by PID is to parse the /proc/[pid]/stat
file. According to the doc, the /proc/[pid]/stat
file contains status information about the process. So we can parse this file to get the following members:
Check this page to get more information about the /proc/[pid]/stat
file and the way to parse it.
Also here is a relevant question about utime
and stime
.
I'm not sure whether Firebase is doing this. But this is a good way to get that information if and only if the /proc/[pid]/stat
file is present and accessible in all Android versions.
See also
How do I get the total CPU usage of an application from /proc/pid/stat?