Reputation: 449
I want to find how much cache efficient my C++ code is. I am running it on UBUNTU. How to find the number of cache hits or cache miss ?
Another Question is: I found using time command: one part of my code is giving 2133 (minor) page faults and another one is giving 2361 (minor) page faults. Is (minor) page faults is related to cache miss? If so how it is related. I have to perform some I/O is that can cause (minor) page faults ?
Upvotes: 2
Views: 894
Reputation: 129314
Writing my own answer as it was getting longer than a single comment to Chris Dodd's answer...
You can use oprofile or perftool (which is basically using the same kernel functionality as oprofile) will give you cache hits vs. misses. Note that it's hard to say "how many cache-misses" or "cache-hits" an application "should have", and you can really only compare the number with another run of the same application (after tweaks, but also seeing how much it varies from one run to another can be quite useful).
I don't think the exact number of page-faults is that critical - it tends to vary a little bit depending on "luck".
Page faults are caused by all manner of things. For example allocating a large chunk of memory, that memory will be "not present" when the page gets used the first time, and at that point, it is then marked present (and probably also filled with zero at that point). You also get page-faults from loading functions from shared libraries, as they are "not present" when the shared library is initialized. In some cases, it may also be that a part of the application uses mmap
to map in a file, instead of usign file-read/write operations (which is probably what you are thinking of with regards to File I/O).
Upvotes: 1
Reputation: 126110
The most comprehensive profiling tool for linux is oprofile, which can profile single applications or your entire system, and can give you detailed information about cache misses (and where they are occurring) on processors that support performance counters for events like cache misses (pretty much all x86 processors made for the past 20 years support such counters)
Page faults have nothing to do with cache misses, though they are also a potential source of performance problems.
Upvotes: 2