gpt4 book ai didi

profile - 'Samples' 在性能输出中是什么意思?

转载 作者:行者123 更新时间:2023-12-01 06:38:23 26 4
gpt4 key购买 nike

我使用 linux perf 来分析我的程序,但我无法理解结果。

10.5% 2 乐趣 .....................
|
|- 80% - ABC
| call_ABC
-- 20% - 防御
调用_DEF

上面的例子意味着 'fun' 有两个样本并且贡献了 10.5% 的开销,

其中80%来自ABC,20%来自DEF。我对吗?

现在我们只有两个样本,那么'perf'如何计算ABC和DEF的分数?

为什么不是 50%?剂量'perf'使用附加信息?

最佳答案

The above example means that 'fun' has two samples and contributes 10.5% overheads,



是的,这部分 perf report -g -n显示 19 个样本中的 2 个(2 个是 19 个的 10.5%)在 foo 函数本身中。在另一个函数中对其他 17 个样本进行了采样。

我刚刚用最近的 gcc( -static -O3 -fno-inline -fno-omit-frame-pointer -g )和性能( perf record -e cycles:u -c 500000 -g ./test12968422 用于低分辨率样本或 -c 5000 用于高分辨率)复制了您的代码。现在 perf 有一些不同的权重规则,但想法应该是一样的。当程序只有 2 个样本并且都在 foo 中时, call-graph ( perf report -n -g callee ) 对于每个 call_DEF/_ABC 都是 50(没有附加信息)。这个程序实际上有 86% 的运行时在 foo 中,其中 61% 从 ABC 调用时占 86%,从 DEF 调用时占 86%:
100%  2  fun
- fun
+ 50% call_DEF
+ 50% call_ABC

perf 可以使用哪些附加信息来重建更多信息?我认为它可以是 call_DEF 和 call_ABC 的自重;或者它可以是所有示例调用堆栈中调用链的“call_ABC->foo”和“call_DEF->foo”部分的频率。

使用 linux 内核版本 4.4/4.10 的性能,我无法重现您的情况。我在 call_ABC 和 call_DEF 中添加了不同数量的自我工作。他们都只是调用 foo 来完成固定的工作量。现在我有 19 个样本 -e cycles:u -c 54000 -g , call_ABC 为 13,call_DEF 为 2,fun 为 2(在某些随机函数中为 2):
  Children  Self  Samples Symbol
74% 68% 13 [.] call_ABC
16% 10.5% 2 [.] call_DEF
10.5% 10.5% 2 [.] fun
- fun
+ 5.26% call_ABC
+ 5.26% call_DEF

因此,请尝试更新版本的 perf,而不是来自 3.2 Linux 内核的时代。

第一来源 fun当从 ABC 和 DEF 调用时,只能工作,不平等的份额:
#define g 100000
int a[2+g];

void fill_a(){
a[0]=0;
for(int f=0;f<g;f++)
a[f+1]=f;
}

int fun(int b)
{
while(a[b])
b=a[b];
return b;
}

int call_ABC(int b)
{
int d = b;
b = fun(d);
return d-b;
}

int call_DEF(int b)
{
int e = b;
b = fun(e);
return e+b;
}

int main()
{
int c,d;
fill_a();
c=call_ABC(100000);
c=call_DEF(45000);
return c+d;
}

ABC 和 DEF 中工作不平等的第二个来源,但在乐趣中做同样的小工作:
#define g 100000
int a[2+g];

void fill_a(){
a[0]=0;
for(int f=0;f<g;f++)
a[f+1]=f;
}

int fun(int b)
{
while(a[b])
b=a[b];
return b;
}

int call_ABC(int b)
{
int d = b;
while(a[d])
d=a[d];
b = fun(5000);
return d-b;
}

int call_DEF(int b)
{
int e = b;
while(a[e])
e=a[e];
b = fun(5000);
return e+b;
}

int main()
{
int c,d;
fill_a();
c=call_ABC(100000);
c=call_DEF(20000);
return c+d;
}

关于profile - 'Samples' 在性能输出中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12968422/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com