There are several examples in this. TAU, an open source profiler that works using PAPI, can also be used.
If, however, you want to write code to measure cache statistics, you can write a program using PAPI. PAPI allows the user to access equipment counters without having to know the system architecture. The PMU uses model-specific registers, so you must have the knwoledge of the registers used.
Perf allows you to measure L1 and LLC (this is L2), Cachegrind, on the other hand, allows the user to measure L1 and LLC (which can be L2 or L3, depending on which cache is at the highest level). Use Cachegrind only if you don't need faster results, because Cachegrind runs the program about 10X slower.
sol
source share