使用llvm-prof收集LLVM Edge配置文件 [英] Collecting LLVM Edge Profiling with llvm-prof
问题描述
我使用这些命令来编译下面的代码,以便收集
边缘/阻塞profil在trunk-llvm:
clang -emit-llvm -c sort.c -o sort.bc
opt -insert-edge-profiling sort.bc -o sort_prof.bc
clang sort_prof.bc -lprofile_rt - L / llvms / lib -o sort_prof
然后运行程序并使用$ b显示分析信息$ b llvm-prof sort_prof.bc,结果是:
=== --------- -------------------------------------------------- -------------- ===
函数执行频率:
##频率
1. 4.3e + 05/708539 main
2. 2.8e + 05/708539 quickSort
注意:从未执行过两个函数!
.....
我的问题是关于执行频率。做任何
感觉主要执行4.3e + 05次?
为什么这样?我编译的代码如下。
################ ##### sort.c #######################
#include< stdio.h>
#include< stdlib.h>
#include< time.h>
const int MAX = 1000000;
void swap(int * a,int * b){
int tmp;
tmp = * a;
* a = * b;
* b = tmp;
}
int分区(int vec [],int left,int right){
int i,j;
i = left;
for(j = left + 1; j <= right; ++ j){
if(vec [j]< vec [left]){
++ i;
swap(& vec [i],& vec [j]);
}
}
swap(& vec [left],& vec [i]);
return i;
}
void quickSort(int vec [],int left,int right){
int r;
if(right> left){
r = partition(vec,left,right);
quickSort(vec,left,r - 1);
quickSort(vec,r + 1,right);
}
}
int main(void){
int vet [MAX],i = 0;
srand(time(NULL));
for(i = 0; i vet [i] = rand()%654321;
}
quickSort(vet,0,MAX-1);
for(i = 0; i if((rand()%7)> 2){
printf d] =%d \\\
,i,vet [i]);
}
else if((rand()%4)> 2){
printf(Num @ [%d] =%d\\\
,i,vet [i ]);
}
else if((rand(%2)> 1){
printf(Num#[%d] =%d\\\
,i,vet [i ]);
}
}
return 0;
}
问题是传递到llvm-prof的bitcode文件与仪器,正确的是使用原始文件(无仪器):
llvm-另一个与llvm-prof相关的问题是,它舍入了函数/块的执行频率(例如,函数/块执行频率)由于科学记数法。我已经向llvm提交了一个修补程序来纠正这个问题。
另一个提示是llvm-prof每个默认只显示前20个最多执行的基本块,用户任何方式改变它。我提交了另一个补丁,它添加了一个命令行参数,使用户可以设置他/她想要在输出中有多少基本块。
I'm using these commands to compile the code below in order to collect
edge/blocks profiling in trunk-llvm:
clang -emit-llvm -c sort.c -o sort.bc
opt -insert-edge-profiling sort.bc -o sort_prof.bc
clang sort_prof.bc -lprofile_rt -L/llvms/lib -o sort_prof
then I run the program and display the profiling information using
llvm-prof sort_prof.bc, and the result is:
===-------------------------------------------------------------------------===
Function execution frequencies:
## Frequency
1. 4.3e+05/708539 main
2. 2.8e+05/708539 quickSort
NOTE: 2 functions were never executed!
.....
My question is regarding the execution frequencies. Does make any
sense main executing 4.3e+05 times?
Why so? The code I'm compiling is below.
###################### sort.c ########################
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
const int MAX = 1000000;
void swap(int* a, int* b) {
int tmp;
tmp = *a;
*a = *b;
*b = tmp;
}
int partition(int vec[], int left, int right) {
int i, j;
i = left;
for (j = left + 1; j <= right; ++j) {
if (vec[j] < vec[left]) {
++i;
swap(&vec[i], &vec[j]);
}
}
swap(&vec[left], &vec[i]);
return i;
}
void quickSort(int vec[], int left, int right) {
int r;
if (right > left) {
r = partition(vec, left, right);
quickSort(vec, left, r - 1);
quickSort(vec, r + 1, right);
}
}
int main(void) {
int vet[MAX], i=0;
srand(time(NULL));
for (i=0; i<MAX; i++) {
vet[i] = rand() % 654321;
}
quickSort(vet, 0, MAX-1);
for (i=0; i<MAX; i++) {
if ((rand() % 7) > 2) {
printf("Num$[%d] = %d\n", i, vet[i]);
}
else if ((rand() % 4) > 2) {
printf("Num@[%d] = %d\n", i, vet[i]);
}
else if ((rand() % 2) > 1) {
printf("Num#[%d] = %d\n", i, vet[i]);
}
}
return 0;
}
解决方案 The problem was that I was passing to llvm-prof the bitcode file with instrumentation, the correct is to use the original file (without instrumentation):
llvm-prof sort.bc
another problem related to llvm-prof is that it's rounding the function/block execution frequency due to scientific notation. I've submitted a patch to llvm for correcting that.
Another tip is llvm-prof per default shows only the top 20 most executed basic blocks and it doesn't provide the user any means to change that. I've submitted another patch that add a command line parameter enabling the user to set how many basic blocks he/she wants in the output.
这篇关于使用llvm-prof收集LLVM Edge配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!