【发布时间】:2011-09-13 02:06:03
【问题描述】:
在尝试优化代码时,我对kcachegrdind 和gprof 生成的配置文件的差异感到有些困惑。具体来说,如果我使用 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 输出的屏幕截图
如果我解释正确,这似乎表明::R_impl(...) 只需要大约 50% 的时间,而另一半则用于线性代数(Wrat(...)、eigenvalues 和底层的 lapack 调用)在gprof 配置文件的下方。
我知道gprof 和cachegrind 使用不同的技术,如果他们的结果有些不同,我不会打扰。但是在这里,它看起来非常不同,我不知道如何解释这些。有什么想法或建议吗?
【问题讨论】:
标签: c++ optimization profiling valgrind gprof