使用DTrace在调用堆栈树中检测冗余函数调用 [英] Detecting redundant function calls within call stack tree with DTrace

查看:126
本文介绍了使用DTrace在调用堆栈树中检测冗余函数调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个相当复杂的算法中,我很难追踪不必要的冗余呼叫.

I'm having a hard time tracking down unnecessary redundant calls within a rather complex algorithm.

我的算法(某些)似乎因非缓存且相对昂贵的函数的冗余调用(在多个子例程中)而严重减慢了速度. 为了确认这一点,我想利用Dtrace检测调用堆栈树的给定分支内单个函数的多个调用.

It looks like (some of my) my algorithm(s) is/are seriously slowed down by redundant calls (in several subroutines) of a non-cached and comparatively expensive function. To confirm this I'd like to utilize Dtrace to detect multiple calls of a single function within a given branch of the call stack tree.

我想问一下dtrace:

I'd like to be able to ask dtrace to:

  • 在给定函数(此处为"foo();",请参见附件)内的调用堆栈树中搜索重复的函数调用(例如,"c();")

  • search the call stack tree within a given function (here "foo();", see attached image) for duplicate function calls ("c();", e.g.)

使用各自的通话计数记录它们(此处:"c();"的3倍)

log them with their respective call count (here: 3x for "c();")

,如果可能的话,

  • 记录每次出现的调用堆栈("foo()/a()/c()""foo()/a()/b()/c()""foo()/a()/b()/d()/c()").
  • log the call stacks of each occurrence ("foo()/a()/c()", "foo()/a()/b()/c()", "foo()/a()/b()/d()/c()").

这可能吗?如果是的话,知道怎么做吗?

Is this possible? And if yes, any idea how?

提前谢谢!

注意:尽管我的代码实际上是在Objective-C中,但我仍在示例代码中使用了C,但是这种事情应该与语言无关,不是吗?至少是一般方法/想法.

Note: I used C in my sample code even though my code is actually in Objective-C, but this kind of thing should be kind of language-agnostic, shouldn't it? The general approach/idea at least.

推荐答案

我使用的方法是此示例. 您想看到的想法是堆栈跟踪由它们负责的挂钟时间加权.优先显示占用大量时间的功能调用站点.

The method I use is random-pausing, as in this example. The idea is what you want to see is stack traces weighted by the wall-clock time they are responsible for. Function call sites responsible for significant time are preferentially displayed.

然后,您只需查看这些内容即可.堆栈跟踪告诉您为什么执行它们. 由此,您可以判断是否有没有它们的方法. 如果这样做,则节省的时间与它们在堆栈中的时间分数相同.

Then you just look at those. The stack traces tell you why they are being executed. From that you can tell if there is a way to do without them. If you do so, the time you save is the same as the fraction of time they were on the stack.

注意:如果执行此操作,则无需关心从该站点(或任何位置)调用该函数的次数,或执行所需的时间. 您需要关心的是,调用站点至少在两个样本上处于堆栈中,并且可以将其删除.

Note: If you do this, you don't need to care how many times the function was called from that site (or anywhere), or how long it takes to execute. All you need to care about is that the call site was on the stack on at least two samples, and that it can be removed.

这篇关于使用DTrace在调用堆栈树中检测冗余函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆