Issue
This is NOT a duplicate of How to run Visual Studio CPU profiler on CMake project?, since in their case, their program spends 100% of the time in IDLE
, while mine gives me [External code]
. They also resolved their problem by running Visual Studio 2019 instead of 2022, while I am using Visual Studio 2019.
I'm trying to profile a CMake project with the Visual Studio Performance Profiler. My project is build with msvc_x64_x64
in RelWithDebugInfo
, and I followed MSVC docs to add the /profile
flag to CMake.
After running the CPU performance profiler, I get everything is running in [External Code]
, which is completely useless. I wonder if somehow the profiler cannot see the symbols of my project - but I compiled with RelWithDebugInfo
, so it should be able to. When I ran the profiler, I also selected "Startup Project" rather than a hard-coded path to a binary.
This is my CMakeSettings.json
if that's helpful.
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": ""
},
{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64_x64" ]
}
]
}
ninja -v
verbose output (with include flags removed for brevity):
[1/3] C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\cl.exe /nologo /TP -DLIBJPEG_STATIC -DLZMA_API_STATIC -DOPJ_STATIC ...[include flags]... /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MD /Zi /O2 /Ob1 /DNDEBUG -std:c++17 /showIncludes /Fooct-invivo-align\CMakeFiles\oct-invivo-align-test.dir\oct-invivo-align.cpp.obj /Fdoct-invivo-align\CMakeFiles\oct-invivo-align-test.dir\ /FS -c ..\..\oct-invivo-align\oct-invivo-align.cpp
[2/3] C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\cl.exe /nologo /TP -DLIBJPEG_STATIC -DLZMA_API_STATIC -DOPJ_STATIC ...[include flags]... /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MD /Zi /O2 /Ob1 /DNDEBUG -std:c++17 /showIncludes /Fooct-invivo-align\CMakeFiles\oct-invivo-align-test.dir\main.cpp.obj /Fdoct-invivo-align\CMakeFiles\oct-invivo-align-test.dir\ /FS -c ..\..\oct-invivo-align\main.cpp
[3/3] cmd.exe /C "cd . && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=oct-invivo-align\CMakeFiles\oct-invivo-align-test.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x64\mt.exe --manifests -- C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\oct-invivo-align-test.rsp /out:oct-invivo-align\oct-invivo-align-test.exe /implib:oct-invivo-align\oct-invivo-align-test.lib /pdb:oct-invivo-align\oct-invivo-align-test.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console && cd ."
Solution
It turns out all I had to do was to check the Show External Code
box in Filter
...
Answered By - kwsp Answer Checked By - Dawn Plyler (WPSolving Volunteer)