From 67add75ad7261c1b7840860075f56d5eec217b72 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 25 Sep 2025 17:06:55 -0400 Subject: [PATCH] instrumentation: Load queries for postBuild hook after build is done We launch a `ctest --wait-and-collect-instrumentation` daemon at the beginning of a build to implement the `postBuild` hook. It waits for the build tool to terminate and then collects instrumentation data. If the build re-runs `cmake`, the instrumentation `query/generated` directory may be regenerated. Previously the daemon loaded the queries up front, but that races with regeneration during the build. Delay loading queries until after the build finishes. This was exposed by intermittent test failures since commit a249e820a8 (instrumentation: Add file lock for build daemon, 2025-08-05), which added build-time regeneration of the build system to an instrumentation test case. --- Source/cmInstrumentation.cxx | 2 +- Source/ctest.cxx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/cmInstrumentation.cxx b/Source/cmInstrumentation.cxx index 48d8ffb7a0..10e43e757e 100644 --- a/Source/cmInstrumentation.cxx +++ b/Source/cmInstrumentation.cxx @@ -790,7 +790,7 @@ int cmInstrumentation::CollectTimingAfterBuild(int ppid) }; int ret = this->InstrumentCommand( "build", {}, [waitForBuild]() { return waitForBuild(); }, cm::nullopt, - cm::nullopt, LoadQueriesAfter::No); + cm::nullopt, LoadQueriesAfter::Yes); this->CollectTimingData(cmInstrumentationQuery::Hook::PostBuild); return ret; } diff --git a/Source/ctest.cxx b/Source/ctest.cxx index e44d6b6032..fbfd97899f 100644 --- a/Source/ctest.cxx +++ b/Source/ctest.cxx @@ -194,8 +194,8 @@ int main(int argc, char const* const* argv) // Dispatch 'ctest --collect-instrumentation' once given PID finishes if (argc == 4 && strcmp(argv[1], "--wait-and-collect-instrumentation") == 0) { - return cmInstrumentation(argv[2]).CollectTimingAfterBuild( - std::stoi(argv[3])); + return cmInstrumentation(argv[2], cmInstrumentation::LoadQueriesAfter::No) + .CollectTimingAfterBuild(std::stoi(argv[3])); } // Dispatch 'ctest --collect-instrumentation' mode directly.