klonyyy / MCUViewer

Real-time embedded variable & trace viewer
GNU General Public License v3.0
824 stars 82 forks source link

CPU/GPU usage when idle #49

Closed dzid26 closed 6 months ago

dzid26 commented 6 months ago

Windows 11. There is constant small CPU/GPU usage even when acquisition is stopped and app is minimized.

Can we pause the rendering at least under those conditions?

klonyyy commented 6 months ago

Could you show me the circumstances under which these usages take place? This is my usage when STMViewer is minimized: image

(Branch jlink_hss @ b6371ef)

dzid26 commented 6 months ago

All the time.

In general the usage is not big (usually 2%) but it jumps to 5% periodically.

Examples (after loading config and minimizing.) (When recording is active, the effect on GPU is slightly lesser. )

https://github.com/klonyyy/STMViewer/assets/841061/79d86b5d-a6b1-4129-a473-e70b54eea0b6

https://github.com/klonyyy/STMViewer/assets/841061/58e69c3a-afc5-450b-8a8f-20b8264e1a1d

I am expecting there could be 0% when stopped. But if imgui is not efficient about mouse events, etc.., then at least maybe we can pause it when minimized.

Thanks

klonyyy commented 6 months ago

Please let me know if the latest commit solved the issue. Thanks for bringing it out!

dzid26 commented 6 months ago

Strangely, today, I couldn't reproduce 5% CPU spikes on any version.

Version 0.4 & 0.5:

With GLFW_FOCUSED:

But the cursors don't refresh when hovering. Not sure if that is useful for anything.

Since the issue doesn't seem as bad as I thought, I guess we could check for "minimized" only?

This works:

if (glfwGetWindowAttrib(window, GLFW_ICONIFIED))
klonyyy commented 6 months ago

Yeah, I was thinking of the GLFW_ICONIFIED however this does not seem to limit the rendering whenever the windows is overlayed by another window (not minimized explicitly). Let's stick with it and see if someone complaints about the high CPU/GPU usage after this fix.

dzid26 commented 6 months ago

Actually, we also could add this in the while loop as another simple efficiency improvement:

        if (glfwGetWindowAttrib(window, GLFW_FOCUSED) || (tracePlotHandler->getViewerState() == PlotHandlerBase::state::RUN) || (plotHandler->getViewerState() == PlotHandlerBase::state::RUN))
            glfwSwapInterval(1);
        else
            glfwSwapInterval(4);

1% instead of 4% GPU usage with visible window.

klonyyy commented 6 months ago

Would you be willing to implement and test that in a PR to the devel branch?