From 933176c2d1cb9f1badfc569c95efbdf3cdf8985d Mon Sep 17 00:00:00 2001 From: Tyler Yankee Date: Thu, 4 Sep 2025 10:02:58 -0400 Subject: [PATCH] instrumentation: Rename install and custom trace events Follow the format of other trace events to produce a pretty name for install events (as the last component of the install script directory) and a slightly prettier name for custom events (still limited by the nature of custom targets). --- Source/cmInstrumentation.cxx | 18 ++++++---- .../Instrumentation/verify-trace.cmake | 34 ++++++++----------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/Source/cmInstrumentation.cxx b/Source/cmInstrumentation.cxx index 135958dc65..fdcf4a0d01 100644 --- a/Source/cmInstrumentation.cxx +++ b/Source/cmInstrumentation.cxx @@ -20,6 +20,7 @@ #include "cmsys/FStream.hxx" #include "cmsys/SystemInformation.hxx" +#include "cmCMakePath.h" #include "cmCryptoHash.h" #include "cmExperimental.h" #include "cmFileLock.h" @@ -946,16 +947,19 @@ void cmInstrumentation::AppendTraceEvent(Json::Value& trace, // Provide a useful trace event name depending on what data is available // from the snippet. - std::string name = snippetData["role"].asString(); + std::string name = cmStrCat(snippetData["role"].asString(), ": "); if (snippetData["role"] == "compile") { - name = cmStrCat("compile: ", snippetData["source"].asString()); + name.append(snippetData["source"].asString()); } else if (snippetData["role"] == "link") { - name = cmStrCat("link: ", snippetData["target"].asString()); - } else if (snippetData["role"] == "custom" || - snippetData["role"] == "install") { - name = snippetData["command"].asString(); + name.append(snippetData["target"].asString()); + } else if (snippetData["role"] == "install") { + cmCMakePath workingDir(snippetData["workingDir"].asCString()); + std::string lastDirName = workingDir.GetFileName().String(); + name.append(lastDirName); + } else if (snippetData["role"] == "custom") { + name.append(snippetData["command"].asString()); } else if (snippetData["role"] == "test") { - name = cmStrCat("test: ", snippetData["testName"].asString()); + name.append(snippetData["testName"].asString()); } snippetTraceEvent["name"] = name; diff --git a/Tests/RunCMake/Instrumentation/verify-trace.cmake b/Tests/RunCMake/Instrumentation/verify-trace.cmake index d6ef33ceee..f24d50829b 100644 --- a/Tests/RunCMake/Instrumentation/verify-trace.cmake +++ b/Tests/RunCMake/Instrumentation/verify-trace.cmake @@ -45,35 +45,29 @@ function(trace_valid_entry trace entry) # Check the formation of the "name" based on the snippet data string(JSON name GET "${entry}" name) + if (NOT name) + json_error("${trace}" "Name is empty: ${entry}") + endif() string(JSON cat GET "${entry}" cat) - set(error_name OFF) + set(expected_name "${cat}: ") if (cat STREQUAL "compile") string(JSON source GET "${args}" source) - if (NOT name STREQUAL "compile: ${source}") - set(error_name ON) - endif() + string(APPEND expected_name "${source}") elseif (cat STREQUAL "link") string(JSON target GET "${args}" target) - if (NOT name STREQUAL "link: ${target}") - set(error_name ON) - endif() - elseif (cat STREQUAL "custom" OR cat STREQUAL "install") + string(APPEND expected_name "${target}") + elseif (cat STREQUAL "install") + string(JSON workingDir GET "${args}" workingDir) + cmake_path(GET workingDir FILENAME lastDirName) + string(APPEND expected_name "${lastDirName}") + elseif (cat STREQUAL "custom") string(JSON command GET "${args}" command) - if (NOT name STREQUAL command) - set(error_name ON) - endif() + string(APPEND expected_name "${command}") elseif (cat STREQUAL "test") string(JSON testName GET "${args}" testName) - if (NOT name STREQUAL "test: ${testName}") - set(error_name ON) - endif() - else() - string(JSON role GET "${args}" role) - if (NOT name STREQUAL role) - set(error_name ON) - endif() + string(APPEND expected_name "${testName}") endif() - if (error_name) + if (NOT name STREQUAL expected_name) json_error("${trace}" "Invalid name: ${name}") endif()