Flame Graph Scanning Mode
You can add the --flamegraph parameter next to the ./tiancheng command to scan and analyze hotspot functions in flame graph SVG files. It is recommended to use flame graph scanning mode for analysis.
Prerequisites
Assume that the Tiancheng Code Optimizer is installed in /home/tiancheng-x.x.x-Linux-Kunpeng.
Example
- Parse the flame graph SVG file, scan the top 3 hotspot functions, and generate an analysis report. In this example, the hotspot.svg file in /home/demo is scanned and the analysis report is stored in /home/demo. Replace the example parameter values with actual values.
./tiancheng --flamegraph /home/demo/hotspot.svg --top=3 -I /path/to/code_project/include -o /home/demo -r /path/to/code_project
Parse the hotspot.svg file in /home/demo, extract the top 3 hotspot functions, scan them, and specify the project header file to generate vectorization check report and JSON report files in /home/demo. In addition, specify the project root directory /path/to/code_project to avoid missing header files.
Command output:
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
Compile database file does not exist or is unreachable. Target functions to analyze: - FindCompoundDictionaryMatch (Score: 14.42%) // Indicates that the function to be analyzed is FindCompoundDictionaryMatch, and Score represents the sampling ratio of the function. - FindLongestMatchH5.constprop.0 (Score: 12.39%) - FindMatchLengthWithLimit (Score: 6.13%) [Locator] Analyzing: FindCompoundDictionaryMatch // Attempts to match the FindCompoundDictionaryMatch function. -> [Match] /path/to/code_project/enc/hash.h: 510 // Indicates the hash.h source file containing the FindCompoundDictionaryMatch function is matched. 510 represents the number of the line where the function is located. [Locator] Analyzing: FindLongestMatchH5 -> [Match] /path/to/code_project/enc/hash_longest_match_inc.h: 163 [Locator] Analyzing: FindMatchLengthWithLimit -> [Match] /path/to/code_project/enc/find_match_length.h: 37 ================================================================================ Analyzing file: /path/to/code_project/enc/find_match_length.h -------------------------------------------------------------------------------- Start to recognize 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. Start to scan code. [Match Found] Function: FindMatchLengthWithLimit at /path/to/code_project/enc/find_match_length.h:37 [FilterAnchors] Limiting from 21 to 10 anchors [CallDepth] Function 'FindMatchLengthWithLimit': original anchors=21, filtered=10 → disabling interprocedural analysis Vectorization check task is being executed. Please wait... Scanning start time: 2026/05/27 16:39:20 ================================================================================ Analyzing file: /path/to/code_project/enc/hash.h // Analyzes the hash.h source file. -------------------------------------------------------------------------------- Start to recognize file: /path/to/code_project/enc/hash.h // Starts to identify the hash.h source file. compile_commands.json not found under: /path/to/code_project Recursively collecting include paths as fallback. Start to scan code. // Starts to scan the code. [Match Found] Function: FindCompoundDictionaryMatch at /path/to/code_project/enc/hash.h:510 // Indicates that the FindCompoundDictionaryMatch function is successfully matched. [FilterAnchors] Limiting from 49 to 10 anchors // Indicates that the number of anchors to be filtered is limited to 10 (down from 49). [CallDepth] Function 'FindCompoundDictionaryMatch': original anchors=49, filtered=10 → disabling interprocedural analysis // Indicates that the call depth is restricted and cross-function analysis is disabled. Vectorization check task is being executed. Please wait... Scanning start time: 2026/05/27 16:39:32 ================================================================================ Analyzing file: /path/to/code_project/enc/hash_longest_match_inc.h -------------------------------------------------------------------------------- Start to recognize 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. Start to scan code. For the details information, please check: Successfully generated vectorization report: /home/demo/Vectorization_Source_20260527_163925_111_3056.html // Indicates the vectorization check report file path. Successfully generated vectorization optimization result: /home/demo/Vectorization_Optimization_Result_20260527_163925_111_3056.json // Indicates the JSON report file path.
- Open the generated JSON report file and analyze and confirm the modification points.
vim /home/demo/Vectorization_Optimization_Result_20260527_163925_111_3056.json
The JSON file content is as follows:
{ "advisor_items": [ { "opt_file": { "begin_line": 315, "description": "", "end_line": 317, "fileName": "/path/to/code_project/enc/hash.h", "headerFile": "#include <arm_neon.h>", "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/hash.h", "headerFile": "#include <arm_neon.h>", "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 }Table 1 Field description Field
Description
advisor_items
Array of code optimization suggestions. Each item in the array is a code tuning optimization.
opt_file
Detailed information about a single optimization suggestion.
begin_line
Start line number of the code to be tuned.
In the example, the start line number is 315.
description
Detailed description of the tuning suggestion.
end_line
End line number of the code to be tuned.
In the example, the end line number is 317.
fileName
Path to the analyzed source file.
In the example, the path is /path/to/code_project/enc/hash.h.
headerFile
Header file to be added.
In the example, #include <arm_neon.h> indicates that the Arm NEON header file must be included in this code snippet to use the NEON instruction set.
headerLocBegin
Start line number where the header file will be inserted.
- If the value is -1, the header file is already included in the code and does not need to be manually added.
- If the value is a positive integer, it indicates the start line number where the header file will be inserted.
In the example, the start line number is 11.
headerLocEnd
End line number where the header file will be inserted.
- If the value is -1, the header file is already included in the code and does not need to be manually added.
- If the value is a positive integer, it indicates the end line number where the header file will be inserted.
In the example, the end line number is 11.
sample_code
Recommended code vectorization sample, which can be directly used to replace the current code.
The following is an example of optimized 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
Tool execution status code.
- The value 0 indicates execution success.
- A non-zero value indicates an interruption.
In the example, 0 indicates that the tool is executed successfully.
recognizedPattern
Number of code snippets to be optimized.
In the example, the number is 2.
- Rewrite the code based on the JSON report.
- View advisor_items, which contains all identified optimization suggestions.
- For each optimization suggestion, check the begin_line and end_line fields to determine the code range to be replaced.
- Copy the vectorized code from sample_code and replace the code in the source file between begin_line and end_line.
- Check the headerLocBegin and headerLocEnd fields.
- If the value is -1, the header file already exists and does not need to be added.
- If the value is a positive integer, add the header file declaration in headerFile to the specified location.
- Save the modified file to complete the automatic rewrite.