首页 > 解决方案 > 不必要的 strerror_l 调用

问题描述

#include <iostream>
int main(){
    for(int i = 0; i < 100000000; i++){
        std::string from = "hello";
    }
    return 0;
}

此代码在 std::string 构造函数内产生一些 strerror_l 调用。它是示例代码,在实际项目中调用了更多次(使用 google pprof 进行分析)。它是什么,我怎样才能避免这些电话?

测试环境:

debian 6.0.1, g++ 4.4.5 and g++ 4.9.2- 没有 strerror_l 调用

debian 8.6, g++ 4.9.2- 几个电话

重现方式(需要google pprof):

使用探查器构建: g++ question.cpp -lprofiler

获取个人资料数据:CPUPROFILE=/tmp/question.out /tmp/a.out

构建调用图:google-pprof --pdf /tmp/a.out question.out > output.pdf

标签: c++profiling

解决方案


推荐阅读