Unfortunately the project isn’t something I can share publicly. Time permitting, I’ll attempt to distill down the problem to a reproducer that I can share next week.
In my own investigations strace was showing the following:
1691715094.457605 brk(0xaaab24394000) = 0xaaab24394000
1691715094.458482 getcwd("/build/tests", 2048) = 40
1691715094.459825 getcwd("/build/tests", 2048) = 40
1691715094.461233 getcwd("/build/tests", 2048) = 40
1691715094.462487 getcwd("/build/tests", 2048) = 40
1691715094.463727 getcwd("/build/tests", 2048) = 40
1691715094.465161 getcwd("/build/tests", 2048) = 40
1691715094.466561 getcwd("/build/tests", 2048) = 40
1691715094.467920 getcwd("/build/tests", 2048) = 40
1691715094.469188 getcwd("/build/tests", 2048) = 40
1691715094.470469 getcwd("/build/tests", 2048) = 40
1691715094.471710 getcwd("/build/tests", 2048) = 40
1691715094.472847 getcwd("/build/tests", 2048) = 40
1691715094.473923 getcwd("/build/tests", 2048) = 40
1691715094.475036 getcwd("/build/tests", 2048) = 40
1691715094.476324 getcwd("/build/tests", 2048) = 40
1691715094.477500 getcwd("/build/tests", 2048) = 40
1691715094.478740 getcwd("/build/tests", 2048) = 40
1691715094.479808 getcwd("/build/tests", 2048) = 40
1691715094.481119 getcwd("/build/tests", 2048) = 40
1691715094.482300 getcwd("/build/tests", 2048) = 40
1691715094.483575 getcwd("/build/tests", 2048) = 40
1691715094.484866 getcwd("/build/tests", 2048) = 40
1691715094.485979 getcwd("/build/tests", 2048) = 40
1691715094.486945 getcwd("/build/tests", 2048) = 40
1691715094.488276 getcwd("/build/tests", 2048) = 40
1691715094.489700 getcwd("/build/tests", 2048) = 40
1691715094.491428 getcwd("/build/tests", 2048) = 40
1691715094.492700 getcwd("/build/tests", 2048) = 40
1691715094.494032 getcwd("/build/tests", 2048) = 40
1691715094.495363 getcwd("/build/tests", 2048) = 40
1691715094.496489 getcwd("/build/tests", 2048) = 40
1691715094.497553 getcwd("/build/tests", 2048) = 40
1691715094.498693 getcwd("/build/tests", 2048) = 40
1691715094.500015 getcwd("/build/tests", 2048) = 40
1691715094.501038 getcwd("/build/tests", 2048) = 40
1691715094.502138 getcwd("/build/tests", 2048) = 40
1691715094.503175 getcwd("/build/tests", 2048) = 40
1691715094.504512 getcwd("/build/tests", 2048) = 40
1691715094.505659 getcwd("/build/tests", 2048) = 40
1691715094.506913 getcwd("/build/tests", 2048) = 40
1691715094.508266 getcwd("/build/tests", 2048) = 40
1691715094.509388 getcwd("/build/tests", 2048) = 40
1691715094.510468 getcwd("/build/tests", 2048) = 40
1691715094.511718 getcwd("/build/tests", 2048) = 40
1691715094.513055 getcwd("/build/tests", 2048) = 40
1691715094.514330 getcwd("/build/tests", 2048) = 40
1691715094.515557 getcwd("/build/tests", 2048) = 40
1691715094.516772 getcwd("/build/tests", 2048) = 40
1691715094.518065 getcwd("/build/tests", 2048) = 40
1691715094.519086 getcwd("/build/tests", 2048) = 40
1691715094.520157 getcwd("/build/tests", 2048) = 40
1691715094.521249 getcwd("/build/tests", 2048) = 40
1691715094.522632 getcwd("/build/tests", 2048) = 40
1691715094.523897 getcwd("/build/tests", 2048) = 40
1691715094.525052 getcwd("/build/tests", 2048) = 40
1691715094.526113 getcwd("/build/tests", 2048) = 40
1691715094.527542 getcwd("/build/tests", 2048) = 40
1691715094.528679 getcwd("/build/tests", 2048) = 40
1691715094.529997 getcwd("/build/tests", 2048) = 40
1691715094.531269 getcwd("/build/tests", 2048) = 40
1691715094.532436 getcwd("/build/tests", 2048) = 40
1691715094.533592 getcwd("/build/tests", 2048) = 40
1691715094.534863 getcwd("/build/tests", 2048) = 40
1691715094.536135 brk(0xaaab243b5000) = 0xaaab243b5000
The stack for each getcwd looks something like this
2259767 > /usr/lib/aarch64-linux-gnu/libc.so.6(getcwd+0x80) [0xd86e0]
2259768 > /Users/pjohnson/git/sandbox/CMake-3.22.1/bin/ctest(_ZN5cmsys11SystemTools26GetCurrentWorkingDirectoryB5cxx11Ev+0x3c) [0x6bce8c]
2259769 > /Users/pjohnson/git/sandbox/CMake-3.22.1/bin/ctest(_ZN13cmSystemTools26GetCurrentWorkingDirectoryB5cxx11Ev+0x30) [0x2c5764]
2259770 > /Users/pjohnson/git/sandbox/CMake-3.22.1/bin/ctest(_ZN18cmCTestTestHandler7AddTestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS6_EE+0x3d0) [0x105710]
2259771 > /Users/pjohnson/git/sandbox/CMake-3.22.1/bin/ctest(_ZNSt17_Function_handlerIFbRKSt6vectorI18cmListFileArgumentSaIS1_EER17cmExecutionStatusEN12_GLOBAL__N_121cmCTestAddTestCommandEE9_M_invokeERKSt9_Any_dataS5_S7_+0x68) [0xf8968]
2259772 > /Users/pjohnson/git/sandbox/CMake-3.22.1/bin/ctest(_ZN10cmMakefile14ExecuteCommandERK18cmListFileFunctionR17cmExecutionStatusSt8optionalINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE+0x7a4) [0x260938]
2259773 > /Users/pjohnson/git/sandbox/CMake-3.22.1/bin/ctest(_ZN10cmMakefile11RunListFileERK10cmListFileRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPNS_13DeferCommandsE+0x354) [0x261038]
2259774 > /Users/pjohnson/git/sandbox/CMake-3.22.1/bin/ctest(_ZN10cmMakefile17ReadDependentFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb+0x264) [0x261ac4]
2259775 > /Users/pjohnson/git/sandbox/CMake-3.22.1/bin/ctest(_ZN12_GLOBAL__N_120cmCTestSubdirCommandERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS6_EER17cmExecutionStatus+0x134) [0xf8c74]
2259776 > /Users/pjohnson/git/sandbox/CMake-3.22.1/bin/ctest(_ZNSt17_Function_handlerIFbRKSt6vectorI18cmListFileArgumentSaIS1_EER17cmExecutionStatusEZN7cmState17AddBuiltinCommandERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPFbRKS0_ISF_SaISF_EES7_EEUlS5_S7_E_E9_M_invokeERKSt9_Any_dataS5_S7_+0x5c) [0x2aa61c]
2259777 > /Users/pjohnson/git/sandbox/CMake-3.22.1/bin/ctest(_ZN10cmMakefile14ExecuteCommandERK18cmListFileFunctionR17cmExecutionStatusSt8optionalINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE+0x7a4) [0x260938]
2259778 > /Users/pjohnson/git/sandbox/CMake-3.22.1/bin/ctest(_ZN10cmMakefile11RunListFileERK10cmListFileRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPNS_13DeferCommandsE+0x354) [0x261038]
2259779 > /Users/pjohnson/git/sandbox/CMake-3.22.1/bin/ctest(_ZN10cmMakefile12ReadListFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x2b8) [0x261e28]
2259780 > /Users/pjohnson/git/sandbox/CMake-3.22.1/bin/ctest(_ZN18cmCTestTestHandler14GetListOfTestsEv+0x4bc) [0x10b88c]
2259781 > /Users/pjohnson/git/sandbox/CMake-3.22.1/bin/ctest(_ZN18cmCTestTestHandler15ComputeTestListEv+0x6c) [0x10bcb0]
2259782 > /Users/pjohnson/git/sandbox/CMake-3.22.1/bin/ctest(_ZN18cmCTestTestHandler16ProcessDirectoryERSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS6_EES9_+0x34) [0x10c164]
2259783 > /Users/pjohnson/git/sandbox/CMake-3.22.1/bin/ctest(_ZN18cmCTestTestHandler14ProcessHandlerEv+0x1bc) [0x10ccbc]
2259784 > /Users/pjohnson/git/sandbox/CMake-3.22.1/bin/ctest(_ZN7cmCTest12ProcessStepsEv+0x5b0) [0x70be4]
2259785 > /Users/pjohnson/git/sandbox/CMake-3.22.1/bin/ctest(_ZN7cmCTest12ExecuteTestsEv+0x484) [0x716d4]
2259786 > /Users/pjohnson/git/sandbox/CMake-3.22.1/bin/ctest(main+0x280) [0x3ed90]
You can use c++filt to demangle the above symbols.
I don’t have the brk stack, but i believe it had something to do with std::string concatenation within ctest.
I don’t think necessarily getcwd is a bottleneck here, but it was the only narrowing down I was able to do in the time i had to investigate this.