简体   繁体   中英

Is there a Android API to pull the CPU/Memory/Network/Disk information like Android Studio in its Monitor?

We are trying to find the appropriate Android API calls to make within our application retrieve details on the CPU, Memory, Disk and Network information like Android Studio in its monitor?

We are looking to capture this data for both the overall phone and a particular targeted application (not the one running the monitor as it will be run as a background service).

Below is an example of Android Studio's Monitor

例

We have been able to find a API to monitor memory but not CPU, Network or Disk info.

  1. CPU Reading the file for /proc/stat looks to be able to provide CPU data but is there a direct API to call for this?
  2. Memory we found a API for ActivityManager.MemoryInfo which looks to work.
  3. Network we would like to capture the network traffic like Android Studio and have been unable to find a API for this?
  4. Disk IO we were also curious if there is a API for this?

Thank you

https://i.stack.imgur.com/FJcCV.png

In one of the apps we developed, we came across a similar requirement and here's what we did.

  1. AFAIK there's no API. To get the data, CPU - /proc/stats like you mentioned or execute top command through Runtime.exec method and parsing the output would be the options.
  2. You can use ActivityManager.MemoryInfo or you can also use Runtime.totalMemory Runtime.freeMemory() methods as well.
  3. For network data, take a look at TrafficStats ( https://developer.android.com/reference/android/net/TrafficStats.html ).

We did not capture the Disk IO stats - so I don't have anything on that one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM