Android System CPU Resource related queries
We all know that Android is based on the Linux system kernel, in the Linux system we look at the system resource consumption, a direct command line from the top command to see that there is CPU specific usage, of course, on the Android system is still retained. Top is still useful, so how do you show it in Android apps?
In the "Settings" app, there is an out-of-the-box view of CPU usage in the developer options, and the display is displayed in the UI's system layer, not activities, which is always higher than activities, and can be displayed normally in any application interface. This system layer design of the UI is pretty good. Let's look at this setting first! Such as:
/*****************************************************************************************************/
Disclaimer: The content of this blog is by http://blog.csdn.net/edsam49 original, reproduced please indicate the source, thank you!
/*****************************************************************************************************/
We can see the display of this special layer in the upper right corner of the system, the LOADAVG is the average load, and the following is a few active tasks. How does this come true?
In the android4.4 system, there is a Developmentsettings.java in the code that sets up the application, there is a show_cpu_usage_key, and tracking it can find some key code:
private void Updatecpuusageoptions () { updatecheckbox (mshowcpuusage, Settings.Global.getInt (Getactivity (). Getcontentresolver (), Settings.Global.SHOW_PROCESSES, 0)! = 0); } private void Writecpuusageoptions () { Boolean value = mshowcpuusage.ischecked (); Settings.Global.putInt (Getactivity (). Getcontentresolver (), Settings.Global.SHOW_PROCESSES, value? 1:0); Intent service = (new Intent ()) . Setclassname ("Com.android.systemui", "Com.android.systemui.LoadAverageService "); if (value) { getactivity (). StartService (service); } else { getactivity (). StopService (service); } }
It is clear that the checkbox of the option is related to the setting value of the Settings.Global.SHOW_PROCESSES database, specifically, if it is hooked up, it triggers a service loadaverageservice on the boot systemui. This service is to get some CPU data, first analysis here, the next article to study some of the loadaverageservice, can not be analyzed proc below the system state file.
Android System CPU Resource related queries