By default, OpenHarmony provides the power consumption statistics feature. However, the power consumption benchmarks vary according to hardware specifications of different products. To address this issue, OpenHarmony provides the power consumption statistics customization function, allowing you to customize power consumption benchmarks depending on your hardware specifications.
Power consumption statistics: When a user uses a device, software and hardware services running on the device report usage events through HiSysEvent. The usage duration of software and hardware can be calculated based on these reported events. Then, the power consumption of the software and hardware can be calculated based on the hardware power consumption benchmarks.
Power consumption benchmark: baseline power consumption (unit: mA) of the product hardware in various states, for example, the baseline power consumption when the camera is turned on and the baseline power consumption of the CPU at different frequencies.
The configuration path for power consumption statistics customization is subject to the configuration policy. In this development guide, /vendor
is used as an example of the configuration path. During actual development, you need to modify the customization path based on the product configuration policy.
Hardware requirements:
Development board running the standard system, for example, the DAYU200 or Hi3516D V300 open source suite.
Environment requirements:
For details about the requirements on the Linux environment, see Quick Start.
The following uses DAYU200 as an example to illustrate power consumption statistics customization.
Create the battery_statistics
folder in the product directory /vendor/hihope/rk3568.
Create a target folder by referring to the default folder of power consumption statistics configuration, and install it in //vendor/hihope/rk3568/battery_statistics
. The content is as follows:
profile
├── BUILD.gn # BUILD.gn file
└── power_average.json # Configuration file for power consumption statistics, including the hardware power consumption benchmarks
Write the custom power_average.json
file by referring to the power_average.json file in the default folder of power consumption statistics configuration. The following table describes the configuration items for power consumption benchmarks.
Table 1 Description of the configuration items for power consumption benchmarks
Configuration Item | Hardware Type | Data Type | Description |
---|---|---|---|
alarm_on | - | Double | Power consumption when the timer is triggered by the system or application once; that is, the baseline power consumption. - Power consumption type: software power consumption - Statistical method: Power consumption = Number of triggering times x Power consumption benchmark |
bluetooth_br_on | Bluetooth | Double | Baseline power consumption when Bluetooth is enabled. - Power consumption type: hardware power consumption - Statistical method: Power consumption = Usage duration x Power consumption benchmark |
bluetooth_br_scan | Bluetooth | Double | Baseline power consumption for Bluetooth scanning. - Power consumption type: software power consumption - Statistical method: Power consumption = Usage duration x Power consumption benchmark |
bluetooth_ble_on | Bluetooth | Double | Baseline power consumption when Bluetooth Low Energy (BLE) is enabled. - Power consumption type: hardware power consumption - Statistical method: Power consumption = Usage duration x Power consumption benchmark |
bluetooth_ble_scan | Bluetooth | Double | Baseline power consumption for Bluetooth Low Energy (BLE) scanning. - Power consumption type: software power consumption - Statistical method: Power consumption = Usage duration x Power consumption benchmark |
wifi_on | WIFI | Double | Baseline power consumption when Wi-Fi is enabled. - Power consumption type: hardware power consumption - Statistical method: Power consumption = Usage duration x Power consumption benchmark |
wifi_scan | WIFI | Double | Power consumption when Wi-Fi scanning is performed once. - Power consumption type: hardware power consumption - Statistical method: Power consumption = Number of triggering times x Power consumption benchmark |
radio_on | Phone | Double array | Baseline power consumption when the call service is enabled. The value is in array format and is used to configure the baseline power consumption for different signal strength levels. The default configuration provides the baseline power consumption for four signal strength levels. - Power consumption type: hardware power consumption - Statistical method: Power consumption = Usage duration x Power consumption benchmark |
radio_data | Phone | Double array | Baseline power consumption when the network service is enabled. The value is in array format and is used to configure the baseline power consumption for different signal strength levels. The default configuration provides the baseline power consumption for four signal strength levels. - Power consumption type: hardware power consumption - Statistical method: Power consumption = Usage duration x Power consumption benchmark |
camera_on | Camera | Double | Baseline power consumption when the camera is enabled. - Power consumption type: software power consumption - Statistical method: Power consumption = Usage duration x Power consumption benchmark |
flashlight_on | Flashlight | Double | Baseline power consumption when the flashlight is enabled. - Power consumption type: software power consumption - Statistical method: Power consumption = Usage duration x Power consumption benchmark |
gnss_on | GNSS | Double | Baseline power consumption when the Global Navigation Satellite System (GNSS) is enabled. - Power consumption type: software power consumption - Statistical method: Power consumption = Usage duration x Power consumption benchmark |
sensor_gravity_on | Gravity Sensor | Double | Baseline power consumption when the gravity sensor is enabled. - Power consumption type: software power consumption - Statistical method: Power consumption = Usage duration x Power consumption benchmark |
sensor_proximity_on | Proximity Sensor | Double | Baseline power consumption when the proximity sensor is enabled. - Power consumption type: software power consumption - Statistical method: Power consumption = Usage duration x Power consumption benchmark |
audio_on | Audio | Double | Baseline power consumption when the audio is enabled. - Power consumption type: software power consumption - Statistical method: Power consumption = Usage duration x Power consumption benchmark |
screen_on screen_brightness |
Screen | Double |
screen_on: baseline power consumption of the screen in the basic state (excluding power consumption generated by screen brightness). screen_brightness: baseline power consumption additionally required when the screen brightness increases by one level. For example, if screen_on is 90, screen_brightness is 2, and the screen brightness is 100, then the baseline power consumption is calculated as follows: 90 + 2 x 100 = 290. - Power consumption type: hardware power consumption - Statistical method: Power consumption = Usage duration x Power consumption benchmark |
cpu_awake | CPU | Double | Baseline power consumption when the CPU wakes up the lock from the lock holding state. - Power consumption type: software power consumption - Statistical method: Power consumption = Usage duration x Power consumption benchmark |
cpu_idle | CPU | Double | Baseline power consumption when the CPU is in the idle state. - Power consumption type: software power consumption - Statistical method: Power consumption = Usage duration x Power consumption benchmark |
cpu_suspend | CPU | Double | Baseline power consumption when the CPU is in the sleep state. - Power consumption type: software power consumption - Statistical method: Power consumption = Usage duration x Power consumption benchmark |
cpu_active | CPU | Double | Baseline power consumption when the CPU is in the active state. - Power consumption type: software power consumption - Statistical method: Power consumption = Usage duration x Power consumption benchmark |
cpu_clusters cpu_speed_clusterX |
CPU | Double array |
cpu_clusters: baseline power consumption of a CPU cluster. The value is in array format and is used to configure the baseline power consumption for different CPU clusters. The default configuration provides the baseline power consumption for three CPU clusters. cpu_speed_clusterX: baseline power consumption of a CPU cluster at different frequencies, in array format. X indicates the sequence number. By default, its value ranges from 0 to 2, corresponding to the size of the cpu_clusters array. For example, if the default size of the cpu_clusters array is 3, the sequence number corresponds to the configuration items cpu_speed_cluster0, cpu_speed_cluster1, and cpu_speed_cluster2. - Scalability: scalability of CPU clusters - Power consumption type: software power consumption - Statistical method: Power consumption = Usage duration x Power consumption benchmark |
NOTE
The hardware type described in the table is the actual hardware name and does not represent the power consumption statistics type. For details about the power consumption statistics type, see ConsumptionType.
Write the BUILD.gn
file by referring to the BUILD.gn file in the default folder of power consumption statistics configuration to pack the power_average.json
file to the //vendor/etc/profile
directory. The configuration is as follows:
import("//build/ohos.gni") # Reference build/ohos.gni.
# Install power_average.json to /vendor/etc/profile/power_average.json
ohos_prebuilt_etc("power_average_config") { # Custom name, for example, power_average_config.
source = "power_average.json"
relative_install_dir = "profile"
install_images = [ chipset_base_dir ] # Required configuration for installing the power_average_config file in the vendor directory, where chipset_base_dir = "vendor". If this field is left unspecified, the power_average_config file is installed in the system directory by default.
part_name = "product_rk3568" # Set part_name to product_rk3568 for subsequent build.
}
Add the build target to module_list
in ohos.build in the /vendor/hihope/rk3568
directory. For example:
{
"parts": {
"product_rk3568": {
"module_list": [
"//vendor/hihope/rk3568/default_app_config:default_app_config",
"//vendor/hihope/rk3568/image_conf:custom_image_conf",
"//vendor/hihope/rk3568/battery_statistics/profile:power_average_config", # Add the configuration for building of power_average_config.
"//vendor/hihope/rk3568/preinstall-config:preinstall-config",
"//vendor/hihope/rk3568/resourceschedule:resourceschedule",
"//vendor/hihope/rk3568/etc:product_etc_conf"
]
}
},
"subsystem": "product_hihope"
}
In the preceding code, //vendor/hihope/rk3568/power/battery_statistics/
is the folder path, profile
is the folder name, and power_average_config
is the build target.
Build the customized version by referring to Quick Start.
./build.sh --product-name rk3568 --ccache
Burn the customized version to the DAYU200 development board.
After startup, run the following command to launch the shell command line:
hdc shell
Run the following command to check whether the power\_average\_config
file is successfully created in the vendor
directory:
ls -l /vendor/etc/profile/
The power\_average\_config
file is successfully created if it exists in /vendor/etc/profile/
.
# ls -l /vendor/etc/profile/
total 4
-rw-r--r-- 1 root root 1446 2023-03-26 16:47 power_average.json
#
If the power_average_config
file is successfully created, run the following command to check whether the information in the power_average_config
file in the vendor
directory is consistent with the customized information:
cat /vendor/etc/profile/power_average.json
If the information is consistent, run the following command to view the power consumption statistics:
hidumper -s 3304 -a -poweraverage
Check the console output for the custom power consumption benchmark information.
For example, the default power consumption benchmark information is as follows:
# hidumper -s 3304 -a -poweraverage
-------------------------------[ability]-------------------------------
----------------------------------BatteryStatisticsService---------------------------------
POWER AVERAGE CONFIGATION DUMP:
··· (Only the camera configuration is displayed here. Other information is omitted.)
camera_on : 810.000000
······
If the power consumption statistics benchmark is set to camera_on:3000 (default value: 810), the console output is as follows:
# hidumper -s 3304 -a -poweraverage
-------------------------------[ability]-------------------------------
----------------------------------BatteryStatisticsService---------------------------------
POWER AVERAGE CONFIGATION DUMP:
··· (Only the camera configuration is displayed here. Other information is omitted.)
camera_on : 3000.000000 # Set the power consumption benchmark to "camera_on": 3000.
······
Check whether the power consumption statistics are calculated according to the custom power consumption benchmark in the power_average_config
file.
You can use the JS APIs or Inner APIs provided by the batterystatistics module to obtain detailed power consumption information and verify the custom power consumption benchmark.
During development, you can refer to the default power consumption statistics configuration.
Default packing path: /system/etc/profile
Customization path: /vendor/etc/profile
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。