以编程方式计算缓存故障 [英] Programmatically counting cache faults
问题描述
我需要在一系列有关内存层次结构效率的假设中评估C ++函数所花费的时间(例如:读取数组的一部分时发生高速缓存未命中,高速缓存命中或页面错误所花费的时间),因此,我想拥有一些可以让我计算缓存未命中/页面错误的库,以便能够自动生成性能摘要.
我知道有一些诸如cachegrind之类的工具可以提供有关给定应用程序执行情况的一些相关统计信息,但是正如我已经说过的,我想要一个库.
编辑哦,我忘记了:我正在使用Linux,并且对可移植性不感兴趣,这是一门学术性的事情.
欢迎任何建议!
看起来现在正是我要搜索的内容: 解决方案
It looks like now there is exactly what I was searching for: perf_event_open.
It lets you do interesting things like initializing/enabling/disabling some performance counters for subsequently fetching their values through an uniform and intuitive API (it gives you a special file descriptor which hosts a struct containing the previously requested informations).
It is a linux-only solution and the functionalities varies depending on the kernel version, so be careful :)
这篇关于以编程方式计算缓存故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!