diff options
Diffstat (limited to 'Source/cmMakefileProfilingData.cxx')
| -rw-r--r-- | Source/cmMakefileProfilingData.cxx | 57 |
1 files changed, 42 insertions, 15 deletions
diff --git a/Source/cmMakefileProfilingData.cxx b/Source/cmMakefileProfilingData.cxx index 1cd97c9..e903ae1 100644 --- a/Source/cmMakefileProfilingData.cxx +++ b/Source/cmMakefileProfilingData.cxx @@ -4,7 +4,8 @@ #include <chrono> #include <stdexcept> -#include <vector> +#include <type_traits> +#include <utility> #include <cm3p/json/value.h> #include <cm3p/json/writer.h> @@ -12,7 +13,6 @@ #include "cmsys/FStream.hxx" #include "cmsys/SystemInformation.hxx" -#include "cmListFileCache.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" @@ -43,8 +43,9 @@ cmMakefileProfilingData::~cmMakefileProfilingData() noexcept } } -void cmMakefileProfilingData::StartEntry(const cmListFileFunction& lff, - cmListFileContext const& lfc) +void cmMakefileProfilingData::StartEntry(const std::string& category, + const std::string& name, + cm::optional<Json::Value> args) { /* Do not try again if we previously failed to write to output. */ if (!this->ProfileStream.good()) { @@ -58,24 +59,17 @@ void cmMakefileProfilingData::StartEntry(const cmListFileFunction& lff, cmsys::SystemInformation info; Json::Value v; v["ph"] = "B"; - v["name"] = lff.LowerCaseName(); - v["cat"] = "cmake"; + v["name"] = name; + v["cat"] = category; v["ts"] = static_cast<Json::Value::UInt64>( std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::steady_clock::now().time_since_epoch()) .count()); v["pid"] = static_cast<int>(info.GetProcessId()); v["tid"] = 0; - Json::Value argsValue; - if (!lff.Arguments().empty()) { - std::string args; - for (auto const& a : lff.Arguments()) { - args += (args.empty() ? "" : " ") + a.Value; - } - argsValue["functionArgs"] = args; + if (args) { + v["args"] = *std::move(args); } - argsValue["location"] = lfc.FilePath + ":" + std::to_string(lfc.Line); - v["args"] = argsValue; this->JsonWriter->write(v, &this->ProfileStream); } catch (std::ios_base::failure& fail) { @@ -112,3 +106,36 @@ void cmMakefileProfilingData::StopEntry() cmSystemTools::Error("Error writing profiling output!"); } } + +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) +{ + other.Data = nullptr; +} + +cmMakefileProfilingData::RAII::~RAII() +{ + if (this->Data) { + this->Data->StopEntry(); + } +} + +cmMakefileProfilingData::RAII& cmMakefileProfilingData::RAII::operator=( + RAII&& other) noexcept +{ + if (this->Data) { + this->Data->StopEntry(); + } + this->Data = other.Data; + other.Data = nullptr; + return *this; +} |
