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

后端 未结 9 1566
一向
一向 2020-12-01 02:33

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 prox

相关标签:
9条回答
  • 2020-12-01 03:34

    Another tool for CPU performance counter-based profiling is oprofile. You can view its results using kcachegrind.

    0 讨论(0)
  • 2020-12-01 03:35

    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.
    0 讨论(0)
  • 2020-12-01 03:36

    Here's kind of a general answer.

    For example, if your program is spending, say, 50% of it's time in cache misses, then 50% of the time when you pause it the program counter will be at the exact locations where it is waiting for the memory fetches that are causing the cache misses.

    0 讨论(0)
提交回复
热议问题