首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Kcachegrind/callgrind对于调度程序函数是不准确的?

Kcachegrind/callgrind对于调度程序函数是不准确的?
EN

Stack Overflow用户
提问于 2011-09-21 00:54:07
回答 1查看 1.3K关注 0票数 4

我有一个模型代码,kcachegrind/callgrind会报告奇怪的结果。它是一种调度函数。dispatcher是从4个地方调用的;每个调用都说明要运行哪个实际的do_J函数(因此first2将只调用do_1do_2,依此类推)

源代码(这是实际代码的模型)

代码语言:javascript
复制
#define N 1000000

int a[N];
int do_1(int *a) { int i; for(i=0;i<N/4;i++) a[i]+=1; }
int do_2(int *a) { int i; for(i=0;i<N/2;i++) a[i]+=2; }
int do_3(int *a) { int i; for(i=0;i<N*3/4;i++) a[i]+=3; }
int do_4(int *a) { int i; for(i=0;i<N;i++) a[i]+=4; }

int dispatcher(int *a, int j) {
    if(j==1) do_1(a);
    else if(j==2) do_2(a);
    else if(j==3) do_3(a);
    else do_4(a);
}

int first2(int *a) { dispatcher(a,1); dispatcher(a,2); }
int last2(int *a) { dispatcher(a,4); dispatcher(a,3); }
int inner2(int *a) { dispatcher(a,2); dispatcher(a,3); }
int outer2(int *a) { dispatcher(a,1); dispatcher(a,4); }

int main(){
    first2(a);
    last2(a);
    inner2(a);
    outer2(a);
}

gcc -O0编译;用valgrind --tool=callgrind调用;用kcachegrindqcachegrind-0.7调用。

下面是该应用程序的完整调用图。所有到do_J的路径都通过dispatcher,这很好( do_1只是因为太快而被隐藏起来,但它确实在这里,只是留给do_2)

让我们关注do_1并检查谁调用了它(这张图片是不正确的):

这非常奇怪,我认为,只有first2outer2调用了do_1,但不是全部。

这是callgrind/kcachegrind的限制吗?我怎样才能得到准确的带权重的调用图(与每个函数的运行时间成正比,有没有它的孩子)?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-10-30 17:52:21

是的,这是callgrind格式的限制。它不存储完整的跟踪;它只存储父子调用信息。

有一个google-perftools项目,其中包含pprof/libprofiler.so CPU profiler,http://google-perftools.googlecode.com/svn/trunk/doc/cpuprofile.htmllibprofiler.so可以获取带有调用跟踪的配置文件,并且它将以完整的回溯存储每个跟踪事件。pprof是libprofile输出到图形格式或callgrind格式的转换器。在完整视图中,结果将与kcachegrind中的结果相同;但如果您将重点放在某些函数上,例如使用pprof的选项焦点的do_1;当您将焦点放在函数上时,它将显示准确的调用树。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7488793

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档