查看缓存的工具--缓存命中率--valgrind,perf

看缓存命中率
运用:
有两个程序,需要比较哪个程序更好?就需要比较程序的命中率,命中率高的就选用
[root@localhost ~]# yum -y install valgrind
[root@localhost ~]# valgrind --tool=cachegrind uname #uname为程序名

==4948== Cachegrind, a cache and branch-prediction profiler
==4948== Copyright (C) 2002-2017, and GNU GPL'd, by Nicholas Nethercote et al.
==4948== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==4948== Command: uname
==4948== 
--4948-- warning: L3 cache found, using its data for the LL simulation.
Linux
==4948== 
==4948== I   refs:      202,155#指令缓存
==4948== I1  misses:      1,043
==4948== LLi misses:      1,036
==4948== I1  miss rate:    0.52%
==4948== LLi miss rate:    0.51%
==4948== 
==4948== D   refs:       71,002  (52,073 rd   + 18,929 wr)#数据缓存
==4948== D1  misses:      3,354  ( 2,685 rd   +    669 wr)
==4948== LLd misses:      2,700  ( 2,083 rd   +    617 wr)
==4948== D1  miss rate:     4.7% (   5.2%     +    3.5%  )
==4948== LLd miss rate:     3.8% (   4.0%     +    3.3%  )
==4948== 
==4948== LL refs:         4,397  ( 3,728 rd   +    669 wr) #三级缓存
==4948== LL misses:       3,736  ( 3,119 rd   +    617 wr)
==4948== LL miss rate:      1.4% (   1.2%     +    3.3%  )

缓存被表示为 L1(一级),L2(二级),LL(最后一级)
I refs:需要读取的指令数,I1 misses: 缓存未命中数,LLi 缓存未命中数,I1 miss rate:未命中率,LLi miss rate:未命中率
D refs:需要读写取的数据数量,D1 misses:缓存未命中数,LLd misses:缓存未命中数… …
另外一个工具:perf
[root@localhost ~]# yum -y install perf

[root@localhost ~]# perf stat -e cache-misses uname
Linux

 Performance counter stats for 'uname':

             4,108      cache-misses                                                

       0.000890324 seconds time elapsed

主要用valgrind

你可能感兴趣的:(系统类)