1# Thermal Log Customization
2
3## Overview
4
5### Introduction
6
7By default, the OpenHarmony provides the thermal log feature. Thermal logs record the temperature of device components during usage. However, the content and path of thermal logs vary according to product specifications. To address this issue, OpenHarmony provides the thermal log customization function.
8
9### Constraints
10
11The configuration path for battery level customization is subject to the [configuration policy](https://gitee.com/openharmony/customization_config_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.
12
13## How to Develop
14
15### Setting Up the Environment
16
17**Hardware requirements:**
18
19Development board running the standard system, for example, the DAYU200 or Hi3516D V300 open source suite.
20
21**Environment requirements:**
22
23For details about the requirements on the Linux environment, see [Quick Start](../quick-start/quickstart-overview.md).
24
25### Getting Started with Development
26
27The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568) as an example to illustrate thermal log customization.
28
291. Create the `thermal` folder in the product directory [/vendor/hihope/rk3568](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568).
30
312. Create a target folder by referring to the [default thermal log configuration folder](https://gitee.com/openharmony/drivers_peripheral/tree/master/thermal/interfaces/hdi_service/profile), and install it in `//vendor/hihope/rk3568/thermal`. The content is as follows:
32
33    ```text
34    profile
35    ├── BUILD.gn
36    ├── thermal_hdi_config.xml
37    ```
38
393. Create a target folder by referring to the [default thermal log parameter configuration folder](https://gitee.com/openharmony/drivers_peripheral/tree/master/thermal/etc) and install it in `//vendor/hihope/rk3568/thermal`. The file format is as follows:
40    ```text
41    etc
42    ├── BUILD.gn
43    ├── thermal.para
44    ├── thermal.para.dac
45    ```
46
474. Write the custom `thermal_hdi_config.xml` file by referring to the [thermal_hdi_config.xml](https://gitee.com/openharmony/drivers_peripheral/blob/master/thermal/interfaces/hdi_service/profile/thermal_hdi_config.xml) file in the default thermal log configuration folder. The following tables describe the related configuration items.
48
49    **Table 1** Description of the tracing configuration
50
51    | Configuration Item| Description| Data Type| Value Range|
52    | -------- | -------- | -------- | -------- |
53    | interval | Interval for recording temperature tracing logs, in ms.| int | >0 |
54    | width | Width of the temperature tracing log, in characters.| int | >0 |
55    | outpath | Path for storing temperature tracing logs.| string | N/A|
56
57    **Table 2** Description of the node configuration
58
59    | Node| Configuration Item| Description|
60    | -------- | -------- | -------- |
61    | title | path | Path for obtaining the thermal zone name.|
62    | title | name | Thermal zone name.|
63    | value | path | Path for obtaining the thermal zone temperature.|
64
65    ```shell
66    <tracing interval="5000" width="20" outpath="/data/log/thermal-log">
67        <node>
68            <title path="sys/class/thermal/thermal_zone0/type"/>
69            <value path="sys/class/thermal/thermal_zone0/temp"/>
70        </node>
71        <node>
72            <title name="gpu-thermal"/>
73            <value path="sys/class/thermal/thermal_zone1/temp"/>
74        </node>
75    </tracing>
76    ```
77
785. Write the custom `thermal.para` and `thermal.para.dac` files by referring to the [thermal.para](https://gitee.com/openharmony/drivers_peripheral/blob/master/thermal/etc/thermal.para) and [thermal.para.dac](https://gitee.com/openharmony/drivers_peripheral/blob/master/thermal/etc/thermal.para.dac) files in the default hot log parameter configuration folder. The custom configuration is as follows:
79
80    thermal.para:
81    ```text
82    persist.thermal.log.enable=true     # Enable the thermal log function.
83    persist.thermal.log.interval=5000   # Set the interval for recording temperature tracing logs, in ms.
84    persist.thermal.log.width=20        # Set the width of the temperature tracing log, in characters.
85    ```
86
87    thermal.para.dac:
88    ```text
89    persist.thermal.log.="power_host:power_host:600" # Configure access permissions.
90    ```
91
926. Write the `BUILD.gn` file by referring to the [BUILD.gn](https://gitee.com/openharmony/drivers_peripheral/blob/master/thermal/interfaces/hdi_service/profile/BUILD.gn) file in the default thermal log configuration folder to pack the `thermal_hdi_config.xml` file to the `//vendor/etc/thermal_config/hdf` directory. The configuration is as follows:
93
94    ```shell
95    import("//build/ohos.gni")
96
97    ohos_prebuilt_etc("thermal_hdf_config") {
98        source = "thermal_hdi_config.xml"
99        relative_install_dir = "thermal_config/hdf"
100        install_images = [ chipset_base_dir ]       # Required configuration for installing the thermal_hdi_config.xml file in the vendor directory.
101        part_name = "product_rk3568"                # Set part_name to product_rk3568 for subsequent build. You can change it as required.
102    }
103    ```
104
1057. Write the `BUILD.gn` file by referring to the [BUILD.gn](https://gitee.com/openharmony/drivers_peripheral/blob/master/thermal/etc/BUILD.gn) file in the default thermal log parameter configuration folder to pack the `thermal.para` and `thermal.para.dac` files to the `//vendor/etc/param/thermal.para` directory. The configuration is as follows:
106
107    ```shell
108    import("//build/ohos.gni")
109
110    ## Install thermal.para to /vendor/etc/param/thermal.para
111
112    ohos_prebuilt_etc("thermal.para") {
113        source = "thermal.para"
114        relative_install_dir = "param"
115        install_images = [ chipset_base_dir ]
116        part_name = "product_rk3568"
117    }
118
119    ohos_prebuilt_etc("thermal.para.dac") {
120        source = "thermal.para.dac"
121        relative_install_dir = "param"
122        install_images = [ chipset_base_dir ]
123        part_name = "product_rk3568"
124    }
125
126    group("param_files") {
127        deps = [
128            ":thermal.para",
129            ":thermal.para.dac",
130        ]
131    }
132    ```
133
1348. Add the build target to `module_list` in [ohos.build](https://gitee.com/openharmony/vendor_hihope/blob/master/rk3568/ohos.build) in the `/vendor/hihope/rk3568` directory. For example:
135
136    ```json
137    {
138        "parts": {
139            "product_rk3568": {
140                "module_list": [
141                    "//vendor/hihope/rk3568/default_app_config:default_app_config",
142                    "//vendor/hihope/rk3568/image_conf:custom_image_conf",
143                    "//vendor/hihope/rk3568/preinstall-config:preinstall-config",
144                    "//vendor/hihope/rk3568/resourceschedule:resourceschedule",
145                    "//vendor/hihope/rk3568/etc:product_etc_conf",
146                    "//vendor/hihope/rk3568/thermal/profile:thermal_hdf_config",  // Add the configuration for building of thermal_hdf_config.
147                    "//vendor/hihope/rk3568/thermal/etc:param_files"              // Add the configuration for building of thermal.para and thermal.para.dac.
148                ]
149            }
150        },
151        "subsystem": "product_hihope"
152    }
153    ```
154    In the preceding code, `//vendor/hihope/rk3568/thermal/` is the folder path, `profile` and `etc` are folder names, and `thermal_hdf_config` and `param_files` are the build targets.
155
1569. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md).
157
158    ```shell
159    ./build.sh --product-name rk3568 --ccache
160    ```
161
16210. Burn the customized version to the DAYU200 development board.
163
164### Debugging and Verification
165
1661. After startup, run the following command to launch the shell command line:
167    ```shell
168    hdc shell
169    ```
170
1712. Go to the customized directory.
172    ```shell
173    cd /data/log/thermal/
174    ```
175
176    View thermal logs.
177    ```shell
178    cat thermal.000.20170805-175756
179    ```
180
181    The following is the reference thermal log after customization:
182    ```shell
183    timestamp                    soc-thermal         gpu-thermal
184    2017-08-05 17:57:56          37777               37222
185    2017-08-05 17:58:01          38333               37777
186    2017-08-05 17:58:06          36666               37222
187    2017-08-05 17:58:11          36666               37222
188    2017-08-05 17:58:16          36666               37222
189    2017-08-05 17:58:21          36111               37222
190    2017-08-05 17:58:26          36111               37222
191    2017-08-05 17:58:31          36666               37222
192    2017-08-05 17:58:36          36111               37222
193    2017-08-05 17:58:41          36111               37222
194    2017-08-05 17:58:46          36666               36666
195    ```
196
197## Reference
198During development, you can refer to the [default thermal log configuration](https://gitee.com/openharmony/drivers_peripheral/tree/master/thermal/interfaces/hdi_service/profile/) and [default thermal log parameter configuration](https://gitee.com/openharmony/drivers_peripheral/tree/master/thermal/etc).
199
200Packing path: `/vendor/etc/thermal_config/hdf`
201