diff options
Diffstat (limited to 'src/mbgl/renderer/renderer_impl.cpp')
-rw-r--r-- | src/mbgl/renderer/renderer_impl.cpp | 84 |
1 files changed, 83 insertions, 1 deletions
diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp index 113840d059..6dbc440ef6 100644 --- a/src/mbgl/renderer/renderer_impl.cpp +++ b/src/mbgl/renderer/renderer_impl.cpp @@ -24,6 +24,23 @@ static RendererObserver& nullObserver() { return observer; } +namespace { + +struct { + double totalTime = 0.0; + double orchestrationTime = 0.0; + double orchestrationTimePeak = 0.0; + double orchestrationPercentagePeak = 0.0; + double uploadTime = 0.0; + double uploadTimePeak = 0.0; + double uploadPercentagePeak = 0.0; + std::size_t failedFrames = 0u; + std::size_t totalFrames = 0u; + std::size_t framesSavedWithBackgroundOrchestration = 0u; +} stats; + +} // namespace + Renderer::Impl::Impl(gfx::RendererBackend& backend_, float pixelRatio_, optional<std::string> localFontFamily_) @@ -35,6 +52,27 @@ Renderer::Impl::Impl(gfx::RendererBackend& backend_, } Renderer::Impl::~Impl() { + Log::Warning(Event::General, + "Overall stats: orchestration took %f ms from %f ms of the total rendering time (%f%%)", + stats.orchestrationTime, + stats.totalTime, + stats.orchestrationTime / stats.totalTime * 100.0); + Log::Warning(Event::General, + "Overall stats: orchestration peak value: %f ms, orchestration peak frame time percentage: %f", + stats.orchestrationTimePeak, + stats.orchestrationPercentagePeak); + Log::Warning(Event::General, + "Overall stats: upload peak value: %f ms, upload peak frame time percentage: %f", + stats.uploadTimePeak, + stats.uploadPercentagePeak); + Log::Warning(Event::General, + "Overall stats: %zu frames out of %zu took > 16.7 ms (%f%%), %zu of them took too long because of " + "orchestration (%f%%)", + stats.failedFrames, + stats.totalFrames, + double(stats.failedFrames) / stats.totalFrames * 100.0, + stats.framesSavedWithBackgroundOrchestration, + double(stats.framesSavedWithBackgroundOrchestration) / stats.failedFrames * 100.0); assert(gfx::BackendScope::exists()); }; @@ -42,7 +80,8 @@ void Renderer::Impl::setObserver(RendererObserver* observer_) { observer = observer_ ? observer_ : &nullObserver(); } -void Renderer::Impl::render(const RenderTree& renderTree) { +void Renderer::Impl::render(const RenderTree& renderTree, TimePoint frame_start) { + auto render_start = Clock::now(); if (renderState == RenderState::Never) { observer->onWillStartRenderingMap(); } @@ -79,6 +118,8 @@ void Renderer::Impl::render(const RenderTree& renderTree) { const auto& sourceRenderItems = renderTree.getSourceRenderItems(); const auto& layerRenderItems = renderTree.getLayerRenderItems(); + auto upload_start = Clock::now(); + // - UPLOAD PASS ------------------------------------------------------------------------------- // Uploads all required buffers and images before we do any actual rendering. { @@ -95,6 +136,7 @@ void Renderer::Impl::render(const RenderTree& renderTree) { renderTree.getLineAtlas().upload(*uploadPass); renderTree.getPatternAtlas().upload(*uploadPass); } + auto upload_end = Clock::now(); // - 3D PASS ------------------------------------------------------------------------------------- // Renders any 3D layers bottom-to-top to unique FBOs with texture attachments, but share the same @@ -220,6 +262,46 @@ void Renderer::Impl::render(const RenderTree& renderTree) { renderState = RenderState::Fully; observer->onDidFinishRenderingMap(); } + + auto frame_end = Clock::now(); + std::chrono::duration<double, std::milli> frameDuration = frame_end - frame_start; + std::chrono::duration<double, std::milli> orchDuration = render_start - frame_start; + std::chrono::duration<double, std::milli> renderDuration = frame_end - render_start; + std::chrono::duration<double, std::milli> uploadDuration = upload_end - upload_start; + + stats.totalTime += frameDuration.count(); + stats.orchestrationTime += orchDuration.count(); + + double orchestrationPercentage = orchDuration.count() / frameDuration.count() * 100.0; + double uploadPercentage = uploadDuration.count() / frameDuration.count() * 100.0; + + if (stats.orchestrationTimePeak < orchDuration.count()) { + stats.orchestrationTimePeak = orchDuration.count(); + } + if (stats.orchestrationPercentagePeak < orchestrationPercentage) { + stats.orchestrationPercentagePeak = orchestrationPercentage; + } + if (stats.uploadTimePeak < uploadDuration.count()) { + stats.uploadTimePeak = uploadDuration.count(); + } + if (stats.uploadPercentagePeak < uploadPercentage) { + stats.uploadPercentagePeak = uploadPercentage; + } + + constexpr double kMaxFrameDuration = 16.7; // 60 fps + stats.totalFrames++; + if (frameDuration.count() > kMaxFrameDuration) { + stats.failedFrames++; + Log::Warning(Event::General, + "Failed frame stats: total: %f ms, orchestration %f ms, rendering %f ms, upload %f ms", + frameDuration.count(), + orchDuration.count(), + renderDuration.count(), + uploadDuration.count()); + if (frameDuration.count() - orchDuration.count() <= kMaxFrameDuration) { + stats.framesSavedWithBackgroundOrchestration++; + } + } } void Renderer::Impl::reduceMemoryUse() { |