How to measure mispredictions for a single branch on Linux?
Asked Answered
U

1

6

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)?

Unipolar answered 4/11, 2015 at 13:35 Comment(0)
G
9

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.

Greyhen answered 5/11, 2015 at 9:48 Comment(1)
It can be more useful to record both branches and branch-misses events: sudo perf record -e branches,branch-misses. With --symbol there will be total counts for the function; in annotated code there will be percents of total counts for current function.Iaria

© 2022 - 2024 — McMap. All rights reserved.