measuring cache misses for a C program

       can u specificy how to measure the cache misses  for a C program
Who is Participating?
grg99Connect With a Mentor Commented:
The Pentium chips have a large set of built-in counters that can be directed to count all kinds of very low-level events, such as cache misses.   They're hard to access, but there are many helper functions available:

If you're doing this on LInux, pls see:

For Windows:

if you mean hardware cache misses that occur when memory items are not in the CPU cache then no - the C run-time provides no such platform specific feature. There may be a low level API for this but i should imagaine it will be CPU specific and only accessible from assembler.

if you mean from within your own data structures then you can code some hit counters quite easily and then report on them before your application exits.

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

The valgrind program does exactly what you're looking for.  It simulates execution of your binary program, including the behavior of your instruction and data caches, and can produce a summary report for all the memory accesses made by the program.
Forgot the link:
I'm not quite sure how valgrind can do all this, as there are sooo many different cache strategies in use, some secret.

Also valgrind isnt going to be able to simulate cache losses due the OS and interrupts taking up code and data cache space.

I'd suggest  if you need really accurate results stick with the hardware counters.

NovaDenizenConnect With a Mentor Commented:
This page describes how valgrind's "cachegrind" subsystem performs cache analysis:
extra-detailed information here:

How do you get to the actual hardware counters?
They're documented in Appendix A of:

Really a whole lot of stuff.

pad_anuAuthor Commented:
can I use VTune performance analyser tool to measure hardware performance counter
for C programs
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.