gprof 是否考虑了阻塞时间?

发布于 2024-08-16 08:41:41 字数 63 浏览 3 评论 0原文

我在可执行文件上运行 gprof,但可执行文件花费大量时间等待子进程完成。 gprof 计时是否考虑了等待时间?

I am running gprof on my executable, but the executable spends a lot of time wait()ing for child processes to complete. Is the time spent waiting factored in to the gprof timings?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烂柯人 2024-08-23 08:41:41

我没有太多使用 gprof,但据我所知,wait 和每个看到的子进程都没有被分析。

看一个简单的例子:

#include <stdlib.h>
#include <unistd.h>
#include <limits.h>

void slow_function()
{
    unsigned int i;
    for (i = 0; i < UINT_MAX; i++);
}

void quick_function(pid_t child)
{
    int status;
    waitpid(child, &status, 0);
    return;
}

int main(int argc, const char *argv[])
{
    pid_t child;

    child = fork();
    if (child == 0) // child process
    {
        slow_function();
        exit(0);
    }
    else
        quick_function(child);

    return 0;
}

gprof 输出是(在我的机器上):

  %   cumulative   self              self     total
 time   seconds   seconds    calls  Ts/call  Ts/call  name
  0.00      0.00     0.00        1     0.00     0.00  quick_function

如果你真的想分析子线程/线程,我建议作为起点。

I haven't used gprof much, but to my knowledge, neither the wait nor the child processes per see are profiled.

See a simple example:

#include <stdlib.h>
#include <unistd.h>
#include <limits.h>

void slow_function()
{
    unsigned int i;
    for (i = 0; i < UINT_MAX; i++);
}

void quick_function(pid_t child)
{
    int status;
    waitpid(child, &status, 0);
    return;
}

int main(int argc, const char *argv[])
{
    pid_t child;

    child = fork();
    if (child == 0) // child process
    {
        slow_function();
        exit(0);
    }
    else
        quick_function(child);

    return 0;
}

The gprof output for this is (on my machine):

  %   cumulative   self              self     total
 time   seconds   seconds    calls  Ts/call  Ts/call  name
  0.00      0.00     0.00        1     0.00     0.00  quick_function

If you actually want to profile the childs/threads, I'd suggest this as a starting point.

捂风挽笑 2024-08-23 08:41:41

似乎有一个选项可以记录分叉进程, 这篇 ibm 文章对此进行了一些讨论。

同一篇文章建议尝试tprof,它在使用上与gprof类似,但在下使用不同的方法该引擎盖可以为多进程/多线程应用程序提供更准确的图像。

It seems there is an option to log fork'ed processes, this ibm article talks about it a bit.

The same article recommends trying tprof, it is similar to gprof in use, but uses different methods under the hood that might give a more accurate picture for multi-process/multi-thread applications.

冬天的雪花 2024-08-23 08:41:41

gprof 仅计算进程中的实际 CPU 时间。效果更好的是对调用堆栈进行采样,并在挂钟时间而不是CPU时间进行采样。当然,在等待用户输入时不应采集样本(或者如果采集了样本,则应将其丢弃)。一些分析器可以完成所有这些,例如 RotateRight/Zoom,或者您可以使用 pstacklsstack但这里有一个简单的方法

gprof only counts actual CPU time in your process. What works a lot better is something that samples the call stack, and samples it on wall-clock time, not CPU time. Of course, samples should not be taken while waiting for user input (or if they are taken, they should be discarded). Some profilers can do all this, such as RotateRight/Zoom, or you can use pstack or lsstack, but here's a simple way to do it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文