1

I have an Android app with 3 activities in 1 package. I also have 1 more package(monitoring package) which has java files mainly for monitoring the performance of these 3 activities.Now I need to monitor cpu usage of my app and I need to have this cpumonitor file defined for the same in monitoring package. I am not supposed to touch the 3 activities. How do I achieve this?

I have seen various posts wherein you get the current running process from activitymanager and find cpu usage. In my case, I cant get context from these 3 activities since I am not allowed to edit them.

1 Answer 1

1

Only one of those Activities will be working at any one time. So attempting to monitor all 3 is going to be fruitless.

You can however monitor a process by package name.

Run this command through Java:

ps -o com.package.name

Here is an example of running a shell command on Android.

Sign up to request clarification or add additional context in comments.

2 Comments

What kind of output will I get? I am doing this - Process process = null; try { process = Runtime.getRuntime().exec("ps -o com.example.buttontestaspect"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
Try accessing your device and typing the command in. adb shell. You will need to parse this information yourself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.