gpt4 book ai didi

c++ - 是否可以在 C++ 代码中使用 Linux Perf 分析器?

转载 作者:太空狗 更新时间:2023-10-29 20:57:32 25 4
gpt4 key购买 nike

我想测量我的 C++ 代码某些部分的 L1、L2 和 L3 缓存命中/未命中率。我对在我的整个应用程序中使用 Perf 不感兴趣。 Perf 可以用作 C++ 内部的库吗?

int main() {
...
...
start_profiling()
// The part I'm interested in
...
end_profiling()
...
...
}

我试用了英特尔 PCM,但遇到了两个问题。首先,它gave me some strange numbers .其次,它不支持 L1 缓存分析。

如果 Perf 无法实现,获取该信息的最简单方法是什么?

最佳答案

听起来您要做的只是读取一些性能计数器,PAPI图书馆是理想的。

Example.

full list of supported counters很长,但听起来您对 PAPI_L1_TCMPAPI_L1_TCA 及其L2L3 最感兴趣> 同行。请注意,您还可以将访问分解为读/写,并且可以区分指令和数据缓存。

关于c++ - 是否可以在 C++ 代码中使用 Linux Perf 分析器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30293956/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com