gpt4 book ai didi

c++ - gprof 与 cachegrind 配置文件

转载 作者:可可西里 更新时间:2023-11-01 15:05:00 24 4
gpt4 key购买 nike

在尝试优化代码时,我对 kcachegrdindgprof 生成的配置文件的差异感到有点困惑。具体来说,如果我使用 gprof(使用 -pg 开关编译等),我有这个:

Flat profile:

Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls ms/call ms/call name
89.62 3.71 3.71 204626 0.02 0.02 objR<true>::R_impl(std::vector<coords_t, std::allocator<coords_t> > const&, std::vector<unsigned long, std::allocator<unsigned long> > const&) const
5.56 3.94 0.23 18018180 0.00 0.00 W2(coords_t const&, coords_t const&)
3.87 4.10 0.16 200202 0.00 0.00 build_matrix(std::vector<coords_t, std::allocator<coords_t> > const&)
0.24 4.11 0.01 400406 0.00 0.00 std::vector<double, std::allocator<double> >::vector(std::vector<double, std::allocator<double> > const&)
0.24 4.12 0.01 100000 0.00 0.00 Wrat(std::vector<coords_t, std::allocator<coords_t> > const&, std::vector<coords_t, std::allocator<coords_t> > const&)
0.24 4.13 0.01 9 1.11 1.11 std::vector<short, std::allocator<short> >* std::__uninitialized_copy_a<__gnu_cxx::__normal_iterator<std::vector<short, std::alloca

这似乎表明除了 ::R_impl(...)

我不需要费心去寻找任何地方

与此同时,如果我在没有 -pg 开关的情况下进行编译并改为运行 valgrind --tool=callgrind ./a.out,我会得到一些相当不同的东西: 这是 kcachegrind 输出的屏幕截图

enter image description here

如果我正确地解释了这一点,它似乎表明 ::R_impl(...) 只需要大约 50% 的时间,而另一半花在线性代数上( Wrat(...)eigenvalues 和底层的 lapack 调用)在 gprof 配置文件中的下方。

我知道 gprofcachegrind 使用不同的技术,如果它们的结果有些不同,我不会介意。但在这里,它看起来非常不同,我不知道如何解释这些。有什么想法或建议吗?

最佳答案

您正在查看错误的列。您必须查看 kcachegrind 输出中的第二列,即名为“self”的列。这是特定子例程仅在不考虑其子例程时花费的时间。第一列是累计时间(它等于 100% 的机器时间),它的信息量不大(在我看来)。

请注意,从 kcachegrind 的输出中,您可以看到该进程的总时间为 53.64 秒,而子例程“R_impl”中花费的时间为 46.72 秒,占总时间的 87%。所以 gprof 和 kcachegrind 几乎完全一致。

关于c++ - gprof 与 cachegrind 配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6316697/

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