Visual Studio 2022性能分析无法解析函数名,提示Source information is not available
性能分析无法解析函数名问题排查
问题描述
在Visual Studio 2022 17.5.3中对Release x64版本程序做性能分析时,即使是简单测试程序也无法解析函数名,仅提示“Source information is not available”。已尝试以下操作但无效:
- 开启
/DEBUG编译选项 - 尝试所有调试信息格式
- .pdb文件与exe/dll同目录,且该目录已加入调试源文件列表
测试代码:
#include <iostream> using namespace std; int main() { float number = 1; for (int i = 1; i < 100000000; i++) { for (int i = 1; i < 100000000; i++) { number = number + number / i; } } printf("%lu ", number ); return 0; }
构建输出:
Build started... 1>------ Build started: Project: empty, Configuration: Release x64 ------ 1>main.cpp 1>Generating code 1>Previous IPDB not found, fall back to full compilation. 1>All 1 functions were compiled because no usable IPDB/IOBJ from previous compilation was found. 1>Finished generating code 1>empty.vcxproj -> C:\Users\abaghdad\Documents\Visual Studio 2022\Projects\empty\x64\Release\empty.exe ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ========== ========== Build started at 6:30 PM and took 00.753 seconds ==========
排查方案
1. 调整Release模式的调试信息生成策略
默认/DEBUG可能搭配/DEBUG:FASTLINK生成增量式pdb,信息不全。改为生成完整pdb:
- 右键项目 → 属性 → 配置属性 → 链接器 → 调试 → 生成调试信息,选择
/DEBUG:FULL
2. 限制编译器优化(关键)
Release模式默认/O2优化会把main函数完全内联或抹除函数边界,导致性能分析工具无法识别:
- 临时降低优化级别:项目属性 → 配置属性 → C/C++ → 优化 → 优化级别,改为
/O1或/Od(禁用优化) - 或针对特定函数禁用内联:给
main函数添加__declspec(noinline)标记,修改代码:
__declspec(noinline) int main() { // ... 原有代码 }
3. 确保性能探查器加载符号
- 打开性能探查器后,点击右上角“设置”图标 → 符号 → 勾选“启用符号加载”,并添加本地pdb所在目录到“符号搜索路径”
4. 重新生成匹配的exe和pdb
执行Clean Solution,再Rebuild Solution,确保exe和pdb是同一编译批次的产物,避免版本不匹配
内容的提问来源于stack exchange,提问作者Nidal Barada
相关产品推荐
相关产品推荐

