I would like to measure L1, L2 and L3 Cache hit/miss ratio of some parts of my C++ code. I am not interested to use Perf for my entire application. Can Perf be used as a library inside C++?
int main() {
...
...
start_profiling()
// The part I'm interested in
...
end_profiling()
...
...
}
I gave Intel PCM a shot, but I had two issues with it. First, it gave me some strange numbers. Second, it doesn't support L1 Cache profiling.
If it's not possible with Perf, what is the easiest way to get that information?
Perf is a facility comprised of kernel infrastructure for gathering various events and userspace tool to get gathered data from the kernel and analyze it. It is like a gprof, but it is non-invasive, low-overhead and profile the whole stack, including your app, libraries, system calls AND kernel with CPU!
Sounds like all you're trying to do is read a few perf counters, something that the PAPI library is ideal for.
Example.
The full list of supported counters is quite long, but it sounds like you're most interested in PAPI_L1_TCM
, PAPI_L1_TCA
, and their L2
and L3
counterparts. Note that you can also break down the accesses into reads/writes, and you can distinguish instruction and data caches.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With