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.
Asked
Active
Viewed 1,254 times
0
-
Dianne Hackborn, who is on the Android team at Google, answers this question really well [here](http://stackoverflow.com/questions/2298208/how-to-discover-memory-usage-of-my-application-in-android/2299813#2299813). – Michael Mar 10 '13 at 22:29
-
Yes, I have read this article and provided a reference in my post. I am looking for some code that can provide me PSS and USS info, using memeoryinfo() or procrank on android. Can you help? – atta Mar 10 '13 at 23:04
-
You might be better off explaining why you want to get the memory usage info for another app. I suspect there's a better tool for your use-case than whatever you're trying to do. – Michael Mar 11 '13 at 05:50
-
Actually I am creating a profiler that will monitor applications CPU, Memory, Energy consumption and perform some actions accordingly. – atta Mar 11 '13 at 21:25
1 Answers
0
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

Iamat8
- 3,888
- 9
- 25
- 35