getProcessMemoryInfo has bad performance

55 views
Skip to first unread message

Kevince Boole

unread,
Dec 27, 2016, 11:01:12 PM12/27/16
to android-platform
Hi,

I'm developing a util app to record information of the system while meeting some scenarios. I use mActivityManager.getProcessMemoryInfo(pids) to get usage of memory of each target process.
But this method has very bad performance. It will cost ~50 ms for each process which in total, more than 5 s for all target processes, which is not acceptable for me.(we need to finish all these tasks in one second)

I have read the source code, and understand the procedure of calling this method:
* Calling ActivityManager via Binder, passing an array of all target pids
* ActivityManager executes the task in a loop by calling native function Debug.getMemoryInfo to get memory info of targets one by one.
* In native code, smaps will be parsed to get necessary information. But this IO operation takes a long time -- about 30-40 ms, which is the hot spot.

My question is:
Is there any way to improve the method by making getMemoryInfo running simualtaneously? As I know, IO of reading smaps takes a long time, can we use multi-threading or coroutine to achieve this?
If not, is there any better way to meet my requirement.

Thanks
Reply all
Reply to author
Forward
0 new messages