instrumentation: Add Config value to snippet data

This commit is contained in:
Martin Duffy
2025-02-06 12:16:24 -05:00
committed by Brad King
parent ee3a55fc48
commit 9689155a05
17 changed files with 65 additions and 9 deletions
+6 -1
View File
@@ -263,6 +263,10 @@ and contain the following data:
``testName`` ``testName``
The name of the test being executed. Only included when ``role`` is ``test``. The name of the test being executed. Only included when ``role`` is ``test``.
``config``
The type of build, such as ``Release`` or ``Debug``. Only included when
``role`` is ``compile``, ``link`` or ``test``.
``dynamicSystemInformation`` ``dynamicSystemInformation``
Specifies the dynamic information collected about the host machine Specifies the dynamic information collected about the host machine
CMake is being run from. Data is collected for every snippet file CMake is being run from. Data is collected for every snippet file
@@ -294,7 +298,8 @@ Example:
"language" : "C++", "language" : "C++",
"outputs" : [ "CMakeFiles/main.dir/main.cxx.o" ], "outputs" : [ "CMakeFiles/main.dir/main.cxx.o" ],
"outputSizes" : [ 0 ], "outputSizes" : [ 0 ],
"source" : "<src>/main.cxx" "source" : "<src>/main.cxx",
"config" : "Debug",
"dynamicSystemInformation" : "dynamicSystemInformation" :
{ {
"afterCPULoadAverage" : 2.3500000000000001, "afterCPULoadAverage" : 2.3500000000000001,
+8 -1
View File
@@ -70,7 +70,8 @@ bool cmCTestLaunch::ParseArguments(int argc, char const* const* argv)
DoingBuildDir, DoingBuildDir,
DoingCurrentBuildDir, DoingCurrentBuildDir,
DoingCount, DoingCount,
DoingFilterPrefix DoingFilterPrefix,
DoingConfig
}; };
Doing doing = DoingNone; Doing doing = DoingNone;
int arg0 = 0; int arg0 = 0;
@@ -100,6 +101,8 @@ bool cmCTestLaunch::ParseArguments(int argc, char const* const* argv)
doing = DoingCurrentBuildDir; doing = DoingCurrentBuildDir;
} else if (strcmp(arg, "--filter-prefix") == 0) { } else if (strcmp(arg, "--filter-prefix") == 0) {
doing = DoingFilterPrefix; doing = DoingFilterPrefix;
} else if (strcmp(arg, "--config") == 0) {
doing = DoingConfig;
} else if (doing == DoingOutput) { } else if (doing == DoingOutput) {
this->Reporter.OptionOutput = arg; this->Reporter.OptionOutput = arg;
doing = DoingNone; doing = DoingNone;
@@ -136,6 +139,9 @@ bool cmCTestLaunch::ParseArguments(int argc, char const* const* argv)
} else if (doing == DoingRole) { } else if (doing == DoingRole) {
this->Reporter.OptionRole = arg; this->Reporter.OptionRole = arg;
doing = DoingNone; doing = DoingNone;
} else if (doing == DoingConfig) {
this->Reporter.OptionConfig = arg;
doing = DoingNone;
} }
} }
@@ -267,6 +273,7 @@ int cmCTestLaunch::Run()
options["language"] = this->Reporter.OptionLanguage; options["language"] = this->Reporter.OptionLanguage;
options["targetType"] = this->Reporter.OptionTargetType; options["targetType"] = this->Reporter.OptionTargetType;
options["role"] = this->Reporter.OptionRole; options["role"] = this->Reporter.OptionRole;
options["config"] = this->Reporter.OptionConfig;
std::map<std::string, std::string> arrayOptions; std::map<std::string, std::string> arrayOptions;
arrayOptions["outputs"] = this->Reporter.OptionOutput; arrayOptions["outputs"] = this->Reporter.OptionOutput;
arrayOptions["targetLabels"] = this->Reporter.OptionTargetLabels; arrayOptions["targetLabels"] = this->Reporter.OptionTargetLabels;
+1
View File
@@ -42,6 +42,7 @@ public:
std::string OptionFilterPrefix; std::string OptionFilterPrefix;
std::string OptionCommandType; std::string OptionCommandType;
std::string OptionRole; std::string OptionRole;
std::string OptionConfig;
// The real command line appearing after launcher arguments. // The real command line appearing after launcher arguments.
std::string CWD; std::string CWD;
+2 -1
View File
@@ -1020,7 +1020,8 @@ void cmCTestRunTest::FinalizeTest(bool started)
this->Instrumentation.InstrumentTest( this->Instrumentation.InstrumentTest(
this->TestProperties->Name, this->ActualCommand, this->Arguments, this->TestProperties->Name, this->ActualCommand, this->Arguments,
this->TestProcess->GetExitValue(), this->TestProcess->GetStartTime(), this->TestProcess->GetExitValue(), this->TestProcess->GetStartTime(),
this->TestProcess->GetSystemStartTime()); this->TestProcess->GetSystemStartTime(),
this->GetCTest()->GetConfigType());
} }
this->MultiTestHandler.FinishTestProcess(this->TestProcess->GetRunner(), this->MultiTestHandler.FinishTestProcess(this->TestProcess->GetRunner(),
started); started);
+9 -1
View File
@@ -312,7 +312,7 @@ int cmInstrumentation::InstrumentTest(
std::string const& name, std::string const& command, std::string const& name, std::string const& command,
std::vector<std::string> const& args, int64_t result, std::vector<std::string> const& args, int64_t result,
std::chrono::steady_clock::time_point steadyStart, std::chrono::steady_clock::time_point steadyStart,
std::chrono::system_clock::time_point systemStart) std::chrono::system_clock::time_point systemStart, std::string config)
{ {
// Store command info // Store command info
Json::Value root(this->preTestStats); Json::Value root(this->preTestStats);
@@ -323,6 +323,7 @@ int cmInstrumentation::InstrumentTest(
root["testName"] = name; root["testName"] = name;
root["binaryDir"] = this->binaryDir; root["binaryDir"] = this->binaryDir;
root["result"] = static_cast<Json::Value::Int64>(result); root["result"] = static_cast<Json::Value::Int64>(result);
root["config"] = config;
// Post-Command // Post-Command
this->InsertTimingData(root, steadyStart, systemStart); this->InsertTimingData(root, steadyStart, systemStart);
@@ -417,6 +418,13 @@ int cmInstrumentation::InstrumentCommand(
} }
} }
} }
// Create empty config entry if config not found
if (!root.isMember("config") &&
(command_type == "compile" || command_type == "link")) {
root["config"] = "";
}
if (arrayOptions.has_value()) { if (arrayOptions.has_value()) {
for (auto const& item : arrayOptions.value()) { for (auto const& item : arrayOptions.value()) {
if (item.first == "targetLabels" && command_type != "link") { if (item.first == "targetLabels" && command_type != "link") {
+2 -1
View File
@@ -32,7 +32,8 @@ public:
int InstrumentTest(std::string const& name, std::string const& command, int InstrumentTest(std::string const& name, std::string const& command,
std::vector<std::string> const& args, int64_t result, std::vector<std::string> const& args, int64_t result,
std::chrono::steady_clock::time_point steadyStart, std::chrono::steady_clock::time_point steadyStart,
std::chrono::system_clock::time_point systemStart); std::chrono::system_clock::time_point systemStart,
std::string config);
void GetPreTestStats(); void GetPreTestStats();
void LoadQueries(); void LoadQueries();
bool HasQuery() const; bool HasQuery() const;
@@ -554,6 +554,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
cmOutputConverter::SHELL, useWatcomQuote); cmOutputConverter::SHELL, useWatcomQuote);
vars.Target = target.c_str(); vars.Target = target.c_str();
vars.TargetPDB = targetOutPathPDB.c_str(); vars.TargetPDB = targetOutPathPDB.c_str();
vars.Config = this->GetConfigName().c_str();
// Setup the target version. // Setup the target version.
std::string targetVersionMajor; std::string targetVersionMajor;
+1 -1
View File
@@ -809,8 +809,8 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
vars.TargetSOName = targetOutSOName.c_str(); vars.TargetSOName = targetOutSOName.c_str();
} }
vars.LinkFlags = linkFlags.c_str(); vars.LinkFlags = linkFlags.c_str();
vars.Manifests = manifests.c_str(); vars.Manifests = manifests.c_str();
vars.Config = this->GetConfigName().c_str();
// Compute the directory portion of the install_name setting. // Compute the directory portion of the install_name setting.
std::string install_name_dir; std::string install_name_dir;
+2
View File
@@ -952,6 +952,7 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
vars.ObjectFileDir = objectFileDir.c_str(); vars.ObjectFileDir = objectFileDir.c_str();
vars.Flags = flags.c_str(); vars.Flags = flags.c_str();
vars.ISPCHeader = ispcHeaderForShell.c_str(); vars.ISPCHeader = ispcHeaderForShell.c_str();
vars.Config = this->GetConfigName().c_str();
std::string definesString = cmStrCat("$(", lang, "_DEFINES)"); std::string definesString = cmStrCat("$(", lang, "_DEFINES)");
@@ -1700,6 +1701,7 @@ void cmMakefileTargetGenerator::WriteDeviceLinkRule(
vars.Object = output.c_str(); vars.Object = output.c_str();
vars.Fatbinary = fatbinaryOutput.c_str(); vars.Fatbinary = fatbinaryOutput.c_str();
vars.RegisterFile = registerFile.c_str(); vars.RegisterFile = registerFile.c_str();
vars.Config = this->GetConfigName().c_str();
std::string linkFlags; std::string linkFlags;
this->GetDeviceLinkFlags(linkFlags, "CUDA"); this->GetDeviceLinkFlags(linkFlags, "CUDA");
+4
View File
@@ -342,6 +342,7 @@ void cmNinjaNormalTargetGenerator::WriteNvidiaDeviceLinkRule(
vars.Flags = "$FLAGS"; vars.Flags = "$FLAGS";
vars.LinkFlags = "$LINK_FLAGS"; vars.LinkFlags = "$LINK_FLAGS";
vars.Manifests = "$MANIFESTS"; vars.Manifests = "$MANIFESTS";
vars.Config = "$CONFIG";
vars.LanguageCompileFlags = "$LANGUAGE_COMPILE_FLAGS"; vars.LanguageCompileFlags = "$LANGUAGE_COMPILE_FLAGS";
@@ -416,6 +417,7 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkRules(
std::string flags = this->GetFlags("CUDA", config); std::string flags = this->GetFlags("CUDA", config);
vars.Flags = flags.c_str(); vars.Flags = flags.c_str();
vars.Config = "$CONFIG";
std::string compileCmd = this->GetMakefile()->GetRequiredDefinition( std::string compileCmd = this->GetMakefile()->GetRequiredDefinition(
"CMAKE_CUDA_DEVICE_LINK_COMPILE"); "CMAKE_CUDA_DEVICE_LINK_COMPILE");
@@ -557,6 +559,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile,
vars.Flags = "$FLAGS"; vars.Flags = "$FLAGS";
vars.LinkFlags = "$LINK_FLAGS"; vars.LinkFlags = "$LINK_FLAGS";
vars.Manifests = "$MANIFESTS"; vars.Manifests = "$MANIFESTS";
vars.Config = "$CONFIG";
std::string langFlags; std::string langFlags;
if (targetType != cmStateEnums::EXECUTABLE) { if (targetType != cmStateEnums::EXECUTABLE) {
@@ -1313,6 +1316,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement(
vars["AIX_EXPORTS"] = this->GetAIXExports(config); vars["AIX_EXPORTS"] = this->GetAIXExports(config);
vars["LINK_PATH"] = frameworkPath + linkPath; vars["LINK_PATH"] = frameworkPath + linkPath;
vars["CONFIG"] = config;
// Compute architecture specific link flags. Yes, these go into a different // Compute architecture specific link flags. Yes, these go into a different
// variable for executables, probably due to a mistake made when duplicating // variable for executables, probably due to a mistake made when duplicating
+5
View File
@@ -630,6 +630,7 @@ cmNinjaRule GetScanRule(
scanVars.DynDepFile = "$DYNDEP_INTERMEDIATE_FILE"; scanVars.DynDepFile = "$DYNDEP_INTERMEDIATE_FILE";
scanVars.DependencyFile = rule.DepFile.c_str(); scanVars.DependencyFile = rule.DepFile.c_str();
scanVars.DependencyTarget = "$out"; scanVars.DependencyTarget = "$out";
scanVars.Config = vars.Config;
// Scanning needs the same preprocessor settings as direct compilation would. // Scanning needs the same preprocessor settings as direct compilation would.
scanVars.Source = vars.Source; scanVars.Source = vars.Source;
@@ -695,6 +696,7 @@ void cmNinjaTargetGenerator::WriteCompileRule(std::string const& lang,
vars.ObjectFileDir = "$OBJECT_FILE_DIR"; vars.ObjectFileDir = "$OBJECT_FILE_DIR";
vars.CudaCompileMode = "$CUDA_COMPILE_MODE"; vars.CudaCompileMode = "$CUDA_COMPILE_MODE";
vars.ISPCHeader = "$ISPC_HEADER_FILE"; vars.ISPCHeader = "$ISPC_HEADER_FILE";
vars.Config = "$CONFIG";
cmMakefile* mf = this->GetMakefile(); cmMakefile* mf = this->GetMakefile();
@@ -1440,6 +1442,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
this->ComputeFlagsForObject(source, language, config, objectFileName); this->ComputeFlagsForObject(source, language, config, objectFileName);
vars["DEFINES"] = this->ComputeDefines(source, language, config); vars["DEFINES"] = this->ComputeDefines(source, language, config);
vars["INCLUDES"] = this->ComputeIncludes(source, language, config); vars["INCLUDES"] = this->ComputeIncludes(source, language, config);
vars["CONFIG"] = config;
auto compilerLauncher = this->GetCompilerLauncher(language, config); auto compilerLauncher = this->GetCompilerLauncher(language, config);
@@ -1793,6 +1796,7 @@ void cmNinjaTargetGenerator::WriteCxxModuleBmiBuildStatement(
this->ComputeFlagsForObject(source, language, config, bmiFileName); this->ComputeFlagsForObject(source, language, config, bmiFileName);
vars["DEFINES"] = this->ComputeDefines(source, language, config); vars["DEFINES"] = this->ComputeDefines(source, language, config);
vars["INCLUDES"] = this->ComputeIncludes(source, language, config); vars["INCLUDES"] = this->ComputeIncludes(source, language, config);
vars["CONFIG"] = config;
if (this->GetMakefile()->GetSafeDefinition( if (this->GetMakefile()->GetSafeDefinition(
cmStrCat("CMAKE_", language, "_DEPFILE_FORMAT")) != "msvc"_s) { cmStrCat("CMAKE_", language, "_DEPFILE_FORMAT")) != "msvc"_s) {
@@ -2035,6 +2039,7 @@ void cmNinjaTargetGenerator::WriteSwiftObjectBuildStatement(
this->GetFlags(language, config)); this->GetFlags(language, config));
vars["DEFINES"] = this->GetDefines(language, config); vars["DEFINES"] = this->GetDefines(language, config);
vars["INCLUDES"] = this->GetIncludes(language, config); vars["INCLUDES"] = this->GetIncludes(language, config);
vars["CONFIG"] = config;
// target-level object filename // target-level object filename
std::string const targetObjectFilename = this->ConvertToNinjaPath(cmStrCat( std::string const targetObjectFilename = this->ConvertToNinjaPath(cmStrCat(
+6
View File
@@ -283,6 +283,12 @@ std::string cmRulePlaceholderExpander::ExpandVariable(
} }
return ""; return "";
} }
if (variable == "CONFIG") {
if (this->ReplaceValues->Config) {
return this->ReplaceValues->Config;
}
return "";
}
auto compIt = this->Compilers.find(variable); auto compIt = this->Compilers.find(variable);
+1
View File
@@ -75,6 +75,7 @@ public:
char const* RegisterFile = nullptr; char const* RegisterFile = nullptr;
char const* Launcher = nullptr; char const* Launcher = nullptr;
char const* Role = nullptr; char const* Role = nullptr;
char const* Config = nullptr;
}; };
// Expand rule variables in CMake of the type found in language rules // Expand rule variables in CMake of the type found in language rules
+2 -2
View File
@@ -2690,13 +2690,13 @@ int cmake::ActualConfigure()
this->State->SetGlobalProperty( this->State->SetGlobalProperty(
"RULE_LAUNCH_COMPILE", "RULE_LAUNCH_COMPILE",
cmStrCat( cmStrCat(
launcher, "--command-type compile", common_args, launcher, "--command-type compile", common_args, "--config <CONFIG> ",
"--output <OBJECT> --source <SOURCE> --language <LANGUAGE> -- ")); "--output <OBJECT> --source <SOURCE> --language <LANGUAGE> -- "));
this->State->SetGlobalProperty( this->State->SetGlobalProperty(
"RULE_LAUNCH_LINK", "RULE_LAUNCH_LINK",
cmStrCat( cmStrCat(
launcher, "--command-type link", common_args, launcher, "--command-type link", common_args,
"--output <TARGET> --target-type <TARGET_TYPE> ", "--output <TARGET> --target-type <TARGET_TYPE> --config <CONFIG> ",
"--language <LANGUAGE> --target-labels \"<TARGET_LABELS>\" -- ")); "--language <LANGUAGE> --target-labels \"<TARGET_LABELS>\" -- "));
this->State->SetGlobalProperty( this->State->SetGlobalProperty(
"RULE_LAUNCH_CUSTOM", "RULE_LAUNCH_CUSTOM",
@@ -52,7 +52,10 @@ function(instrument test)
list(APPEND ARGS_CONFIGURE_ARG "-Wno-dev") list(APPEND ARGS_CONFIGURE_ARG "-Wno-dev")
endif() endif()
set(RunCMake_TEST_SOURCE_DIR ${RunCMake_SOURCE_DIR}/project) set(RunCMake_TEST_SOURCE_DIR ${RunCMake_SOURCE_DIR}/project)
run_cmake_with_options(${test} ${ARGS_CONFIGURE_ARG}) if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
set(maybe_CMAKE_BUILD_TYPE -DCMAKE_BUILD_TYPE=Debug)
endif()
run_cmake_with_options(${test} ${ARGS_CONFIGURE_ARG} ${maybe_CMAKE_BUILD_TYPE})
# Follow-up Commands # Follow-up Commands
if (ARGS_BUILD) if (ARGS_BUILD)
@@ -99,6 +99,14 @@ foreach(snippet IN LISTS snippets)
snippet_error("${snippet}" "Unexpected testName: ${testName}") snippet_error("${snippet}" "Unexpected testName: ${testName}")
endif() endif()
endif() endif()
# Verify that Config is Debug
if (filename MATCHES "^test|^compile|^link")
string(JSON config GET "${contents}" config)
if (NOT config STREQUAL "Debug")
snippet_error(${snippet} "Unexpected config: ${config}")
endif()
endif()
endforeach() endforeach()
# Verify that listed snippets match expected roles # Verify that listed snippets match expected roles
@@ -37,18 +37,21 @@ function(snippet_has_fields snippet contents)
has_key("${snippet}" "${contents}" outputSizes) has_key("${snippet}" "${contents}" outputSizes)
has_key("${snippet}" "${contents}" targetType) has_key("${snippet}" "${contents}" targetType)
has_key("${snippet}" "${contents}" targetLabels) has_key("${snippet}" "${contents}" targetLabels)
has_key("${snippet}" "${contents}" config)
elseif (filename MATCHES "^compile-*") elseif (filename MATCHES "^compile-*")
has_key("${snippet}" "${contents}" target) has_key("${snippet}" "${contents}" target)
has_key("${snippet}" "${contents}" outputs) has_key("${snippet}" "${contents}" outputs)
has_key("${snippet}" "${contents}" outputSizes) has_key("${snippet}" "${contents}" outputSizes)
has_key("${snippet}" "${contents}" source) has_key("${snippet}" "${contents}" source)
has_key("${snippet}" "${contents}" language) has_key("${snippet}" "${contents}" language)
has_key("${snippet}" "${contents}" config)
elseif (filename MATCHES "^custom-*") elseif (filename MATCHES "^custom-*")
has_key("${snippet}" "${contents}" target) has_key("${snippet}" "${contents}" target)
has_key("${snippet}" "${contents}" outputs) has_key("${snippet}" "${contents}" outputs)
has_key("${snippet}" "${contents}" outputSizes) has_key("${snippet}" "${contents}" outputSizes)
elseif (filename MATCHES "^test-*") elseif (filename MATCHES "^test-*")
has_key("${snippet}" "${contents}" testName) has_key("${snippet}" "${contents}" testName)
has_key("${snippet}" "${contents}" config)
endif() endif()
if(ARGS_DYNAMIC_QUERY) if(ARGS_DYNAMIC_QUERY)
has_key("${snippet}" "${contents}" dynamicSystemInformation) has_key("${snippet}" "${contents}" dynamicSystemInformation)