Ideal cpu percent for android app [closed]

2020-06-06 07:58发布

问题:

I used adb shell to get cpu used by my android app.

and I recorded these values but I see in some cases cpu usage -for my app- 25%.

my question is: is this value -25% from cpu- very high or what? and what ideal cpu % for android app?

thanks in advance

回答1:

The first thing to remember is that when an app runs, it doesn't actually do computation for the whole time it's running: most of the time it's idle, waiting for data to arrive over the network, or while you're looking at it on the screen. Only very badly-written apps and games keep the CPU active the whole time they're running: this runs the battery down very quickly, and makes your phone rather warm.

So even if Chrome has been on the screen for 30 minutes, it shouldn't have used 30 minutes of CPU time. If it's completely static in that time and you're not interacting with it, it might not have used any CPU time at all! But at the other extreme, even if it was continually scrolling a page, it wouldn't use 30 minutes of CPU time: the screen updates every 1/60th of a second, and each time it just has to run for long enough to work out what the next frame should be.

CPU foreground

Bearing this in mind, CPU foreground is how much time the app has been running on the CPU while an activity from the app was in the foreground. (It might also include when a service from the app was in the foreground: that is, displaying an "ongoing" notification.) It's not a very useful figure on its own.

CPU total

I'm sure you already know that apps can run services and broadcast receivers in the background, as well as activities in the foreground. (For more on this, see What's the difference between a service and a broadcast receiver? ) CPU total includes all of this CPU use. If it's a lot more than CPU foreground, you might suspect that the app is doing a lot of work in the background and therefore might be a battery hog. How much is "a lot" depends on the app. An app that keeps running to check some remote service will use more CPU in the background than a sudoku game.

Keep awake

When the screen of your phone is off, it starts to think about having a quick nap. It enters a low-power mode called sleep where the CPU is almost completely powered down until needed. Because this can interrupt apps' background activities, an app can use a wake lock to stop the device going to sleep until it's finished. (There's also another kind of wake lock, which stops the screen turning off automatically. A video player might use that kind of wake lock.) An app can also use an alarm to wake the device up to perform some background tasks.

Keep awake measures the length of time that this app has used wake locks or alarms to keep the device awake when it would otherwise have been asleep. In a way, this is potentially the biggest drain on battery. Sleeping uses much less power than staying awake, so if an app keeps a wake lock for a long time, it's keeping your device in a high-power mode all that time, even if the app isn't doing any useful work.

If you have CPU usage to this extend for some time and then it release the usage its quite ok to some extend . If not you have identify which is your case for high CPU usage from above description .