阻止进程时例如执行某些io,Perf或DTrace是否不采样?

问题描述

以下是在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时间,这给了我错误的热点。这是正确的行为还是我使用的方式错误?

enter image description here

在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 (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...