valgrind——Cachegrind分析CPU的cache命中率、丢失率,用于进行代码优化。
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                valgrind——Cachegrind分析CPU的cache命中率、丢失率,用于进行代码优化。
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                功能擴展1 Cachegrind
1.1 指令范式
單行最重要指令:
 valgrind --tool= [default: memcheck]
sun@sun:~/workspace/deptrum$ valgrind --tool=
//table  查看工具
cachegrind   callgrind    drd          exp-bbv      exp-dhat     exp-sgcheck  
getoff       helgrind     lackey       massif       memcheck     none          
Run the Valgrind tool called toolname,
 e.g. memcheck, cachegrind, callgrind, helgrind, drd, massif, dhat, lackey, none, exp-bbv, etc.
valgrind --tool=cachegrind ./build/bin/aurora300_runner ./data/d_aurora300/speckle.bmp --ir ./data/d_aurora300/ir.bmp --config ./data/d_aurora300/config/
 
1.2 cachegrind 指令,緩存和分支預測分析器。它可以幫助您使程序運行得更快。
1.2.1 指令范式
 valgrind --tool=cachegrind ./build/bin/aurora300_runner ./data/d_aurora300/speckle.bmp  
1.2.2 測試結果
 生成的文件名: cachegrind.out.73262,就是callgrind生成的文件。
1.2.3 kcachegrind工具安裝
首先安裝運行分析函數時間的工具 kcachegrind
 下載安裝包 http://kcachegrind.sourceforge.net/,下載最新的 tar.gz 文件
 解壓文件,進入解壓之后的目錄,從 README 中可以找到安裝方式,這里記錄一下
cmake .
make -j8
sudo make install
 
中間過程中遇到的一些,cmake的時候出問題,找不到一個依賴包
CMake Error at /usr/local/share/cmake-3.12/Modules/FindKDE4.cmake:100 (message):ERROR: cmake/modules/FindKDE4Internal.cmake not found in/home/zhangying/.kde/share/apps;/usr/share/kde4/apps
Call Stack (most recent call first):CMakeLists.txt:5 (find_package) 
sudo apt-get install kdelibs5-dev  
在 make install 的時候,如果沒有加 sudo 也會報錯
Install configuration: "RelWithDebInfo"
CMake Error at doc/cmake_install.cmake:49 (file):file cannot create directory: /usr/local/share/doc/HTML/en/kcachegrind.Maybe need administrative privileges.
Call Stack (most recent call first):cmake_install.cmake:42 (include)Makefile:85: recipe for target 'install' failed
make: *** [install] Error 1
 
這個時候加上 sudo 就可以了,此時分析工具安裝完成了,該分析工具是為了在 valgrind 跑完之后,會生成一個結果文件,該工具可以分析這個結果
使用 valgrind 跑程序
valgrind --tool=callgrind --separate-threads=yes ./runner
                            總結
以上是生活随笔為你收集整理的valgrind——Cachegrind分析CPU的cache命中率、丢失率,用于进行代码优化。的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: 魅族16thplus和RedmiK30买
 - 下一篇: 《梦仙》第四十句是什么