You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:Linux perf无法正确记录libstdc++.so中的函数调用

Perf分析C程序时无法显示libstdc随机函数调用链路的问题

程序代码

std::string generateRandomString() {
    // Initialize a random number generator
    std::random_device rd;
    std::mt19937 gen(rd());

    // Define a distribution for the length of the string (1 to 6)
    std::uniform_int_distribution<> lenDistribution(1, 6);
    int length = lenDistribution(gen);

    // Define characters that can be part of the string
    const std::string characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

    // Generate the random string
    std::uniform_int_distribution<> charDistribution(0, characters.size() - 1);
    std::string result;
    result.reserve(length);

    for (int i = 0; i < length; ++i) {
        result += characters[charDistribution(gen)];
    }
    return result;
}


void test_trie(){
    for (...) generateRandomString();
}

void test(){
    // do something
}

int main(){
    test_trie();
    test();
}

操作步骤

  • 使用命令g++ -g -O2 main.cpp -o secmaster_test编译程序(也尝试过-O0优化等级);
  • 执行perf record -F 999 -g -- ./secmaster_test进行性能数据采集;
  • 生成火焰图后,结果不符合预期,无法正确显示libstdc++.so中随机相关函数的调用链路。

预期火焰图结构

| --- some random -----|
                  | ...something...        | generateRandomString | -- --|
                  | ----------test-------- | --------------test_trie-----|
                  | ---------------------main----------------------------|
|--startup code-- | -------------------secmaster_test------------------- | -- cleanup -- |

目前perf无法识别main()中调用的随机相关函数,已尝试以下两种方式但均未解决:

  • 使用perf record --call-graph dwarf;
  • 使用perf record --call-graph fp;

特此求助。

内容的提问来源于stack exchange,提问作者54138qqqq

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 17:27:39