| 31 | ProfilingToolsService ProfilingToolsServiceInstance; |
| 32 | |
| 33 | void ProfilingToolsService::Update() |
| 34 | { |
| 35 | ZoneScoped; |
| 36 | PROFILE_MEM(Profiler); |
| 37 | |
| 38 | // Capture stats |
| 39 | { |
| 40 | auto& stats = ProfilingTools::Stats; |
| 41 | |
| 42 | stats.ProcessMemory = Platform::GetProcessMemoryStats(); |
| 43 | stats.MemoryCPU = Platform::GetMemoryStats(); |
| 44 | stats.MemoryGPU.Total = GPUDevice::Instance->TotalGraphicsMemory; |
| 45 | stats.MemoryGPU.Used = GPUDevice::Instance->GetMemoryUsage(); |
| 46 | stats.FPS = Engine::GetFramesPerSecond(); |
| 47 | |
| 48 | stats.UpdateTimeMs = static_cast<float>(Time::Update.LastLength * 1000.0); |
| 49 | stats.PhysicsTimeMs = static_cast<float>(Time::Physics.LastLength * 1000.0); |
| 50 | stats.DrawCPUTimeMs = static_cast<float>(Time::Draw.LastLength * 1000.0); |
| 51 | |
| 52 | float presentTime; |
| 53 | ProfilerGPU::GetLastFrameData(stats.DrawGPUTimeMs, presentTime, stats.DrawStats); |
| 54 | stats.DrawCPUTimeMs = Math::Max(stats.DrawCPUTimeMs - presentTime, 0.0f); // Remove swapchain present wait time to exclude from drawing on CPU |
| 55 | } |
| 56 | |
| 57 | // Extract CPU profiler events |
| 58 | Platform::MemoryBarrier(); |
| 59 | const auto& threads = ProfilerCPU::Threads; |
| 60 | Platform::MemoryBarrier(); |
| 61 | for (auto& pt : ProfilingTools::EventsCPU) |
| 62 | pt.Events.Clear(); |
| 63 | ProfilingTools::EventsCPU.EnsureCapacity(threads.Count()); |
| 64 | for (int32 i = 0; i < threads.Count(); i++) |
| 65 | { |
| 66 | ProfilerCPU::Thread* thread = threads[i]; |
| 67 | if (thread == nullptr) |
| 68 | continue; |
| 69 | ProfilingTools::ThreadStats* pt = nullptr; |
| 70 | for (auto& e : ProfilingTools::EventsCPU) |
| 71 | { |
| 72 | if (e.Name == thread->GetName()) |
| 73 | { |
| 74 | pt = &e; |
| 75 | break; |
| 76 | } |
| 77 | } |
| 78 | if (!pt) |
| 79 | { |
| 80 | pt = &ProfilingTools::EventsCPU.AddOne(); |
| 81 | pt->Name = thread->GetName(); |
| 82 | } |
| 83 | |
| 84 | thread->Buffer.Extract(pt->Events, true); |
| 85 | } |
| 86 | |
| 87 | #if 0 |
| 88 | // Print CPU threads events to the log |
| 89 | for (auto& pt : ProfilingTools::EventsCPU) |
| 90 | { |
nothing calls this directly
no test coverage detected