| 205 | }; |
| 206 | |
| 207 | void Profiler::BuildUI(bool enableFeedbackStats) |
| 208 | { |
| 209 | float const fontSize = ImGui::GetFontSize(); |
| 210 | |
| 211 | char durationLabel[64]; |
| 212 | snprintf(durationLabel, sizeof durationLabel, "%.1f s", m_profilerHistoryDuration); |
| 213 | ImGui::PushItemWidth(fontSize * 6.f); |
| 214 | if (ImGui::BeginCombo("Plot Duration", durationLabel)) |
| 215 | { |
| 216 | double durations[] = { 0.5, 1.0, 2.0, 5.0 }; |
| 217 | for (double duration : durations) |
| 218 | { |
| 219 | snprintf(durationLabel, sizeof durationLabel, "%.1f s", duration); |
| 220 | if (ImGui::Selectable(durationLabel, m_profilerHistoryDuration == duration)) |
| 221 | { |
| 222 | m_profilerHistoryDuration = duration; |
| 223 | } |
| 224 | } |
| 225 | ImGui::EndCombo(); |
| 226 | } |
| 227 | ImGui::PopItemWidth(); |
| 228 | |
| 229 | if (m_profilerHistory.size() < 10) |
| 230 | return; |
| 231 | |
| 232 | double const secondToMs = 1e3; |
| 233 | size_t const historySize = m_profilerHistory.size(); |
| 234 | double maxTime = 0; |
| 235 | double maxTiles = 0; |
| 236 | |
| 237 | for (auto const& record : m_profilerHistory) |
| 238 | { |
| 239 | maxTime = std::max(maxTime, record.frameTime); |
| 240 | maxTime = std::max(maxTime, record.renderTime); |
| 241 | if (enableFeedbackStats) |
| 242 | maxTime = std::max(maxTime, record.transcodingTime); |
| 243 | |
| 244 | maxTiles = std::max(maxTiles, double(record.tilesAllocated)); |
| 245 | maxTiles = std::max(maxTiles, double(record.tilesStandby)); |
| 246 | } |
| 247 | |
| 248 | maxTime *= secondToMs; |
| 249 | m_timePlotLimit.Update(maxTime, m_profilerHistory.back().frameTime); |
| 250 | m_tilesPlotLimit.Update(maxTiles, m_profilerHistory.back().frameTime); |
| 251 | |
| 252 | if (ImPlot::BeginPlot("Frame Time", ImVec2(20.f * fontSize, 15.f * fontSize), |
| 253 | ImPlotFlags_NoTitle | ImPlotFlags_NoMenus | ImPlotFlags_NoInputs)) |
| 254 | { |
| 255 | ImPlot::SetupAxes("Time (s)", "Time (ms)"); |
| 256 | ImPlot::SetupAxesLimits(-m_profilerHistoryDuration, 0, 0, m_timePlotLimit.GetMaximum(), ImGuiCond_Always); |
| 257 | ImPlot::PlotLineG("Frame Time", &ProfilerGetters::GetFrameTime, this, historySize); |
| 258 | ImPlot::PlotLineG("Render Time", &ProfilerGetters::GetRenderTime, this, historySize); |
| 259 | if (enableFeedbackStats) |
| 260 | ImPlot::PlotLineG("Transcoding Time", &ProfilerGetters::GetTranscodingTime, this, historySize); |
| 261 | ImPlot::EndPlot(); |
| 262 | } |
| 263 | |
| 264 | if (enableFeedbackStats && |
no test coverage detected