中文
注册
我要评分
文档获取效率
文档正确性
内容完整性
文档易理解
在线提单
论坛求助

编译反馈优化

编译反馈优化用于帮助用户更加方便的使用编译器的AutoFDO功能,使用编译反馈优化功能进行性能提升。

命令功能

根据用户配置可以帮助用户自动实现AutoFDO功能,进行性能提升。

命令格式

1
devkit advisor kfdo [-h | --help] {-i INPUT_CONFIG_PATH | --input INPUT_CONFIG_PATH} [-l {0,1,2,3} | --log-level {0,1,2,3}] [--set-timeout TIMEOUT]

参数说明

表1 参数说明

参数

参数选项

参数说明

-h/--help

-

获取帮助信息。

-i/--input

configuration_file_path

必选参数,配置文件的绝对路径,配置文件用于描述源码构建命令和perf采样信息。

例如:home/test/redis/config.json。

--set-timeout

time

任务超时时间,单位为分钟,若执行时间超过超时时间则退出执行。默认无超时时间,任务将持续执行直到结束。

-l/--log-level

0/1/2/3

设置日志级别,默认为1。
  • 0:日志级别为DEBUG。
  • 1:日志级别为INFO。
  • 2:日志级别为WARNING。
  • 3:日志级别为ERROR。

工具提供6种样例配置文件(all.json、run_sample_opt.json、sample_opt.json、opt.json、run_sample.json、sample.json),请根据实际情况进行选择。

样例配置文件路径为“/root/CLI/DevKit-CLI-xxx-Linux-Kunpeng/advisor/devkitplugins/affinity/tools/compileopt/templates/”。

“/root/CLI/DevKit-CLI-xxx-Linux-Kunpeng/”为命令行工具安装路径。

使用示例

此处以在“/home/test/redis”下进行编译反馈优化,config.json保存在“/home/test/redis”下为例,请根据实际情况进行修改。

1
2
3
4
ls -al /home/test /redis/
-rw-r--r--  1 test     test         817 Jul 15 20:43 config.json
-rw-r--r--  1 test      test    4189897 Jul 11 08:59 redis-7.2.5.zip   
devkit advisor kfdo -i /home/test/config.json

返回信息如下,并输出报告。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
['/home/test/affinity/devkitplugins/dist/advisor/devkitplugins/affinity/tools/compileopt/bin/kfdo', '--input', '/home/test/redis/config.json', '-l', '1']
begin to run kfdo tool
[#######...                                                              ]
[running] reading configuration file
[waiting] building baseline software
[waiting] using perf to collect sample profiles
[waiting] using profile to optimize binary program
[##############...                                                       ]
[      ] reading configuration file
[running] building baseline software
[waiting] using perf to collect sample profiles
[waiting] using profile to optimize binary program
...
[#######################################################################]
[      ] reading configuration file
[      ] building baseline software
[      ] using perf to collect sample profiles
[      ] using profile to optimize binary program
finish run kfdo tool

config.json文件说明

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
{
    /**
     * stages可以设置的值有all,run_sample_opt,sample_opt,opt,run_sample,sample
     *
     * all表示执行所有的步骤,包含步骤1基础编译,步骤2运行负载程序,步骤3采集程序数据,步骤4优化编译。
     * run_sample_opt表示执行三个步骤,包含步骤2运行负载程序,步骤3采集程序数据,步骤4优化编译。
     * sample_opt表示执行两个步骤,包含步骤3采集程序数据,步骤4优化编译。
     * opt表示只执行步骤4优化编译
     * run_sample表示执行两个步骤,包含步骤2运行负载程序,步骤3采集程序数据, 并在${workspace}/devkit_compiler目录下生成profile.afdo文件,该文件用于优化编译步骤中的afdo_file。
     * sample只执行步骤3采集程序数据,并在${workspace}/devkit_compiler目录下生成profile.afdo文件,该文件用于优化编译步骤中的afdo_file。
     */
    "stages": "all",
    /**
     * compiler_type可以设置的值有gcc,bisheng
     *
     * gcc:
     *    1.在采集程序数据步骤中,使用create_gcov创建profile.afdo文件
     *    2.在基础编译步骤和优化编译步骤中,使用的编译器为gcc for OpenEuler或者gcc(当前只支持7.x到10.x版本)。
     * bisheng:
     *    1.在采集程序数据步骤中,使用create_llvm_prof创建profile.afdo文件
     *    2.在基础编译步骤和优化编译步骤中,使用的编译器为毕昇编译器 (当前只支持2.4到4.0版本)。
     */
    "compiler_type" : "bisheng",
    // 执行命令的基础目录
    "workspace" : "/home/workspace/",
    // 步骤1: 基础编译
    "baseline_build" : {
        //环境变量
        "env":{
            // 环境变量CC,编译器具体命令。
            // "CC": "clang"
        },
        // 编译命令,支持多条命令,多个命令用分号分割。
       "command" : "cd redis-6.2.14;make"
    },
    // 步骤2: 运行负载程序
    "load_program" : [
        {
            // 环境变量
            "env":{
                // "LD_LIBRARY_PATH": "/home/workspace/local/lib64"
            },
            // 启动命令,只支持单条命令。
            "command" : "/home/workspace/redis-6.2.14/src/redis-server /home/workspace/redis.conf",
            // 停止命令,只支持单条命令。在采集完成后执行,不配置则默认通过拉起时的进程组进行停止。
            "stop_command":"/bin/bash /home/workspace/stop.sh",
            // 下一个应用的启动间隔,单位秒
            "interval": 5
        },
        {
            // 应用压力测试
            // 环境变量
            "env":{
                // "LD_LIBRARY_PATH": "/home/workspace/local/lib64"
            },
            // 启动命令,只支持单条命令。
            "command" : "/home/workspace/redis-6.2.14/src/redis-benchmark -t set -n 1000000",
            // 停止命令,只支持单条命令。在采集完成后执行,不配置则默认通过拉起时的进程组进行停止。
            "stop_command":"",
            // 下一个应用的启动间隔
            "interval": 0
        }
    ],
    // 步骤3: 采集程序数据
    "perf_sample" : {
        // 需要进行采样的程序启动命令的特征,通过ps -e -o pid,command,可以查询到
        "app_names":["redis-server"],
        // 采集时间,单位秒
        "duration" : 10,
        // 采集时延,单位秒
        "delay" : 0,
        // 使用create_llvm_prof或者create_gcov生成profile.afdo需要的二进制文件
        "create_afdo":{
            "binary":  "/home/workspace/redis-6.2.14/src/redis-server"
        }
    },
    // 步骤4: 优化编译
    "optimize_build" : {
        // 环境变量
        "env":{
            // 环境变量CC,编译器具体命令。
            //  "CC": "clang"
        },
        // afdo_file配置只有当stages为opt时,才生效,其他场景不生效。用于指定优化编译时使用的采集优化的数据,
        //     可通过create_llvm_prof或者create_gcov生成。
        // "afdo_file": "/home/workspace/devkit_compiler/profile.afdo",
        // 编译命令,支持多条命令,多个命令用分号分割。
        "command" : "cd redis-6.2.14_opt;make"
    }
}
表2 config.json文件说明

参数

参数选项

说明

stage

all,run_sample_opt,sample_opt,opt,run_sample,sample

  • all表示执行基础编译,运行负载程序、采集程序数据和优化编译。
  • run_sample_opt表示运行负载程序、采集程序数据和优化编译。
  • sample_opt表示执行采集程序数据和优化编译。
  • opt表示只执行优化编译。
  • run_sample表示执行运行负载程序和采集程序数据,并在${workspace}/devkit_compiler目录下生成profile.afdo文件,该文件用于优化编译中的afdo_file。
  • sample只执行采集程序数据,并在${workspace}/devkit_compiler目录下生成profile.afdo文件,该文件用于优化编译中的afdo_file。

compiler_type

gcc,bisheng

编译过程中需要使用的编译器类型,支持gcc、bisheng。

workspace

-

执行命令的基础目录。

baseline_build

env

基础编译环境变量。

command

基础编译命令,支持多条命令,多个命令用英文分号分割。

load_program

env

运行负载程序环境变量。

command

负载程序启动命令。

stop_command

负载程序停止命令,只支持单条命令。在采集完成后执行,不配置则默认通过拉起时的进程组进行停止。

interval

下一个应用的启动间隔时间,单位秒。

perf_sample

app_names

需要进行采样的程序启动命令的特征,通过“ps -e -o pid,command”可以查询到。

duration

采集时间,单位秒。

delay

采集时延,单位秒。

create_afdo

  • binary

使用create_llvm_prof或者create_gcov生成profile.afdo需要的二进制文件。

optimize_build

env

优化编译环境变量。

afdo_file

afdo_file配置只有当stages为opt时才生效,其他场景下不生效。

用于指定优化编译时使用的采集优化的数据,可通过create_llvm_prof或者create_gcov生成。

command

优化编译命令,支持多条命令,多个命令用英文分号分割。