我使用clang-3.8 build / link option为我的流程获取了一些分析数据(code.profdata
):
-fprofile-instr-generate
我使用:
生成输出llvm-profdata show -all-functions -counts -ic-targets -output=llvm_prof.log code.profdata
谢谢!
数据:
Counters:
fn1:
Hash: 0x878e8bfe5d1b6a20
Counters: 8
Function count: 4464
Indirect Call Site Count: 0
Block counts: [4464, 0, 294838272, 0, 4464, 0, 4464]
Indirect Target Results:
file1.c:fn2:
Hash: 0x36804e8dae059d63
Counters: 6
Function count: 24576
Indirect Call Site Count: 0
Block counts: [24576, 24576, 0, 24576, 24576]
Indirect Target Results:
file2.c:fn3:
Hash: 0x000000000000028a
Counters: 3
Function count: 0
Indirect Call Site Count: 0
Block counts: [0, 0]
Indirect Target Results:
file3.c:fn4:
Hash: 0x0000000000000000
Counters: 1
Function count: 0
Indirect Call Site Count: 0
Block counts: []
Indirect Target Results:
答案 0 :(得分:0)
我错过了一步
LLVM工具链提供了另一种工具 - llvm-cov
需要将llvm-profdata merge
的输出传递给llvm-cov
以将函数计数器数据链接到源代码,如下所示:
llvm-cov show test.bin -instr-profile=merge.out
它将生成输出:
| 1|#include <stdio.h>
| 2|#include <stdlib.h>
1.11k| 3|#define CTR 10
| 4|
| 5|int
| 6|main()
1| 7|{
1| 8| int i, j, k;
11| 9| for(i=0; i < CTR; ++i) {
10| 10| printf("3: %d", i);
10| 11| }
101| 12| for(i=0; i < CTR*10; ++i) {
100| 13| printf("3: %d", i);
100| 14| }
1.00k| 15| for(i=0; i < CTR*100; ++i) {
1.00k| 16| printf("3: %d", i);
1.00k| 17| }
1| 18| // exit(0);
1| 19| return 0;
1| 20|}
写了一篇涵盖整个流程的博文:link