开发者
资源
文档评分
获取效率
正确性
完整性
易理解
在线提单
论坛求助

火焰图扫描模式使用场景

用户可以通过在命令./tiancheng flamegraph之后,添加“--flamegraph”参数的方式,实现对火焰图SVG和鲲鹏性能定界工具KSYS分析结果JSON中热点函数的提取及扫描分析。推荐用户优先使用火焰图扫描模式进行分析。

前提条件

以天秤源码优化工具安装路径“/home/tiancheng-x.x.x-Linux-Kunpeng”为例。

火焰图扫描分析

解析火焰图SVG文件,对Top10的热点函数进行扫描并输出分析报告。此处以扫描“/home/demo”路径下的flamegraph.svg文件,分析报告存放至“/home/demo”路径为例,请根据实际情况进行修改。
./tiancheng flamegraph --flamegraph /home/demo/flamegraph.svg --top=10 -I /path/to/code_project/include -o /home/demo -r /path/to/code_project

解析“/home/demo”下的flamegraph.svg文件,提取出前10个热点函数,对前10个热点函数进行扫描,同时指定项目的头文件,在“/home/demo”下生成向量化检查报告和JSON报告文件。同时指定待分析源码文件所属项目的根目录“/path/to/code_project”,避免头文件缺失。

返回信息如下:

Compile database file does not exist or is unreachable.
Target functions to analyze: 
  - FindCompoundDictionaryMatch (Score: 14.42%) // 提示待分析的函数为FindCompoundDictionaryMatch函数,Score表示该函数的采样占比。
  - FindLongestMatchH5.constprop.0 (Score: 12.39%) 
  - FindMatchLengthWithLimit (Score: 6.13%) 
  - FindLongestMatchH5.constprop.1 (Score: 5.80%) 
  - SortHuffmanTreeItems.constprop.0 (Score: 4.30%) 
  - BrotliOptimizeHuffmanCountsForRle (Score: 3.86%) 
  - StoreRangeH5 (Score: 3.67%) 
  - SortHuffmanTree (Score: 3.49%) 
  - CreateBackwardReferencesDH5.isra.0 (Score: 3.20%) 
  - BrotliCreateHuffmanTree (Score: 2.96%) 

----------------------------------------------------------------------
Start to locate function: FindCompoundDictionaryMatch
     [Clang] locating: FindCompoundDictionaryMatch  file: hash.h
Start to locate function: FindLongestMatchH5.constprop.0
     [Clang] locating: FindLongestMatchH5.constprop.0  file: hash.h
     [Clang] locating: FindLongestMatchH5.constprop.0  file: hash_forgetful_chain_inc.h  (via hash.h)
     [Clang] locating: FindLongestMatchH5.constprop.0  file: hash_longest_match64_inc.h  (via hash.h)
     [Clang] locating: FindLongestMatchH5.constprop.0  file: backward_references_inc.h  (via backward_references.c)
     [Clang] locating: FindLongestMatchH5.constprop.0  file: hash_rolling_inc.h  (via hash.h)
     [Clang] locating: FindLongestMatchH5.constprop.0  file: hash_longest_match_inc.h  (via hash.h)
     [Clang] locating: FindLongestMatchH5.constprop.0  file: hash_longest_match_quickly_inc.h  (via hash.h)
     [Clang] locating: FindLongestMatchH5.constprop.0  file: hash_composite_inc.h  (via hash.h)
Start to locate function: FindMatchLengthWithLimit
     [Clang] locating: FindMatchLengthWithLimit  file: hash.h
     [Clang] locating: FindMatchLengthWithLimit  file: compress_fragment.c
     [Clang] locating: FindMatchLengthWithLimit  file: static_dict.c
     [Clang] locating: FindMatchLengthWithLimit  file: backward_references_hq.c
     [Clang] locating: FindMatchLengthWithLimit  file: compress_fragment_two_pass.c
     [Clang] locating: FindMatchLengthWithLimit  file: hash_forgetful_chain_inc.h  (via hash.h)
     [Clang] locating: FindMatchLengthWithLimit  file: hash_longest_match64_inc.h  (via hash.h)
     [Clang] locating: FindMatchLengthWithLimit  file: hash_to_binary_tree_inc.h  (via hash.h)
Start to locate function: FindLongestMatchH5.constprop.1
     [Clang] locating: FindLongestMatchH5.constprop.1  file: hash.h
     [Clang] locating: FindLongestMatchH5.constprop.1  file: hash_forgetful_chain_inc.h  (via hash.h)
     [Clang] locating: FindLongestMatchH5.constprop.1  file: hash_longest_match64_inc.h  (via hash.h)
     [Clang] locating: FindLongestMatchH5.constprop.1  file: backward_references_inc.h  (via backward_references.c)
     [Clang] locating: FindLongestMatchH5.constprop.1  file: hash_rolling_inc.h  (via hash.h)
     [Clang] locating: FindLongestMatchH5.constprop.1  file: hash_longest_match_inc.h  (via hash.h)
     [Clang] locating: FindLongestMatchH5.constprop.1  file: hash_longest_match_quickly_inc.h  (via hash.h)
     [Clang] locating: FindLongestMatchH5.constprop.1  file: hash_composite_inc.h  (via hash.h)
Start to locate function: SortHuffmanTreeItems.constprop.0
     [Clang] locating: SortHuffmanTreeItems.constprop.0  file: entropy_encode.h
Start to locate function: BrotliOptimizeHuffmanCountsForRle
     [Clang] locating: BrotliOptimizeHuffmanCountsForRle  file: entropy_encode.c
Start to locate function: StoreRangeH5
     [Clang] locating: StoreRangeH5  file: hash.h
     [Clang] locating: StoreRangeH5  file: hash_forgetful_chain_inc.h  (via hash.h)
     [Clang] locating: StoreRangeH5  file: hash_longest_match64_inc.h  (via hash.h)
     [Clang] locating: StoreRangeH5  file: hash_to_binary_tree_inc.h  (via hash.h)
     [Clang] locating: StoreRangeH5  file: backward_references_inc.h  (via backward_references.c)
     [Clang] locating: StoreRangeH5  file: hash_rolling_inc.h  (via hash.h)
     [Clang] locating: StoreRangeH5  file: hash_longest_match_inc.h  (via hash.h)
     [Clang] locating: StoreRangeH5  file: hash_longest_match_quickly_inc.h  (via hash.h)
Start to locate function: SortHuffmanTree
     [Clang] locating: SortHuffmanTree  file: brotli_bit_stream.c
     [Clang] locating: SortHuffmanTree  file: entropy_encode.c
     [Clang] locating: SortHuffmanTree  file: huffman.c
     [Clang] locating: SortHuffmanTree  file: huffman.h
     [Clang] locating: SortHuffmanTree  file: transform.c
     [Clang] locating: SortHuffmanTree  file: constants.c
     [Clang] locating: SortHuffmanTree  file: platform.c
     [Clang] locating: SortHuffmanTree  file: context.c
Start to locate function: CreateBackwardReferencesDH5.isra.0
     [Clang] locating: CreateBackwardReferencesDH5.isra.0  file: backward_references_inc.h  (via backward_references.c)
     [Clang] locating: CreateBackwardReferencesDH5.isra.0  file: backward_references.c
     [Clang] locating: CreateBackwardReferencesDH5.isra.0  file: transform.c
     [Clang] locating: CreateBackwardReferencesDH5.isra.0  file: constants.c
     [Clang] locating: CreateBackwardReferencesDH5.isra.0  file: platform.c
     [Clang] locating: CreateBackwardReferencesDH5.isra.0  file: context.c
     [Clang] locating: CreateBackwardReferencesDH5.isra.0  file: shared_dictionary.c
     [Clang] locating: CreateBackwardReferencesDH5.isra.0  file: dictionary.c
Start to locate function: BrotliCreateHuffmanTree
     [Clang] locating: BrotliCreateHuffmanTree  file: entropy_encode.c
----------------------------------------------------------------------
[Locator] Analyzing: FindCompoundDictionaryMatch // 开始匹配FindCompoundDictionaryMatch函数。
  -> [Match] /path/to/code_project/enc/hash.h: 510-611 
// 成功匹配FindCompoundDictionaryMatch函数所在的hash.h源文件,510-611表示该函数所在的行号位置。
[Locator] Analyzing: FindLongestMatchH5
  -> [Match] /path/to/code_project/enc/hash_longest_match_inc.h: 163-278
[Locator] Analyzing: FindMatchLengthWithLimit
  -> [Match] /path/to/code_project/enc/find_match_length.h: 37-141
[Locator] Analyzing: FindLongestMatchH5
  -> [Match] /path/to/code_project/enc/hash_longest_match_inc.h: 163-278
[Locator] Analyzing: SortHuffmanTreeItems
  -> [Match] /path/to/code_project/enc/entropy_encode.h: 84-117
[Locator] Analyzing: BrotliOptimizeHuffmanCountsForRle
  -> [Match] /path/to/code_project/enc/entropy_encode.c: 248-377
[Locator] Analyzing: StoreRangeH5
  -> [Match] /path/to/code_project/enc/hash_longest_match_inc.h: 116-130
[Locator] Analyzing: SortHuffmanTree
  -> [Overload] Collected 2 candidates for: SortHuffmanTree
  -> [Match] /path/to/code_project/enc/brotli_bit_stream.c: 400-403 [SortHuffmanTree(const HuffmanTree *, const HuffmanTree *)]
  -> [Match] /path/to/code_project/enc/entropy_encode.c: 49-58 [SortHuffmanTree(const HuffmanTree *, const HuffmanTree *)]
[Locator] Analyzing: CreateBackwardReferencesDH5
  -> [Match] /path/to/code_project/enc/backward_references_inc.h: 10-189
[Locator] Analyzing: BrotliCreateHuffmanTree
  -> [Match] /path/to/code_project/enc/entropy_encode.c: 75-154

================================================================================
Analyzing file: /path/to/code_project/enc/backward_references_inc.h
--------------------------------------------------------------------------------
compile_commands.json not found under: /path/to/code_project
Recursively collecting include paths as fallback. 

[Scan] Target  : /path/to/code_project/enc/backward_references_inc.h
[Scan] Mode    : template-include (no include guard / _inc.h suffix)
[Scan] Root    : /path/to/code_project
compile_commands.json not found under: /path/to/code_project
Recursively collecting include paths as fallback. 
Start to scan code. // 开始扫描代码。

================================================================================
Analyzing file: /path/to/code_project/enc/brotli_bit_stream.c
--------------------------------------------------------------------------------
compile_commands.json not found under: /path/to/code_project
Recursively collecting include paths as fallback. 

[Scan] Target  : /path/to/code_project/enc/brotli_bit_stream.c
[Scan] Mode    : direct scan (source file)
[Scan] Entry   : /path/to/code_project/enc/brotli_bit_stream.c

Start to scan code.

[Match Found] Function: SortHuffmanTree at /path/to/code_project/enc/brotli_bit_stream.c:400

================================================================================
Analyzing file: /path/to/code_project/enc/entropy_encode.c
--------------------------------------------------------------------------------
compile_commands.json not found under: /path/to/code_project
Recursively collecting include paths as fallback. 

[Scan] Target  : /path/to/code_project/enc/entropy_encode.c
[Scan] Mode    : direct scan (source file)
[Scan] Entry   : /path/to/code_project/enc/entropy_encode.c

Start to scan code.

[Match Found] Function: SortHuffmanTree at /path/to/code_project/enc/entropy_encode.c:49

[Match Found] Function: BrotliCreateHuffmanTree at /path/to/code_project/enc/entropy_encode.c:75

[Match Found] Function: BrotliOptimizeHuffmanCountsForRle at /path/to/code_project/enc/entropy_encode.c:248
  [FilterAnchors] Limiting from 37 to 10 anchors
  [CallDepth] Function 'BrotliOptimizeHuffmanCountsForRle': original anchors=37, filtered=10 → disabling interprocedural analysis 

Vectorization check task is being executed. Please wait...
Scanning start time: 2026/08/13 16:04:15

================================================================================
Analyzing file: /path/to/code_project/enc/entropy_encode.h
--------------------------------------------------------------------------------
compile_commands.json not found under: /path/to/code_project
Recursively collecting include paths as fallback. 

[Scan] Target  : /path/to/code_project/enc/entropy_encode.h
[Scan] Mode    : direct scan (standalone header)
[Scan] Entry   : /path/to/code_project/enc/entropy_encode.h

Start to scan code.

[Match Found] Function: SortHuffmanTreeItems.constprop.0 at /path/to/code_project/enc/entropy_encode.h:84

Vectorization check task is being executed. Please wait...
Scanning start time: 2026/08/13 16:04:15

================================================================================
Analyzing file: /path/to/code_project/enc/find_match_length.h
--------------------------------------------------------------------------------
compile_commands.json not found under: /path/to/code_project
Recursively collecting include paths as fallback. 

[Scan] Target  : /path/to/code_project/enc/find_match_length.h
[Scan] Mode    : direct scan (standalone header)
[Scan] Entry   : /path/to/code_project/enc/find_match_length.h

Start to scan code.

[Match Found] Function: FindMatchLengthWithLimit at /path/to/code_project/enc/find_match_length.h:37
  [FilterAnchors] Limiting from 23 to 10 anchors
  [CallDepth] Function 'FindMatchLengthWithLimit': original anchors=23, filtered=10 → disabling interprocedural analysis 

Vectorization check task is being executed. Please wait...
Scanning start time: 2026/08/13 16:04:15

================================================================================
Analyzing file: /path/to/code_project/enc/hash.h // 分析hash.h源文件。
--------------------------------------------------------------------------------
compile_commands.json not found under: /path/to/code_project
Recursively collecting include paths as fallback. 

[Scan] Target  : /path/to/code_project/enc/hash.h
[Scan] Mode    : direct scan (standalone header)
[Scan] Entry   : /path/to/code_project/enc/hash.h

Start to scan code. // 开始扫描代码。

[Match Found] Function: FindCompoundDictionaryMatch at /path/to/code_project/enc/hash.h:510 // 提示FindCompoundDictionaryMatch函数匹配成功。
  [FilterAnchors] Limiting from 51 to 10 anchors // 提示将过滤锚点数量从51个限制为10个。
  [CallDepth] Function 'FindCompoundDictionaryMatch': original anchors=51, filtered=10 → disabling interprocedural analysis  // 限制调用深度,提示禁用跨函数分析。

Vectorization check task is being executed. Please wait...
Scanning start time: 2026/08/13 16:04:16

================================================================================
Analyzing file: /path/to/code_project/enc/hash_longest_match_inc.h
--------------------------------------------------------------------------------
compile_commands.json not found under: /path/to/code_project
Recursively collecting include paths as fallback. 

[Scan] Target  : /path/to/code_project/enc/hash_longest_match_inc.h
[Scan] Mode    : template-include (no include guard / _inc.h suffix)
[Scan] Root    : /path/to/code_project
compile_commands.json not found under: /path/to/code_project
Recursively collecting include paths as fallback. 
Start to scan code.

[Match Found] Function: StoreRangeH5 at /path/to/code_project/enc/hash_longest_match_inc.h:116

[Match Found] Function: FindLongestMatchH5.constprop.0 at /path/to/code_project/enc/hash_longest_match_inc.h:163
  [FilterAnchors] Limiting from 40 to 10 anchors
  [CallDepth] Function 'FindLongestMatchH5': original anchors=40, filtered=10 → disabling interprocedural analysis 

Vectorization check task is being executed. Please wait...
Scanning start time: 2026/08/13 16:04:17
For the details information, please check:
Successfully generated vectorization report: /home/demo/Vectorization_Source_20260813_160350_662_6871.html
 // 提示HTML向量化检查报告文件的存放路径。
Successfully generated vectorization optimization result: /home/demo/Vectorization_Optimization_Result_20260813_160350_662_6871.json // 提示JSON报告文件的存放路径

扫描任务已完成,分析结果已保存到指定的输出目录中。

输出目录中包含两类分析报告,请根据实际需求选择查看:

  • JSON报告文件:仅包含已成功优化的可向量化代码片段,适用于快速提取优化结果场景。
  • HTML报告文件:提供全景视图,详细展示“可向量化”、“潜在向量化”及“不可向量化”三类代码,适用于深入分析优化潜力场景。

查看向量化检查报告

  • 查看HTML向量化检查报告文件。

    报告内容包括Top热点函数展示、循环向量化检查报告、函数向量化检查报告和任务信息。具体内容如下图所示,报告参数说明请参见表1。

    如示例中所示,排名Top 1的热点函数为FindCompoundDictionaryMatch,其热点占比表示该函数性能开销为14.42%,为性能优化的最高优先级目标。用户可依据此优先级对该函数进行针对性优化,单击该热点函数右侧的对应操作,可查看该热点函数向量化检查的具体信息。

    • 若该热点函数未检测到有可优化项,则对应项的操作栏为不可选状态。
    • 当启用x86 Intel intrinsics分析功能时报告中才有函数向量化检查报告,不启用时报告中的函数向量化检查报告为空。
    表1 Top热点函数参数说明

    参数

    说明

    Top热点函数

    热点排序

    根据用户指定的Top N,按性能开销占比从高到低对热点函数进行排序。用于确定优化优先级。

    热点占比

    热点函数的性能开销占比。

    函数名称

    热点函数的名称。

    源码文件存放路径

    热点函数所在源码文件的存放路径。

    热点函数行号

    被识别为性能热点的函数在源码文件中的起始行号位置。

    函数优化

    用于标识当开启x86 Intel intrinsics分析功能时的函数优化情况。当值为1时,表示该函数可优化;当值为0时,则表明功能未开启或该函数不可优化。

    循环优化

    可优化循环总数。

    操作

    查看热点函数的函数或循环可优化信息。

    单击“循环向量化检查报告”查看循环检查结果。具体内容如下图所示,报告结果参数说明请参见表2。

    表2 循环向量化检查报告结果参数说明

    参数

    说明

    循环向量化统计结果

    总循环数量

    源码文件中扫描出的循环总数。

    可向量化数量

    源码文件中扫描出的可以进行向量化的循环数量。

    潜在向量化数量

    需要进行特殊处理(如函数内联)才有可能向量化的循环数量。

    不可向量化数量

    源码文件中扫描出的不可向量化的循环数量。

    分析循环行数

    被识别为待优化循环的源码在源码文件中的具体行号位置。

    循环检查结果类别

    天秤源码优化工具检查出的循环类别,包括可向量化、潜在向量化和不可向量化三种类别。

    循环变量

    在循环中进行循环的变量。

    源码文件存放路径

    循环所在源码文件的存放路径。

    单击“分析循环行数”查看循环分析过程,包括可向量化、潜在向量化、不可向量化三种循环分析过程。循环分析过程参数说明请参见表3。

    • 可向量化循环分析过程如下图所示。如示例中所示,将向量化优化后的代码段复制并替换源文件对应位置(第315-317行)的代码,保存修改后的文件即可完成改写。

      天秤源码优化工具对支持改写的模块,直接提供优化后的代码段;对暂未匹配的模块,将在循环体逐行分析中输出向量化检查信息,可根据向量化检查结果进行优化。

    • 潜在向量化循环分析过程如下图所示,根据检查信息可查看源文件对应位置(第275-282行)代码的潜在向量化原因。

    • 不可向量化循环分析过程如下图所示,根据检查信息可查看源文件对应位置(第84-105行)代码的不可向量化原因。

    表3 循环分析过程参数说明

    循环分析过程

    参数

    说明

    可向量化分析

    循环完整代码段

    循环在源码文件中的代码段。

    向量优化后代码段

    天秤源码优化工具对循环进行向量化优化后的代码段。

    潜在向量化分析

    循环完整代码段

    循环在源码文件中的代码段。

    不可向量化分析

    不可向量化原因

    天秤源码优化工具将循环判断为不可向量化的原因。

    循环完整代码段

    循环在源码文件中的代码段。

    公有参数

    循环体分析(逐行)

    天秤源码优化工具对循环进行检查分析的过程。

    代码行

    循环中循环体的代码行。

    覆盖率

    是否被天秤可向量化模式匹配覆盖。

    代码行向量化状态

    循环体单个代码行的向量化状态,包括可向量化、潜在向量化、不可向量化三种类别。

    检查信息

    天秤源码优化工具对代码行的检查分析结果。

    说明:

    如果代码行向量化状态为可向量化,则不显示检查信息;如果代码行向量化状态为潜在向量化和不可向量化,则显示对应的原因或建议。

    未开启x86 Intel intrinsics分析功能,函数向量化检查报告内容为空。具体内容如下图所示。

    单击“任务信息”可查看当前检查报告的生成信息。具体内容如下图所示,任务信息参数说明请参见表4。

    在“任务信息”中可快速查看报告名称、报告生成时间、源码存放路径等相关信息。

    表4 任务信息参数说明

    参数

    说明

    任务名称

    天秤源码优化工具自动创建的检查任务名。

    报告生成时间

    天秤源码优化工具生成报告的时间。

    源码文件存放路径

    扫描的源码所在文件的路径。

    火焰图路径

    扫描的火焰图SVG文件的路径。

    特定函数名

    扫描的函数名。

    文件所属项目

    待分析源码文件所属项目的根目录。

    Clang资源文件路径

    Clang内置头文件(如stddef.h)所在的目录。

    GCC工具链

    GCC编译器安装的目录,作为代码分析时的工具链路径。

    是否启用SVE

    是否转换为SVE指令集。

    HTML报告侧重诊断分析,需根据提示人工调整代码结构,调整后重新验证效果。

  • 查看JSON报告文件。

    打开生成的JSON报告文件,分析并确认修改点。

    vim /home/demo/Vectorization_Optimization_Result_20260813_160350_662_6871.json

    JSON文件详情如下:

    {
      "advisor_items": [
        {
          "opt_file": {
            "begin_line": 315,
            "description": "",
            "end_line": 317,
            "fileName": "/path/to/code_project/enc/entropy_encode.c",
            "headerFile": {
              "name": "#include <arm_neon.h>",
              "operation": "add"
            },
            "headerLocBegin": 11,
            "headerLocEnd": 11,
            "sample_code": "          k = 0;\n          for (; k + 16 < step; k += 16) {\n              vst1q_u8(good_for_rle + i - k - 1, vdupq_n_u8(1));\n          }\n          for (; k < step; ++k) {\n            good_for_rle[i - k - 1] = 1;\n          }"
          }
        },
        {
          "opt_file": {
            "begin_line": 348,
            "description": "",
            "end_line": 352,
            "fileName": "/path/to/code_project/enc/entropy_encode.c",
            "headerFile": {
              "name": "#include <arm_neon.h>",
              "operation": "add"
            },
            "headerLocBegin": 11,
            "headerLocEnd": 11,
            "sample_code": "        k = 0;\n        for (; k + 4 < stride; k += 4) {\n            vst1q_u32(counts + i - k - 1, vdupq_n_u32(count));\n        }\n        for (; k < stride; ++k) {\n          /* We don't want to change value at counts[i],\n             that is already belonging to the next stride. Thus - 1. */\n          counts[i - k - 1] = (uint32_t)count;\n        }"
          }
        }
      ],
      "code": 0,
      "recognizedPattern": 2
    }
    表5 字段说明

    字段

    字段说明

    advisor_items

    代码优化点建议数组,里面的每一项都是一个代码优化点建议。

    opt_file

    单个优化建议的详细信息。

    begin_line

    需要优化代码的起始行号。

    示例中“315”为优化代码的起始行号。

    description

    优化建议的详细描述。

    end_line

    需要优化代码的结束行号。

    示例中“317”为优化代码的结束行号。

    fileName

    当前分析的源文件所在路径。

    示例中“/path/to/code_project/enc/entropy_encode.c”为分析的源文件所在路径。

    headerFile

    向量化过程中涉及的头文件处理信息。

    示例中"name": "#include <arm_neon.h>"表明此段代码需要新增或替换的目标头文件,用于使用NEON指令集,"operation": "add"表明该指定头文件的处理方式。

    “operation”包含的两种处理方式:

    • “add”:用于标量代码向量化时新增目标头文件。
    • “replace”:用于x86向ARM向量化迁移时将原有x86头文件替换为对应的ARM头文件。

    headerLocBegin

    头文件插入的起始行号。

    • 若为-1,表示头文件在原始代码中已经包含,无需手动添加。
    • 若为正整数,表示头文件插入的起始行号。

    示例中“11”为头文件插入的起始行号。

    headerLocEnd

    头文件插入的结束行号。

    • 若为-1,表示头文件在原始代码中已经包含,无需手动添加。
    • 若为正整数,表示头文件插入的结束行号。

    示例中“11”为头文件插入的结束行号。

    sample_code

    推荐的向量化实现代码样例,可直接用于替换源文件的原始代码。

    示例中以下代码为优化后的代码样例。

     k = 0;\n          for (; k + 16 < step; k += 16) {\n              vst1q_u8(good_for_rle + i - k - 1, vdupq_n_u8(1));\n          }\n          for (; k < step; ++k) {\n            good_for_rle[i - k - 1] = 1;\n          } 

    code

    工具执行状态码。

    • 0表示工具执行成功。
    • 非零值表示异常中断。

    示例中“0”表明工具执行成功。

    recognizedPattern

    需要优化的代码段数量。

    示例中“2”表明有2处代码需要优化。

    根据JSON文件进行代码改写。

    1. 查看advisor_items,其中包含了所有识别到的优化建议。
    2. 对于每个优化建议,查看begin_line和end_line字段,确定需要替换的代码范围。
    3. 将sample_code字段中的向量化代码复制并替换源文件对应位置的代码(第begin_line行至第end_line行)。
    4. 检查headerLocBegin和headerLocEnd字段:
      • 如果值为-1,表示头文件已存在,无需添加。
      • 如果为正整数,需要在指定位置添加headerFile中的头文件声明。
    5. 保存修改后的文件,即可完成自动化改写。