From 6929baca2f5c615fcbe8fc8beb4186c12249cd30 Mon Sep 17 00:00:00 2001 From: Tyler Yankee Date: Thu, 25 Sep 2025 13:50:02 -0400 Subject: [PATCH] instrumentation: Fix trace event names Amend commit 933176c2d1 (instrumentation: Rename install and custom trace events, 2025-09-04) to remove the trailing colon for trace events which have no name suffix. --- Source/cmInstrumentation.cxx | 20 +++++++++++-------- .../Instrumentation/verify-trace.cmake | 12 +++++------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Source/cmInstrumentation.cxx b/Source/cmInstrumentation.cxx index edc1c30eb3..e251268d6b 100644 --- a/Source/cmInstrumentation.cxx +++ b/Source/cmInstrumentation.cxx @@ -944,21 +944,25 @@ void cmInstrumentation::AppendTraceEvent(Json::Value& trace, // Provide a useful trace event name depending on what data is available // from the snippet. - std::string name = cmStrCat(snippetData["role"].asString(), ": "); + std::string nameSuffix; if (snippetData["role"] == "compile") { - name.append(snippetData["source"].asString()); + nameSuffix = snippetData["source"].asString(); } else if (snippetData["role"] == "link") { - name.append(snippetData["target"].asString()); + nameSuffix = snippetData["target"].asString(); } else if (snippetData["role"] == "install") { cmCMakePath workingDir(snippetData["workingDir"].asCString()); - std::string lastDirName = workingDir.GetFileName().String(); - name.append(lastDirName); + nameSuffix = workingDir.GetFileName().String(); } else if (snippetData["role"] == "custom") { - name.append(snippetData["command"].asString()); + nameSuffix = snippetData["command"].asString(); } else if (snippetData["role"] == "test") { - name.append(snippetData["testName"].asString()); + nameSuffix = snippetData["testName"].asString(); + } + if (!nameSuffix.empty()) { + snippetTraceEvent["name"] = + cmStrCat(snippetData["role"].asString(), ": ", nameSuffix); + } else { + snippetTraceEvent["name"] = snippetData["role"].asString(); } - snippetTraceEvent["name"] = name; snippetTraceEvent["cat"] = snippetData["role"]; snippetTraceEvent["ph"] = "X"; diff --git a/Tests/RunCMake/Instrumentation/verify-trace.cmake b/Tests/RunCMake/Instrumentation/verify-trace.cmake index f24d50829b..59399a9f53 100644 --- a/Tests/RunCMake/Instrumentation/verify-trace.cmake +++ b/Tests/RunCMake/Instrumentation/verify-trace.cmake @@ -49,23 +49,23 @@ function(trace_valid_entry trace entry) json_error("${trace}" "Name is empty: ${entry}") endif() string(JSON cat GET "${entry}" cat) - set(expected_name "${cat}: ") + set(expected_name "${cat}") if (cat STREQUAL "compile") string(JSON source GET "${args}" source) - string(APPEND expected_name "${source}") + string(APPEND expected_name ": ${source}") elseif (cat STREQUAL "link") string(JSON target GET "${args}" target) - string(APPEND expected_name "${target}") + 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}") + string(APPEND expected_name ": ${lastDirName}") elseif (cat STREQUAL "custom") string(JSON command GET "${args}" command) - string(APPEND expected_name "${command}") + string(APPEND expected_name ": ${command}") elseif (cat STREQUAL "test") string(JSON testName GET "${args}" testName) - string(APPEND expected_name "${testName}") + string(APPEND expected_name ": ${testName}") endif() if (NOT name STREQUAL expected_name) json_error("${trace}" "Invalid name: ${name}")