我正在尝试学习 papi api 来监控各种 CPU 事件的性能。首先,我运行了 PAPI 官方文档中提到的示例片段之一。下面是代码
#include<stdio.h>
#include <unistd.h>
#include "papi.h"
#define NUM_EVENTS 2
int main()
{
int Events[NUM_EVENTS] = {PAPI_TOT_INS, PAPI_TOT_CYC};
int num1=1234;
int num2=9876;
int res1,res2;
long_long values[NUM_EVENTS];
/* Start counting events */
if (PAPI_start_counters(Events, NUM_EVENTS) != PAPI_OK)
printf("\nerror!!!\n");
//handle_error(1);
/* Do some computation here*/
res1=num1*num2;
printf("\n%d",res1);
/* Read the counters */
if (PAPI_read_counters(values, NUM_EVENTS) != PAPI_OK)
printf("\nerror!!!\n");
/* Do some computation here */
res2=num1+num2;
printf("\n%d",res2);
/* Stop counting events */
if (PAPI_stop_counters(values, NUM_EVENTS) != PAPI_OK)
printf("\nerror!!!\n");
return 0;
}
我使用包含文件路径编译它,如下所示
gcc -I/home/sabarna/Desktop/DEV/clockCycle/papi/src/ papi_try1.c -L/home/sabarna/Desktop/DEV/clockCycle/papi/src/ -lpapi
执行 a.out 时出现错误
/a.out: error while loading shared libraries: libpapi.so.5: cannot open shared object file: No such file or directory
我尝试通过导出 LD_PRELOAD 来解决这个问题,但这没有用。有人可以帮我吗?我以前从未使用过 PAPI api,所以我不确定我是否以正确的方式编译它。