How to measure mispredictions for a single branch

2019-04-11 10:23发布

I know that I can get the total percentage of branch mispredictions during the execution of a program with perf stat. But how can I get the statistics for a specific branch (if or switch statement in C code)?

1条回答
孤傲高冷的网名
2楼-- · 2019-04-11 10:47

You can sample on the branch-misses event:

sudo perf record -e branch-misses <yourapp>

and then report it (and even selecting the function you're interested in):

sudo perf report -n --symbols=<yourfunction>

There you can access the annotated code and get some statistics for a given branch. Or directly annotate it with the perf command with --symbol option.

查看更多
登录 后发表回答