Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux C++: how to profile time wasted due to cache misses?

I know that I can use gprof to benchmark my code.

However, I have this problem -- I have a smart pointer that has an extra level of indirection (think of it as a proxy object).

As a result, I have this extra layer that effects pretty much all functions, and screws with caching.

Is there a way to measure the time my CPU wastes due to cache misses?

like image 694
anon Avatar asked Mar 21 '10 11:03

anon


2 Answers

You could try cachegrind and it's front-end kcachegrind.

like image 54
Taavi Avatar answered Oct 06 '22 06:10

Taavi


Linux supports with perf from 2.6.31 on. This allows you to do the following:

  • compile your code with -g to have debug information included
  • run your code e.g. using the last level cache misses counters: perf record -e LLC-loads,LLC-load-misses yourExecutable
  • run perf report
    • after acknowledging the initial message, select the LLC-load-misses line,
    • then e.g. the first function and
    • then annotate. You should see the lines (in assembly code, surrounded by the the original source code) and a number indicating what fraction of last level cache misses for the lines where cache misses occurred.
like image 28
Andre Holzner Avatar answered Oct 06 '22 06:10

Andre Holzner