cmMakefileProfilingData.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include <memory>
  5. #include <string>
  6. #include <cm/optional>
  7. #include <cm3p/json/value.h> // IWYU pragma: keep
  8. #include "cmsys/FStream.hxx"
  9. namespace Json {
  10. class StreamWriter;
  11. }
  12. class cmMakefileProfilingData
  13. {
  14. public:
  15. cmMakefileProfilingData(const std::string&);
  16. ~cmMakefileProfilingData() noexcept;
  17. void StartEntry(const std::string& category, const std::string& name,
  18. cm::optional<Json::Value> args = cm::nullopt);
  19. void StopEntry();
  20. class RAII
  21. {
  22. public:
  23. RAII() = delete;
  24. RAII(const RAII&) = delete;
  25. RAII(RAII&&) noexcept;
  26. RAII(cmMakefileProfilingData& data, const std::string& category,
  27. const std::string& name,
  28. cm::optional<Json::Value> args = cm::nullopt);
  29. ~RAII();
  30. RAII& operator=(const RAII&) = delete;
  31. RAII& operator=(RAII&&) noexcept;
  32. private:
  33. cmMakefileProfilingData* Data = nullptr;
  34. };
  35. private:
  36. cmsys::ofstream ProfileStream;
  37. std::unique_ptr<Json::StreamWriter> JsonWriter;
  38. };