Cache Hit/Miss for a value in C/C++ Program Cache Hit/Miss for a value in C/C++ Program c c

Cache Hit/Miss for a value in C/C++ Program


If you really want to know when your caches are hitting/missing, modern processors have performance counters that you can use for exactly this purpose. I have used them extensively for academic research. The easiest way to use them is through perfmon2. Perfmon2 has both a library you can link into your program or a stand-alone program that will monitor an existing program. For example, here's the stand-alone program recording all level 1 data cache read requests and misses:

pfmon -eL1D_CACHE_LD:MESI,L1D_CACHE_LD:I_STATE your_program

For reference, Appendix A of this document (PDF) lists Intel's documentation on what hardware counters are available.


I would try using the valgrind cachegrind tool, it can print out annotated source lines with the number of hits/misses in which cache for that line.


I don't know if AMD CodeAnalyst can show that level of granularity but it wouldn't hurt to check.