I want to know the memory consumption of an application A through Application B. I am aware of all the techniques that have been discussed on this website. However, none of them are working for me. My scenario is, I have already implemented a code that can monitor CPU consumption of any specific application through top command. However, the top command only provides VSS and RSS, while i am interested in PSS and USS. One way to get these values is through procrank. However, I am not sure if procrank command can be executed on smartphone as I have tried process p2 = Runtime.getRuntime().exec("procrank");
but its not working. (EDIT: Works on Android emulator (not smartphone). Can someone please guide me how to get PSS and USS through Application id or name, which I have already taken through top command.
I know the question is old, I will suggest something..
Firstly get root privilege in console with
Process process = Runtime.getRuntime().exec("su");
Then write your command with root access
su <--command-->
Read stream output
try { Process process = Runtime.getRuntime().exec("su"); DataOutputStream dataOutputStream = new DataOutputStream(process.getOutputStream()); if (dataOutputStream != null) { dataOutputStream.writeBytes("procrank\\n"); dataOutputStream.flush(); BufferedInputStream bufferedInputStream = new BufferedInputStream(process.getInputStream()); byte[] bff = new byte[bufferedInputStream.available()]; bufferedInputStream.read(bff); } } catch (Exception e) { }
Please go through my answer for explanation
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.