gprof中计算的时间是否包括未分析的函数所花费的时间? [英] Would the time counted in gprof include what is spent in functions that are not profiled?

查看:119
本文介绍了gprof中计算的时间是否包括未分析的函数所花费的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有一个要对其进行概要分析的项目,但是它使用了另一个我无法控制的库.如果有这样的功能,请说:

I now have a project which I want do profiling on, but it used another library which I have no control of. Say if there if such a function:

#include <library.h>
void function(...)
{
    // do something
    for (...)
    {
        // ...
        library_function(...);
        // ...
    }
    // do something
}

让我们假设library_function来自另一个静态库,该静态库未在启用概要分析的情况下进行编译.现在,如果gprof告诉我,运行function花费了10秒(包括其所有子项),这是否包括在library_function中花费的时间?

Let's assume that library_function is from another static library which is not compiled with profiling enabled. Now if gprof tells me running function took 10s including all its children, will this include the time spent in library_function?

推荐答案

否,因为gprof的工作方式,它将对程序计数器进行采样,找出程序计数器所处的功能,并为此增加自耗时间功能.

No, because the way gprof works, it samples the program counter, figures out which function the program counter is in, and increments the self time for that function.

此外,它计算任何函数A调用任何函数B的次数.

In addition, it counts the number of times any function A calls any function B.

从那开始,它试图找出其他所有内容.

From that, it tries to figure everything else out.

当然,这仅适用于它所了解的功能.

Of course, this only works for functions it knows about.

这非常聪明,但是 您可以做得更好 .

It's very clever, but you can do better.

已添加:由于某人明智地决定删除上述帖子,因此以下是您如何做得更好的简短摘要:

ADDED: since somebody in their wisdom decided to delete the above post, here is a brief summary of how you can do better:

尝试一下./a>
这是加速44倍的示例.
这里的速度是730倍.
这里是统计信息的说明.
这是对批判的答案.
这是一个8分钟的视频演示.

Try this instead.
Here's an example of a 44x speedup.
Here's a 730x speedup.
Here's an explanation of the statistics.
Here's an answer to critiques.
Here's an 8-minute video demonstration.

这篇关于gprof中计算的时间是否包括未分析的函数所花费的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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