Power consumption detection detects high CPU load events by event subscription.
For details about how to use the HiAppEvent APIs to subscribe to high CPU load events, see the following topic. Currently, only the ArkTS APIs are provided.
The system periodically collects the running time of third-party applications on the CPU and collects statistics on the average CPU load within the previous 5 minutes every 5 minutes under specific conditions (such as switching between the foreground and background). If the load exceeds the specified threshold, the HiAppEvent warning event is triggered.
The load in the high CPU load event triggered by the application is the running time normalized based on the number of CPU cores. For example, if an application process runs on a 10-core CPU for 5 minutes within 5 minutes, the average load is calculated as follows: 5 (running time on the CPU)/5 (statistics period, in minutes)/10 (number of cores) = 10%.
High CPU load events occur in the following scenarios:
When the average CPU load of a foreground application is greater than 30% within 5 minutes, a high CPU load event is triggered.
When the average CPU load of a background application is greater than 10% within 5 minutes, a high CPU load event is triggered.
When the average load of a single thread in 1 minute is greater than 70%, a high thread load event is triggered.
Foreground CPU high-load exception: By default, the call stack of a single application is captured only once a day, and the stack is sampled once a day.
High CPU load in the background: By default, the call stack of a single application is captured only once a day, and the stack is sampled once a day.
High thread CPU usage: By default, the sampling stack is captured only once a day.
You can customize related configurations.
In the last step of the subscription event development step, after obtaining the processing log of the system event data, you can search for the fault log file path recorded in external_log in the log to obtain the fault log. Example:
HiAppEvent eventInfo={"domain":"OS","name":"CPU_USAGE_HIGH","eventType":1,"params":{"begin_time":1765959898079,"bundle_name":"com.xpower.test","bundle_version":"1.0.0","end_time":1765959958079,"external_log":["/data/storage/el2/log/hiappevent/CPU_USAGE_HIGH_1765959959260_0.log"],"fault_type":3,"foreground":true,"log_over_limit":false,"threads":[{"name":"WorkerThread","tid":29164,"usage":72}],"time":1765959959257,"usage":72}} external_log records the path of the fault log file, from which you can obtain the fault log file.
The call stack fault log is the call chain stack information of the current faulty thread when the fault is triggered. For details about the format and description of call stack fault logs, see Log Specifications for Common Fault Scenarios.
Sampling stack fault logs are proactively collected perf logs. For details about the format and description of sampling stack fault logs, see Log Specifications.