From 55bca4658fd7b5fed59e889aa260f22471d4f708 Mon Sep 17 00:00:00 2001 From: AMZN-ScottR <24445312+AMZN-ScottR@users.noreply.github.com> Date: Mon, 18 Oct 2021 17:54:08 -0700 Subject: [PATCH] [atom_cpu_profiler_gem_promotion] quick small changes based on PR feedback Signed-off-by: AMZN-ScottR <24445312+AMZN-ScottR@users.noreply.github.com> --- Gems/Atom/RHI/Code/Source/RHI/FrameScheduler.cpp | 2 ++ Gems/Profiler/Code/Source/CpuProfiler.h | 2 +- Gems/Profiler/Code/Source/CpuProfilerImpl.cpp | 7 +------ Gems/Profiler/Code/Source/ImGuiCpuProfiler.cpp | 8 ++++---- Gems/Profiler/Code/Source/ImGuiCpuProfiler.h | 10 +++++----- .../Code/Source/ProfilerImGuiSystemComponent.cpp | 2 +- Gems/Profiler/Code/Source/ProfilerSystemComponent.cpp | 2 +- 7 files changed, 15 insertions(+), 18 deletions(-) diff --git a/Gems/Atom/RHI/Code/Source/RHI/FrameScheduler.cpp b/Gems/Atom/RHI/Code/Source/RHI/FrameScheduler.cpp index 027847c35e..11ae78c69a 100644 --- a/Gems/Atom/RHI/Code/Source/RHI/FrameScheduler.cpp +++ b/Gems/Atom/RHI/Code/Source/RHI/FrameScheduler.cpp @@ -86,6 +86,8 @@ namespace AZ if (auto statsProfiler = AZ::Interface::Get(); statsProfiler) { + statsProfiler->ActivateProfiler(rhiMetricsId, true); + auto& rhiMetrics = statsProfiler->GetProfiler(rhiMetricsId); rhiMetrics.GetStatsManager().AddStatistic(frameTimeMetricId, frameTimeMetricName, /*units=*/"clocks", /*failIfExist=*/false); } diff --git a/Gems/Profiler/Code/Source/CpuProfiler.h b/Gems/Profiler/Code/Source/CpuProfiler.h index 289a549ddd..23130efa63 100644 --- a/Gems/Profiler/Code/Source/CpuProfiler.h +++ b/Gems/Profiler/Code/Source/CpuProfiler.h @@ -38,7 +38,7 @@ namespace Profiler }; CachedTimeRegion() = default; - CachedTimeRegion(const GroupRegionName& groupRegionName); + explicit CachedTimeRegion(const GroupRegionName& groupRegionName); CachedTimeRegion(const GroupRegionName& groupRegionName, uint16_t stackDepth, uint64_t startTick, uint64_t endTick); GroupRegionName m_groupRegionName{nullptr, nullptr}; diff --git a/Gems/Profiler/Code/Source/CpuProfilerImpl.cpp b/Gems/Profiler/Code/Source/CpuProfilerImpl.cpp index 253f8576a6..c88afdecd0 100644 --- a/Gems/Profiler/Code/Source/CpuProfilerImpl.cpp +++ b/Gems/Profiler/Code/Source/CpuProfilerImpl.cpp @@ -71,11 +71,6 @@ namespace Profiler m_initialized = true; AZ::SystemTickBus::Handler::BusConnect(); m_continuousCaptureData.set_capacity(10); - - if (auto statsProfiler = AZ::Interface::Get(); statsProfiler) - { - statsProfiler->ActivateProfiler(AZ_CRC_CE("RHI"), true); - } } void CpuProfilerImpl::Shutdown() @@ -290,7 +285,7 @@ namespace Profiler m_cachedTimeRegions.clear(); } - timeRegion.m_stackDepth = static_cast(m_stackLevel); + timeRegion.m_stackDepth = aznumeric_cast(m_stackLevel); AZ_Assert(m_timeRegionStack.size() < TimeRegionStackSize, "Adding too many time regions to the stack. Increase the size of TimeRegionStackSize."); m_timeRegionStack.push_back(timeRegion); diff --git a/Gems/Profiler/Code/Source/ImGuiCpuProfiler.cpp b/Gems/Profiler/Code/Source/ImGuiCpuProfiler.cpp index 1f8e9ae099..3f364f99e0 100644 --- a/Gems/Profiler/Code/Source/ImGuiCpuProfiler.cpp +++ b/Gems/Profiler/Code/Source/ImGuiCpuProfiler.cpp @@ -45,12 +45,12 @@ namespace Profiler using DeserializedCpuData = AZStd::vector; - AZ::Outcome LoadSavedCpuProfilingStatistics(const AZStd::string& capturePath) + AZ::Outcome LoadSavedCpuProfilingStatistics(const char* capturePath) { auto* base = AZ::IO::FileIOBase::GetInstance(); char resolvedPath[AZ::IO::MaxPathLength]; - if (!base->ResolvePath(capturePath.c_str(), resolvedPath, AZ::IO::MaxPathLength)) + if (!base->ResolvePath(capturePath, resolvedPath, AZ::IO::MaxPathLength)) { return AZ::Failure(AZStd::string::format("Could not resolve the path to file %s, is the path correct?", resolvedPath)); } @@ -103,7 +103,7 @@ namespace Profiler if (deserializationResult.GetProcessing() == AZ::JsonSerializationResult::Processing::Halted || serializer.m_cpuProfilingStatisticsSerializerEntries.empty()) { - return AZ::Failure(AZStd::string::format("Error in deserializing document: %s\n", deserializationResult.ToString(capturePath.c_str()).c_str())); + return AZ::Failure(AZStd::string::format("Error in deserializing document: %s\n", deserializationResult.ToString(capturePath).c_str())); } AZ_TracePrintf("JsonUtils", "Successfully loaded CPU profiling data with %zu profiling entries.\n", @@ -421,7 +421,7 @@ namespace Profiler void ImGuiCpuProfiler::LoadFile() { const AZ::IO::Path& pathToLoad = m_cachedCapturePaths[m_currentFileIndex]; - auto loadResult = CpuProfilerImGuiHelper::LoadSavedCpuProfilingStatistics(pathToLoad.String()); + auto loadResult = CpuProfilerImGuiHelper::LoadSavedCpuProfilingStatistics(pathToLoad.c_str()); if (!loadResult.IsSuccess()) { AZ_TracePrintf("ImGuiCpuProfiler", "%s", loadResult.GetError().c_str()); diff --git a/Gems/Profiler/Code/Source/ImGuiCpuProfiler.h b/Gems/Profiler/Code/Source/ImGuiCpuProfiler.h index 4529c7a3b2..2c6a3e470a 100644 --- a/Gems/Profiler/Code/Source/ImGuiCpuProfiler.h +++ b/Gems/Profiler/Code/Source/ImGuiCpuProfiler.h @@ -71,9 +71,9 @@ namespace Profiler AZStd::sys_time_t m_runningAverageTicks = 0; }; - //! ImGui widget for examining Atom CPU Profiling instrumentation. + //! ImGui widget for examining CPU Profiling instrumentation. //! Offers both a statistical view (with sorting and searching capability) and a visualizer - //! similar to RAD and other profiling tools. + //! similar to other profiling tools. class ImGuiCpuProfiler : public AZ::SystemTickBus::Handler { @@ -99,10 +99,10 @@ namespace Profiler void Draw(bool& keepDrawing); private: - static constexpr float RowHeight = 35.0; + static constexpr float RowHeight = 35.0f; static constexpr int DefaultFramesToCollect = 50; - static constexpr float MediumFrameTimeLimit = 16.6; // 60 fps - static constexpr float HighFrameTimeLimit = 33.3; // 30 fps + static constexpr float MediumFrameTimeLimit = 16.6f; // 60 fps + static constexpr float HighFrameTimeLimit = 33.3f; // 30 fps //! Draws the statistical view of the CPU profiling data. void DrawStatisticsView(); diff --git a/Gems/Profiler/Code/Source/ProfilerImGuiSystemComponent.cpp b/Gems/Profiler/Code/Source/ProfilerImGuiSystemComponent.cpp index c1ed66d465..ea7414a82a 100644 --- a/Gems/Profiler/Code/Source/ProfilerImGuiSystemComponent.cpp +++ b/Gems/Profiler/Code/Source/ProfilerImGuiSystemComponent.cpp @@ -29,7 +29,7 @@ namespace Profiler { ec->Class("ProfilerImGui", "Provides in-game visualization of the performance data gathered by the ProfilerSystemComponent") ->ClassElement(AZ::Edit::ClassElements::EditorData, "") - ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System")) + ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("System")) ->Attribute(AZ::Edit::Attributes::AutoExpand, true); } } diff --git a/Gems/Profiler/Code/Source/ProfilerSystemComponent.cpp b/Gems/Profiler/Code/Source/ProfilerSystemComponent.cpp index f876a8d4c4..1150027edd 100644 --- a/Gems/Profiler/Code/Source/ProfilerSystemComponent.cpp +++ b/Gems/Profiler/Code/Source/ProfilerSystemComponent.cpp @@ -126,7 +126,7 @@ namespace Profiler { ec->Class("Profiler", "Provides a custom implementation of the AZ::Debug::Profiler interface for capturing performance data") ->ClassElement(AZ::Edit::ClassElements::EditorData, "") - ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System")) + ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("System")) ->Attribute(AZ::Edit::Attributes::AutoExpand, true); ProfilerNotificationBusHandler::Reflect(context);