1、先装上Intel PCM,具体安装可见GitHub
2、使用pcm中统计函数,具体如下:
getBytesReadFromMC是brief Computes number of bytes read from DRAM memory controllers
getBytesWrittenToMC是brief Computes number of bytes written to DRAM memory controllers
getBytesReadFromPMM是brief Computes number of bytes read from PMM memory
getBytesWrittenToPMM是brief Computes number of bytes written to PMM memory
3、嵌入自己的代码中,最终可以获得分别的读写量(return Number of bytes)
实列代码如下:
#include "cpucounters.h"//引入头文件
pcm::PCM * m = pcm::PCM::getInstance();
auto status = m->program();
pcm::SystemCounterState before_sstate = pcm::getSystemCounterState();
%your code
pcm::SystemCounterState after_sstate = pcm::getSystemCounterState();
printf("L3 misses: %lld\n",pcm::getL3CacheMisses(before_sstate, after_sstate));
printf("DRAM Reads (bytes): %lld\n",pcm::getBytesReadFromMC(before_sstate, after_sstate));
printf("DRAM Writes (bytes): %lld\n",pcm::getBytesWrittenToMC(before_sstate, after_sstate));
按照如下进行编译
记得将libpcm.so 做软连接到/usr/lib下
然后
g++ -O3 -g -std=c++11 -m64 -D_REENTRANT -fno-strict-aliasing -I/root/install/pcm/src -L/root/install/pcm -DINTEL -Wno-unused-value -Wno-format -o ./main-gu-zipfian main-gu-zipfian.c -lpcm -lpthread
4、更简便的用法待续。。。。
PCM API源码链接:https://github.com/intel/pcm/blob/master/src/cpucounters.h#L3707
参考文献:在代码中使用PCM(Processor Counter Monitor)_intel pcm api-CSDN博客
Using Intel’s PCM in Linux and inside C++ « All a bit technical