views:

43

answers:

1

Hi,

In my application , i have an option to capture the hprof dump. I used

android.os.Debug.dumpHprofData (String fileName)

Initially i though the hprof data generated by the method above is for the entire device , which is not so . The hprof data generated is only for my process.

Now i am trying to generate hprof data for other process as well. I need to get the Hprof dump for all the running processes from application code.

from adb shell i tried "kill -10 " , This command will generate the hprof file for the corresponding process in the data/misc folder.

Now the problem is this command is working perfectly from the adb shell prompt , but i am not able to embed the command to mycode.

My code is like

Runtime.getRuntime().exec("chmod 777 /data/misc") Runtime.getRunTime().exec("kill -10 ")

No exceptions are thrown , but somehow it is not working. The same code above is capturing Hprof dump for my process, when i give my process ID.

I tried with "android.os.Process.sendSignal (int pid, android.os.Process.SIGNAL_USR1) ;" also.Getting the same problem.It is capturing Hprof dump for my process. For other processes it is not working.

Do we need to have any special permission to kill other process from our process ? Or is it a built issue ? can you please suggest some possible way to get Hprof dump for other processes from application code?

Thanks

A: 

Do we need to have any special permission to kill other process from our process ?

Yes, just like in any other Linux system.

can you please suggest some possible way to get Hprof dump for other processes from application code?

Root your phone.

You can try to use ActivityManager and its killBackgroundProcesses() method, but I do not know if that generates the file you wish. If it does, it is a security breach, and needs to be fixed.

CommonsWare