android: how to get memory usage (ram) of a given PID programically -
i want log ram usage of given application @ given time rate. wrote code full memory value used not know how memory usage of given pid.
please me out
this code used memory
activitymanager localactivitymanager = (activitymanager)getsystemservice("activity"); activitymanager.memoryinfo localmemoryinfo = new activitymanager.memoryinfo(); localactivitymanager.getmemoryinfo(localmemoryinfo); log.i("",string.valueof(localmemoryinfo.availmem));
i think can using public memoryinfo[] getprocessmemoryinfo (int[] pids), not know how code since im android beginer
activitymanager localactivitymanager = (activitymanager)getsystemservice(context.activity_service); // use context.activity_service not literal "activity" list<activitymanager.runningappprocessinfo> procsinfo = localactivitymanager.getrunningappprocesses(); int[] pids = new int[procsinfo.size()]; (int = 0; < procsinfo.size(); i++) { activitymanager.runningappprocessinfo info = procsinfo.get(i); pids[i] = info.pid; } debug.memoryinfo[] procsmeminfo = localactivitymanager.getprocessmemoryinfo(pids); // walk procsmeminfo array
if schedule recurring timer periodically re-query running pids , query memory info can use timestamps compute memory usage on time.
Comments
Post a Comment