大网数据广告活动
服务器运维问答

Linux get CPU cache hit ratio

· 52CE 我爱测

AFAIK a lot of modern CPUs have counters for memory cache misses/hits. Is there an API/program which can query this? Is there a way to reset the counters? I'm interested in any generic or CPU specific program. Note: I'm aware of …

问题原文

原帖链接 · Karoly Horvath · CC BY-SA 3.0

AFAIK a lot of modern CPUs have counters for memory cache misses/hits.

Is there an API/program which can query this? Is there a way to reset the counters?

I'm interested in any generic or CPU specific program.

Note: I'm aware of cachegrind, but that's a simulation, and not the actual CPU counter.

社区高分解答

原帖链接 · Soham Chakraborty · CC BY-SA 3.0

Alright, I plundered some more resources and appears like for CPU cache hit/miss counters, we have to go for individual process or pid or tid based tracing. That is, in other words, perf and oprofile.

For example perf stat gives this.

 Performance counter stats for 'ls':

      3.905621 task-clock                #    0.831 CPUs utilized
             1 context-switches          #    0.000 M/sec
             0 CPU-migrations            #    0.000 M/sec
           267 page-faults               #    0.068 M/sec
       379,003 cycles                    #    0.097 GHz                     [24.55%]
     1,332,419 stalled-cycles-frontend   #  351.56% frontend cycles idle    [36.65%]
 <not counted> stalled-cycles-backend
       833,177 instructions              #    2.20  insns per cycle
                                         #    1.60  stalled cycles per insn
       580,745 branches                  #  148.695 M/sec                   [95.65%]
        37,799 branch-misses             #    6.51% of all branches         [71.09%]

   0.004697863 seconds time elapsed

Oprofile gives the similar output but perf is pretty awesome, imo.

Other thing is, for memory banks, numastat gives you another level of detail.

$ numastat
                       node0
numa_hit                74263001
numa_miss                      0
numa_foreign                   0
interleave_hit             15459
local_node              74263001
other_node                     0

Yeah, this system is a 1 node system.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-08-15)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。