From 553794e98706800a8c792bbcd81d49522333a50f Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Thu, 10 Nov 2022 18:15:08 -0500 Subject: cmake::CreateProfilingEntry: Refactor to take lambda for args --- Source/cmMakefile.cxx | 15 ++++++++++++++- Source/cmMakefileProfilingData.cxx | 29 +++++++++-------------------- Source/cmMakefileProfilingData.h | 14 +++----------- Source/cmake.h | 13 ++++++++++--- 4 files changed, 36 insertions(+), 35 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 2091f27..db8f785 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -376,7 +376,20 @@ public: this->Makefile->ExecutionStatusStack.push_back(&status); #if !defined(CMAKE_BOOTSTRAP) this->ProfilingDataRAII = - this->Makefile->GetCMakeInstance()->CreateProfilingEntry(lff, lfc); + this->Makefile->GetCMakeInstance()->CreateProfilingEntry( + "script", lff.LowerCaseName(), [&lff, &lfc]() -> Json::Value { + Json::Value argsValue = Json::objectValue; + if (!lff.Arguments().empty()) { + std::string args; + for (auto const& a : lff.Arguments()) { + args = cmStrCat(args, args.empty() ? "" : " ", a.Value); + } + argsValue["functionArgs"] = args; + } + argsValue["location"] = + cmStrCat(lfc.FilePath, ':', std::to_string(lfc.Line)); + return argsValue; + }); #endif } diff --git a/Source/cmMakefileProfilingData.cxx b/Source/cmMakefileProfilingData.cxx index e4844f3..e903ae1 100644 --- a/Source/cmMakefileProfilingData.cxx +++ b/Source/cmMakefileProfilingData.cxx @@ -6,9 +6,6 @@ #include #include #include -#include - -#include #include #include @@ -16,7 +13,6 @@ #include "cmsys/FStream.hxx" #include "cmsys/SystemInformation.hxx" -#include "cmListFileCache.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" @@ -47,22 +43,6 @@ cmMakefileProfilingData::~cmMakefileProfilingData() noexcept } } -void cmMakefileProfilingData::StartEntry(const cmListFileFunction& lff, - cmListFileContext const& lfc) -{ - cm::optional argsValue(cm::in_place, Json::objectValue); - if (!lff.Arguments().empty()) { - std::string args; - for (auto const& a : lff.Arguments()) { - args = cmStrCat(args, args.empty() ? "" : " ", a.Value); - } - (*argsValue)["functionArgs"] = args; - } - (*argsValue)["location"] = - cmStrCat(lfc.FilePath, ':', std::to_string(lfc.Line)); - this->StartEntry("script", lff.LowerCaseName(), std::move(argsValue)); -} - void cmMakefileProfilingData::StartEntry(const std::string& category, const std::string& name, cm::optional args) @@ -127,6 +107,15 @@ void cmMakefileProfilingData::StopEntry() } } +cmMakefileProfilingData::RAII::RAII(cmMakefileProfilingData& data, + const std::string& category, + const std::string& name, + cm::optional args) + : Data(&data) +{ + this->Data->StartEntry(category, name, std::move(args)); +} + cmMakefileProfilingData::RAII::RAII(RAII&& other) noexcept : Data(other.Data) { diff --git a/Source/cmMakefileProfilingData.h b/Source/cmMakefileProfilingData.h index e8d7dfa..4cf0bfa 100644 --- a/Source/cmMakefileProfilingData.h +++ b/Source/cmMakefileProfilingData.h @@ -3,7 +3,6 @@ #pragma once #include #include -#include #include @@ -15,15 +14,11 @@ namespace Json { class StreamWriter; } -class cmListFileContext; -class cmListFileFunction; - class cmMakefileProfilingData { public: cmMakefileProfilingData(const std::string&); ~cmMakefileProfilingData() noexcept; - void StartEntry(const cmListFileFunction& lff, cmListFileContext const& lfc); void StartEntry(const std::string& category, const std::string& name, cm::optional args = cm::nullopt); void StopEntry(); @@ -35,12 +30,9 @@ public: RAII(const RAII&) = delete; RAII(RAII&&) noexcept; - template - RAII(cmMakefileProfilingData& data, Args&&... args) - : Data(&data) - { - this->Data->StartEntry(std::forward(args)...); - } + RAII(cmMakefileProfilingData& data, const std::string& category, + const std::string& name, + cm::optional args = cm::nullopt); ~RAII(); diff --git a/Source/cmake.h b/Source/cmake.h index 2f7f7bd..6b585a1 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -638,13 +638,20 @@ public: cmMakefileProfilingData& GetProfilingOutput(); bool IsProfilingEnabled() const; - template cm::optional CreateProfilingEntry( - Args&&... args) + const std::string& category, const std::string& name) + { + return this->CreateProfilingEntry( + category, name, []() -> cm::nullopt_t { return cm::nullopt; }); + } + + template + cm::optional CreateProfilingEntry( + const std::string& category, const std::string& name, ArgsFunc&& argsFunc) { if (this->IsProfilingEnabled()) { return cm::make_optional( - this->GetProfilingOutput(), std::forward(args)...); + this->GetProfilingOutput(), category, name, argsFunc()); } return cm::nullopt; } -- cgit v0.12