About Store Forum Documentation Contact



Post Reply 
cpu load when minimized
Author Message
yvanvds Offline
Member

Post: #1
cpu load when minimized
Hi

I noticed that my server application starts using a lot more cpu time when minimized. I can recreate this even with a very simple app:

PHP Code:
void InitPre()
{
   
EE_INIT();
  
App.flag=APP_WORK_IN_BACKGROUND|APP_NO_PAUSE_ON_WINDOW_MOVE_SIZE|APP_MINIMIZABLE|APP_ALLOW_NO_GPU;
   
D.sync(true);
   
Renderer.type(RT_SIMPLE);
   
D.shadowMode(SHADOW_NONE).shadowMapSize(0);
}

bool Init() { return true; }
void Shut() {}

bool Update() {
   
Time.wait(1);
   return 
true;
}

void Draw() { return; } 

When I start the application it uses about 1% cpu time. This is stable. When I minimize it, the cpu time slowly climbs up to about 10% over a few minutes. When the window is restored, it climbs further to 15% for a few minutes and then suddenly drops back to 1%. After that, it stays on 1% until I minimize it again.

Any idea how to fix this?

Regards,

yvan
10-03-2015 02:46 PM
Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #2
RE: cpu load when minimized
there is the possibility that I always use for good measure and that is adding extra Time.wait() time in update inside if(App.minimized()) I think that is what I use, if I am remembering incorrectly there should still be something in App that tells you that the app is minimized.

Also I am not sure what additional stuff the engine might stop calling when minimized but I assume it is something, meaning when the app is in focus Time.wait is more effective.
10-03-2015 03:44 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #3
RE: cpu load when minimized
Hi,

I've just tried reproducing this, but I'm getting 0% when minimized.

Can you tell me what platform are you using? Windows DX10+? That's what I've tried.

Can you try disabling Oculus Rift with APP_NO_OCULUS.. in InitPre?

If that won't help, having the source license, you could add some extra codes around different parts of the engine loop, to measure what exactly uses that CPU time.

something like:
Dbl t=Time.curTime();
updatesomething();
Dbl time_needed_for_updatesomething=Time.curTime()-t;

store the results in the memory, and then verify which part takes the most time.
10-03-2015 11:17 PM
Find all posts by this user Quote this message in a reply
yvanvds Offline
Member

Post: #4
RE: cpu load when minimized
I tried both, dx9 and 10+. That didn't make a difference. I'll try your suggestions tomorrow, because it's getting a bit late now.

As for now i've 'fixed' it with calling this function in update (credit goes to zervox):

PHP Code:
void TimeSlice(Flt fps=60){
 static 
Flt now 0;
 static 
Flt lastFrame 0;
 static 
Flt delta 0;
 
now Time.curTime();
 
delta now lastFrame
 
lastFrame now
 
fps 1.0f fps 1000.0f
 if (
delta fps){ Time.wait(fps delta); }


Used it with 30 fps. I also noticed that before using that function, my framerate went up to 450fps while minimized. I guess that explains for the most part?
10-03-2015 11:28 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #5
RE: cpu load when minimized
In this function, 'delta' and 'now' don't need to be static, and don't need to be initialized to zero.
Also fps = 1.0f / fps * 1000.0f; can be replaced with Flt ms = 1000.0f / fps; (and use ms later instead of fps)

Right now I'm doing lots of optimizations in the engine, so my mind is in "optimizing mode" smile

Even with Time.wait(1) the CPU usage should not get high in a simple app like posted at the top.
You can even get 1000 FPS, and that's ok, because when app is minimized the drawing is not performed at all. So the issue must be somewhere else.
10-04-2015 03:45 AM
Find all posts by this user Quote this message in a reply
Post Reply