i’m new to this, thrilled to be here and doing a first little project in of.
my goal is to have a daemon-like app(let) that receives serial data from an arduino, parses it and sends it on as osc-formatted messages. so far so good. i got it all working.
what i notice, though, is that whenever the app’s window is completely hidden, the CPU percentage as shown by top goes through the roof. where normally the app runs at around 3.5% CPU when visible, as soon as it’s hidden the values go up to 60% or 70% CPU.
i tried disabling all drawing and window etc, but to no avail.
i’m stumped and have no idea where to begin optimizing this.
ideally i’d like to compile the app as command-line tool without any GUI whatsoever, a real daemon.
by default, glut wants to run as fast as possible, and it will take the cpu usage high even if it’s not doing anything. if you set the frame rate slower, it will yield more, like
setting the framerate does indeed stabilize the CPU utilization.
will this also cap the rate at which update() is called?
am i correct to think that the execution loop is a callback run by glut?
and that glut when is not provided with a context to draw in i.e. its window is hidden, it runs absolutely wild?
[quote author=“j45ch”]setting the framerate does indeed stabilize the CPU utilization.
will this also cap the rate at which update() is called?
am i correct to think that the execution loop is a callback run by glut?
and that glut when is not provided with a context to draw in i.e. its window is hidden, it runs absolutely wild?
[/quote]
That’s right, the frame rate setting throttles GLUT’s idle callback which is responsible for calling the app’s update() and glutPostRedisplay() to schedule the next draw. So update() and draw() are called in lockstep.
If you want to decouple drawing from your app, you can try to either run your daemon code in a separate thread (see the ofxThread addon) or skip OF altogether and place you code inside a regular c++ main() block and just rip and reuse the bits of OF and the addons you need.