问题描述
以下是在macOS 10.15.4上使用https://www.jetbrains.com/help/clion/cpu-profiler.html使用clion进行概要分析的示例,我发现它仅输出部分调用堆栈。
#include <iostream>
#include <thread>
#include <cmath>
void g() {
std::this_thread::sleep_for(std::chrono::seconds(1));
}
float l2sqr(float* x,float* y,size_t N) {
float ret = 0;
for (size_t i = 0; i<N;i++) {
ret += (x[i]-y[i])*(x[i]-y[i]);
}
return std::sqrt(ret);
}
int main() {
float x[512];
float y[512];
std::fill_n(x,512,0.1);
std::fill_n(y,0.2);
float s = 0.0;
for (int i = 0; i < 5; ++i) {
for (int j = 0; j < 10000; ++j) {
s += l2sqr(x,y,512);
}
g();
std::cout << s << std::endl;
}
}
,这是结果,它没有给出函数g的任何样本。在实际情况下,没有报告大量的db io时间,这给了我错误的热点。这是正确的行为还是我使用的方式错误?
在Ubuntu 16.04中使用perf:
g++ test.cpp && sudo perf record -F 999 -g ./a.out && sudo perf report
我得到类似的结果:
- main
+ 99.67% l2sqr
0.08% std::sqrt
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)