diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2022-11-10 23:15:08 (GMT) |
---|---|---|
committer | Kyle Edwards <kyle.edwards@kitware.com> | 2022-11-11 16:45:00 (GMT) |
commit | 553794e98706800a8c792bbcd81d49522333a50f (patch) | |
tree | 168b7b2625b4673d77c60089926df96ed70442af /Source | |
parent | 31893e8c8f580d6a94fc70b85e8cae47300cc6c0 (diff) | |
download | CMake-553794e98706800a8c792bbcd81d49522333a50f.zip CMake-553794e98706800a8c792bbcd81d49522333a50f.tar.gz CMake-553794e98706800a8c792bbcd81d49522333a50f.tar.bz2 |
cmake::CreateProfilingEntry: Refactor to take lambda for args
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmMakefile.cxx | 15 | ||||
-rw-r--r-- | Source/cmMakefileProfilingData.cxx | 29 | ||||
-rw-r--r-- | Source/cmMakefileProfilingData.h | 14 | ||||
-rw-r--r-- | 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 <stdexcept> #include <type_traits> #include <utility> -#include <vector> - -#include <cm/utility> #include <cm3p/json/value.h> #include <cm3p/json/writer.h> @@ -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<Json::Value> 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<Json::Value> args) @@ -127,6 +107,15 @@ void cmMakefileProfilingData::StopEntry() } } +cmMakefileProfilingData::RAII::RAII(cmMakefileProfilingData& data, + const std::string& category, + const std::string& name, + cm::optional<Json::Value> 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 <memory> #include <string> -#include <utility> #include <cm/optional> @@ -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<Json::Value> args = cm::nullopt); void StopEntry(); @@ -35,12 +30,9 @@ public: RAII(const RAII&) = delete; RAII(RAII&&) noexcept; - template <typename... Args> - RAII(cmMakefileProfilingData& data, Args&&... args) - : Data(&data) - { - this->Data->StartEntry(std::forward<Args>(args)...); - } + RAII(cmMakefileProfilingData& data, const std::string& category, + const std::string& name, + cm::optional<Json::Value> 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 <typename... Args> cm::optional<cmMakefileProfilingData::RAII> CreateProfilingEntry( - Args&&... args) + const std::string& category, const std::string& name) + { + return this->CreateProfilingEntry( + category, name, []() -> cm::nullopt_t { return cm::nullopt; }); + } + + template <typename ArgsFunc> + cm::optional<cmMakefileProfilingData::RAII> CreateProfilingEntry( + const std::string& category, const std::string& name, ArgsFunc&& argsFunc) { if (this->IsProfilingEnabled()) { return cm::make_optional<cmMakefileProfilingData::RAII>( - this->GetProfilingOutput(), std::forward<Args>(args)...); + this->GetProfilingOutput(), category, name, argsFunc()); } return cm::nullopt; } |