1# 热日志定制开发指导
2
3## 概述
4
5### 简介
6
7OpenHarmony默认提供了热日志的特性。热日志是设备器件在使用过程中温度的流水日志。由于热日志输出的内容和路径在不同的产品上规格是不同的,产品希望根据产品的设计规格来定制此特性。OpenHarmony提供了热日志的定制方式,产品定制开发者可根据产品的设计规格来定制这些特性。
8
9### 约束与限制
10
11产品定制的配置路径,需要根据[配置策略](https://gitee.com/openharmony/customization_config_policy)决定。本开发指导中的定制路径以`/vendor`进行举例,请开发者根据具体的产品配置策略,修改定制路径。
12
13## 开发指导
14
15### 搭建环境
16
17设备要求:
18
19标准系统开发板,如DAYU200/Hi3516DV300开源套件。
20
21环境要求:
22
23Linux调测环境,相关要求和配置可参考《[快速入门](../quick-start/quickstart-overview.md)》。
24
25### 开发步骤
26
27本文以[DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568)为例介绍热日志的定制方法。
28
291. 在产品目录[(/vendor/hihope/rk3568)](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568)下创建thermal文件夹。
30
312. 参考[默认热日志的配置文件夹](https://gitee.com/openharmony/drivers_peripheral/tree/master/thermal/interfaces/hdi_service/profile)创建目标文件夹,并安装到`//vendor/hihope/rk3568/thermal`,文件格式如下:
32
33    ```text
34    profile
35    ├── BUILD.gn
36    ├── thermal_hdi_config.xml
37    ```
38
393. 参考[默认热日志的参数配置文件夹](https://gitee.com/openharmony/drivers_peripheral/tree/master/thermal/etc)创建目标文件夹,并安装到`//vendor/hihope/rk3568/thermal`,文件格式如下:
40    ```text
41    etc
42    ├── BUILD.gn
43    ├── thermal.para
44    ├── thermal.para.dac
45    ```
46
474. 参考[默认热日志的配置文件夹中的thermal_hdi_config.xml](https://gitee.com/openharmony/drivers_peripheral/blob/master/thermal/interfaces/hdi_service/profile/thermal_hdi_config.xml)编写定制的thermal_hdi_config.xml。包含热日志配置说明及定制后的热日志配置如下:
48
49    **表1** tracing配置说明
50
51    | 配置项名称 | 配置项描述 | 数据类型 | 取值范围 |
52    | -------- | -------- | -------- | -------- |
53    | outpath | 温度跟踪日志输出的路径 | string | 无 |
54
55    **表2** node配置说明
56
57    | 节点名称 | 配置项名称 | 配置项描述 |
58    | -------- | -------- | -------- |
59    | title | path | 获取thermal zone名称的路径 |
60    | title | name | thermal zone名称 |
61    | value | path | 获取thermal zone温度的路径 |
62
63    ```shell
64    <tracing outpath="/data/log/thermal-log">
65        <node>
66            <title path="sys/class/thermal/thermal_zone0/type"/>
67            <value path="sys/class/thermal/thermal_zone0/temp"/>
68        </node>
69        <node>
70            <title name="gpu-thermal"/>
71            <value path="sys/class/thermal/thermal_zone1/temp"/>
72        </node>
73    </tracing>
74    ```
75
765. 参考默认热日志的参数配置文件夹中的[thermal.para](https://gitee.com/openharmony/drivers_peripheral/blob/master/thermal/etc/thermal.para)和[thermal.para.dac](https://gitee.com/openharmony/drivers_peripheral/blob/master/thermal/etc/thermal.para.dac)编写定制的thermal.parathermal.para.dac。包含定制后的配置如下:
77
78    thermal.para79    ```text
80    persist.thermal.log.enable=true     # 打开thermal log
81    persist.thermal.log.interval=5000   # 温度跟踪日志的时间间隔,单位为毫秒
82    persist.thermal.log.width=20        # 温度跟踪日志的宽度,单位为字符
83    ```
84
85    thermal.para.dac86    ```text
87    persist.thermal.log.="power_host:power_host:500" # 控制访问权限
88    ```
89
906. 参考[默认热日志配置文件夹中的BUILD.gn](https://gitee.com/openharmony/drivers_peripheral/blob/master/thermal/interfaces/hdi_service/profile/BUILD.gn)编写BUILD.gn文件,将thermal_hdi_config.xml打包到`//vendor/etc/thermal_config/hdf`目录下:
91
92    ```shell
93    import("//build/ohos.gni")
94
95    ohos_prebuilt_etc("thermal_hdf_config") {
96        source = "thermal_hdi_config.xml"
97        relative_install_dir = "thermal_config/hdf"
98        install_images = [ chipset_base_dir ]       # 安装到vendor目录下的必要配置
99        part_name = "product_rk3568"                # part_name暂定为product_rk3568,以实现后续编译,产品定制根据需要自行修改
100    }
101    ```
102
1037. 参考[默认热日志的参数配置文件夹的BUILD.gn](https://gitee.com/openharmony/drivers_peripheral/blob/master/thermal/etc/BUILD.gn)编写BUILD.gn文件,将thermal.parathermal.para.dac打包到`//vendor/etc/param/thermal.para`目录下
104
105    ```shell
106    import("//build/ohos.gni")
107
108    ## Install thermal.para to /vendor/etc/param/thermal.para
109
110    ohos_prebuilt_etc("thermal.para") {
111        source = "thermal.para"
112        relative_install_dir = "param"
113        install_images = [ chipset_base_dir ]
114        part_name = "product_rk3568"
115    }
116
117    ohos_prebuilt_etc("thermal.para.dac") {
118        source = "thermal.para.dac"
119        relative_install_dir = "param"
120        install_images = [ chipset_base_dir ]
121        part_name = "product_rk3568"
122    }
123
124    group("param_files") {
125        deps = [
126            ":thermal.para",
127            ":thermal.para.dac",
128        ]
129    }
130    ```
131
1328. 将编译目标添加到[ohos.build](https://gitee.com/openharmony/vendor_hihope/blob/master/rk3568/ohos.build)的"module_list"中,例如:
133
134    ```json
135    {
136        "parts": {
137            "product_rk3568": {
138                "module_list": [
139                    "//vendor/hihope/rk3568/default_app_config:default_app_config",
140                    "//vendor/hihope/rk3568/image_conf:custom_image_conf",
141                    "//vendor/hihope/rk3568/preinstall-config:preinstall-config",
142                    "//vendor/hihope/rk3568/resourceschedule:resourceschedule",
143                    "//vendor/hihope/rk3568/etc:product_etc_conf",
144                    "//vendor/hihope/rk3568/thermal/profile:thermal_hdf_config",  // 添加thermal_hdf_config的编译
145                    "//vendor/hihope/rk3568/thermal/etc:param_files"              // 添加thermal.parathermal.para.dac的编译
146                ]
147            }
148        },
149        "subsystem": "product_hihope"
150    }
151    ```
152    “//vendor/hihope/rk3568/thermal/”为文件夹路径,“profile”、“etc”为创建的文件夹名字,“thermal_hdf_config”、“param_files”为编译目标。
153
1549. 参考《[快速入门](../quick-start/quickstart-overview.md)》编译定制版本,编译命令如下:
155
156    ```shell
157    ./build.sh --product-name rk3568 --ccache
158    ```
159
16010. 将定制版本烧录到DAYU200开发板中。
161
162### 调测验证
163
1641. 开机后,进入shell命令行:
165    ```shell
166    hdc shell
167    ```
168
1692. 进入定制后的目录。
170    ```shell
171    cd /data/log/thermal/
172    ```
173
174    查看热日志。
175    ```shell
176    cat thermal.000.20170805-175756
177    ```
178
179    成功获取热日志内容
180    ```shell
181    timestamp                    soc-thermal         gpu-thermal
182    2017-08-05 17:57:56          37777               37222
183    2017-08-05 17:58:01          38333               37777
184    2017-08-05 17:58:06          36666               37222
185    2017-08-05 17:58:11          36666               37222
186    2017-08-05 17:58:16          36666               37222
187    2017-08-05 17:58:21          36111               37222
188    2017-08-05 17:58:26          36111               37222
189    2017-08-05 17:58:31          36666               37222
190    2017-08-05 17:58:36          36111               37222
191    2017-08-05 17:58:41          36111               37222
192    2017-08-05 17:58:46          36666               36666
193    ```
194
195## 参考
196开发过程中可参考的配置文件路径:[默认热日志的配置源码路径](https://gitee.com/openharmony/drivers_peripheral/tree/master/thermal/interfaces/hdi_service/profile/) 和[默认热日志的参数配置源码路径](https://gitee.com/openharmony/drivers_peripheral/tree/master/thermal/etc)
197
198打包路径:`/vendor/etc/thermal_config/hdf`
199
200
201