查看使用 oprofile 分析性能瓶颈的源代码
←
使用 oprofile 分析性能瓶颈
跳转到:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
您刚才请求的操作只有这个用户组中的用户才能使用:
用户
您可以查看并复制此页面的源代码:
== 例子 == oprofile 可以分析处理器周期、TLB 失误、分支预测失误、缓存失误、中断处理程序,等等。你可以使用 opcontrol --list-events 列出当前处理器上可监视事件列表。 下面分析一个编写不当的例子: [带有cache问题的代码cache.c] <source lang=c> int matrix[2047][7]; void bad_access() { int k, j, sum = 0; for(k = 0; k < 7; k++) for(j = 0; j < 2047; j++) sum += matrix[j][k] * 1024; } int main() { int i; for(i = 0; i< 100000; i++) bad_access(); return 0; } </source> 编译之: gcc -g cache.c -o cache 使用oprofile 分析之: <source lang=bash> $ opcontrol --init $ opcontrol --setup --event=DCACHE_MISSES:500::0:1 $ opcontrol --start && ./cache && opcontrol --dump && opcontrol --stop </source> 使用 opannotate 分析结果为: <source lang=bash> /* * Command line: opannotate --source ./cachee * * Interpretation of command line: * Output annotated source file with samples * Output all files * * CPU: GODSON2E, speed 0 MHz (estimated) * Counted ICACHE_MISSES events (Instruction Cache misses number ) with a unit mask of 0x00 (No unit mask) count 500 */ /* * Total samples for file : "/comcat/test/pmc.test/cachee.c" * * 34 100.000 */ :int matrix[2047][7]; : :void bad_access() :{ /* bad_access total: 33 97.0588 */ : int k, j, sum = 0; : : for(k = 0; k < 7; k++) 33 97.0588 : for(j = 0; j < 2047; j++) : sum += matrix[j][k] * 1024; : :} : :int main() :{ /* main total: 1 2.9412 */ : int i; : 1 2.9412 : for(i = 0; i< 10000; i++) : bad_access(); : : return 0; : :} : </source> opreport 解析的结果为: <source lang=bash> GodSonSmall:/comcat/test/pmc.test# opreport -l ./cache CPU: GODSON2E, speed 0 MHz (estimated) Counted ICACHE_MISSES events (Instruction Cache misses number ) with a unit mask of 0x00 (No unit mask) count 500 samples % symbol name 33 97.0588 bad_access 1 2.9412 main </source> 可以看到bad_access() cache miss 事件的样本共有33个,占总数的97% 改进 bad_access() 为 good_access() 后: <source lang=c> void good_access() { int k, j, sum = 0; for(k = 0; k < 2047; k++) for(j = 0; j < 7; j++) sum += matrix[k][j] * 1024; } </source> <source lang=bash> CPU: GODSON2E, speed 0 MHz (estimated) Counted ICACHE_MISSES events (Instruction Cache misses number ) with a unit mask of 0x00 (No unit mask) count 500 samples % symbol name 22 95.6522 good_access 1 4.3478 main </source> 可以看到改进后 cache miss 事件的样本减少为22个,占总数的95% <br><br> <br><br> <br><br> <br><br> <br><br> <br><br>
返回到
使用 oprofile 分析性能瓶颈
。
个人工具
登录
名字空间
页面
讨论
变换
查看
阅读
查看源代码
查看历史
操作
搜索
导航
首页
社区专页
新闻动态
最近更改
随机页面
帮助
工具箱
链入页面
相关更改
特殊页面