瀏覽代碼

cmake::CreateProfilingEntry: Refactor to take lambda for args

Kyle Edwards 2 年之前
父節點
當前提交
553794e987
共有 4 個文件被更改,包括 36 次插入35 次删除
  1. 14 1
      Source/cmMakefile.cxx
  2. 9 20
      Source/cmMakefileProfilingData.cxx
  3. 3 11
      Source/cmMakefileProfilingData.h
  4. 10 3
      Source/cmake.h

+ 14 - 1
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
   }
 

+ 9 - 20
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)
 {

+ 3 - 11
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();
 

+ 10 - 3
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;
   }