MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Update

Method Update

Source/Engine/Profiler/ProfilingTools.cpp:33–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31ProfilingToolsService ProfilingToolsServiceInstance;
32
33void 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 {

Callers

nothing calls this directly

Calls 15

GetFramesPerSecondFunction · 0.85
AddOneMethod · 0.80
MaxFunction · 0.50
MemoryBarrierFunction · 0.50
GetMemoryUsageMethod · 0.45
ClearMethod · 0.45
EnsureCapacityMethod · 0.45
CountMethod · 0.45
GetNameMethod · 0.45
ExtractMethod · 0.45
HasItemsMethod · 0.45
HasDataMethod · 0.45

Tested by

no test coverage detected