• 15
• 15
• 11
• 9
• 10

CPU Usage FPS

This topic is 2641 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Using JOGL, I noticed my computer getting fairly noisy when I test my game (though it does very little right now), just drawing a few polygons. I was using Animator which I think makes the program run as fast as possible, so I changed to FPSAnimator and set it to 60 because I thought 60FPS was usually what people want in a game, but it was still doing about the same amount of CPU Usage in task manager (going between 40% and 60%). Then I tried changing it to 30 and the cpu usage dropped significantly, it was going between 10% and 25% which seemed more reasonable. Finally I changed it to 1 and then cpu usage dropped to 0.

I'm just wondering should I be using FPSAnimator, is there some standard for FPS, I thought it was 60 but maybe I'm wrong. Should I be worried about CPU Usage going up to 50%? Also, is there anything else I should look into that might be causing CPU Usage to jump up? Thanks.

Share on other sites
often games are restrictet to max 60 fps, because they use vsync which snycs the drawing of a frame with the monitor, which decreases tearing. When u just limit the frame rate to a "random" number, you will just slow down your rendering.

use "gl.setSwapInterval(1)" with JOGL to activate VSync.

For my part, I use the standart Animator for normal desktop mode of my app, I use the FPSAnimator class only when running as an applet cause the Animator class don't work that well as an applet(don'T know why).

About your CPU usage problem, have u tried setting the following flag to false?

Animator a = new Animator(drawable);a.setRunAsFastAsPossible(false);

also do you have any "while(true)" loops in your code? I'm asking, becasue I set the above flag to true in my app and doing a lot of things and use onyl 5-10% of the CPU.

And if this also don't help, you have to profile your programm and see which part of your code produces the overheat, you properly just use some very expensive algorithm or do a lot of object allocation.

Share on other sites
I have gl.setSwapInterval(1). I just tried changing it back to Animator with setRunAsFastAsPossible(false) and it didn't seem to make any difference. I don't have any while(true) loops. I just ran the program without even adding anything to the canvas (so it's just a black window), basically the entire program right now is just the main containing the following:

Frame frame = new Frame("Game");
GLCanvas canvas = new GLCanvas();
frame.setSize(1024, 768);
final Animator animator = new Animator(canvas);
animator.setRunAsFastAsPossible(false);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
animator.start();
canvas.requestFocus();

I've got javaw.exe doing about 50% CPU usage from just that. I don't really know what profiling my program means or how to go about doing that (is it just commenting out blocks of code?), but I think at least there's a problem outside of the meat of my program.

Share on other sites
IDEs like Netbeans or Eclipse have profiling tools, who tell you which part of your code took the longest to execute, or other things like memory consumption and so on.

besides that, u should find in your jdk/bin folder the jvisualvm app which can sometimes profile running java apps(don't know which java version is required but with new newest it should be there)

Share on other sites
I think it's pretty clear that it's the animator though. Anyways I ran Java VisualVM, I'm not really sure what I should be looking for, but I went to my game's process, then I went to the profiler tab and clicked on CPU. I had 2 methods that were taking up most of the self time, I'm not entirely sure what that is though. Using FPSAnimator at 30FPS it showed:
com.sun.opengl.util.FPSAnimator$1.run() Self Time: 51% javax.media.opengl.GLCanvas$DisplayOnEventDispatchThreadAction.run()
Self Time: 45%
javax.media.opengl.GLCanvas$DisplayAction.run() Self Time: 4% Doing the same thing with Animator and setRunAsFastAsPossible(false) it showed: javax.media.opengl.GLCanvas$DisplayOnEventDispatchThreadAction.run()
Self Time: 98%
javax.media.opengl.GLCanvas$DisplayAction.run() Self Time: 2% Again with Animator, but with setRunAsFastAsPossible(true) it showed: javax.media.opengl.GLCanvas$DisplayOnEventDispatchThreadAction.run()
Self Time: 99%
javax.media.opengl.GLCanvas$DisplayAction.run() Self Time: 1% If I run it without adding anything to the canvas with Animator and setRunAsFastAsPossible(false) I get: javax.media.opengl.GLCanvas$DisplayOnEventDispatchThreadAction.run()
Self Time: 100%

I'm not sure if this is important but every time the invocations updated for the DisplayOnEventDispatchThreadAction it jumped up about 150 with Animator (with setRunAsFastAsPossible as true and false, it didn't really make a difference). With The FPSAnimator at 30FPS it was going up by about 75 invocations each update.

Share on other sites
mm, this doesn't show anything new. The Animator just try to draw a many frames as possible. What one usually wants, but in this case it fries the CPU :-)

What happens if u give the graphic card something to do, is it sill up the CPU usage?

Last question what hardware are u running on?

Share on other sites
I wasn't exactly sure what to do to give my graphics card something else to do, I ran a game (Heroes of Newerth) which took up about 25% CPU usage, then I ran my game with Animator and it still takes up 50%. I added Thread.sleep(10) and it didn't seem to make any difference, the usage was still at 50%.

I've got 3GB ram, 3GHz processor, and nvidia geforce 8600 GTS.