Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  CPU usage  (Read 3816 times)
0 Members and 1 Guest are viewing this topic.
Offline Porlus

Junior Member





« Posted 2012-04-30 18:40:01 »

Hi all,

The CPU usage is currently at about 12-32 CPU usage for the java instance for a game I'm making, which seems quite high. I've made quite a bit of the game now and it's quite difficult for me to go through and isolate the source of the leak, although when I disable the tick of my game, the usage doesn't drop that significantly, but when I disable the rendering, it drops to about 8-20 so I was wondering whether there is any program or addon for eclipse that could assist me in finding where I'm going wrong? I would post my code, but it has about 20 classes now. :p

Anyway, in brief, I'm looking for a sort of static analysis program or any tips for reducing CPU usage. :] Please ask to see any section of my program.

Thanks,

Paul
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #1 - Posted 2012-04-30 18:45:14 »

You'll want a profiler like VisualVM ( http://www.oracle.com/splash/java.net/maintenance/index.html ), then you can capture your game running and see where your CPU time is going.

Although 10/30% cpu isn't particularly high - how are you monitoring that? Bear in mind that most user-facing CPU monitors (like Task Manager) are not particularly accurate and may include time your app is actually idle but waiting on drivers/sleep/other.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Porlus

Junior Member





« Reply #2 - Posted 2012-04-30 18:52:08 »

Yeah, I've just been using task manager. But I have been drifting in and out of a few source code samples, as I'm still quite new to 2d game development. I'll give that VisualVM a go, thanks!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline sproingie

JGO Kernel


Medals: 202



« Reply #3 - Posted 2012-04-30 18:53:28 »

VisualVM is good, and if you're using NetBeans, it has a built-in profiler that's also quite nice.  Eclipse has TPTP, which I gave up on, and there's also JVMMonitor which looks quite nice, though I haven't tried it.
Online Riven
« League of Dukes »

JGO Overlord


Medals: 744
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2012-04-30 18:59:36 »

VisualVM is good, and if you're using NetBeans, it has a built-in profiler that's also quite nice.
built-in profiler of netbeans == VisualVM

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Porlus

Junior Member





« Reply #5 - Posted 2012-04-30 19:01:06 »

I'll try that JVMMonitor too then. Thanks mate!
Offline Porlus

Junior Member





« Reply #6 - Posted 2012-04-30 21:28:58 »

Hi again, I've just been using that JVM monitor, which has led me to quite a few problems with my rendering hierarchy. That's taken it from a stable 25-30 CPU usage to about 5-15, which is great. But I keep getting these spikes every few seconds to about 20-25 and at one point it just went back to 30. Is there anything in the CPU tab in JVM that I should be looking out for?

Thanks,

Paul
Offline sproingie

JGO Kernel


Medals: 202



« Reply #7 - Posted 2012-04-30 21:38:57 »

Check your memory graphs: are those spikes coincident with garbage collections? 
Offline theagentd
« Reply #8 - Posted 2012-05-01 04:25:13 »

Another question: How many cores does your computer have? On a hyperthreaded quad core (8 logical cores visible in Task Manager) the maximum utilization you can get is 12.5% without using threads. 12.5% therefore means that you have 100% usage on one core...

Myomyomyo.
Offline Porlus

Junior Member





« Reply #9 - Posted 2012-05-01 06:53:04 »

I've got a duel core processor. What's odd is that sometimes it will appear to have far less CPU usage than other times. Sometimes it stays on average less than 15 and then in other instances it can hover around 25-30.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Porlus

Junior Member





« Reply #10 - Posted 2012-05-01 07:33:06 »

I've just taken out the method call that clears the screen to black before re-rendering as there will be no instance where the previous tiles will show in the current tiles and that's dropped the CPU usage significantly. It's still not quite as low as I'd hoped and it still has a few unexplainable spikes, though. I sort of get the general jist of what these features mean in JVM monitor, but I'm not really sure of how the "Time %" header works in the CPU section. For example, the main render method in my top class appears to use roughly 65%, but if you expand by clicking all the arrows of the methods that are called within that render method, they are much lower than 60% so it doesn't list everything. Does anyone know how to make it list everything?
Online Riven
« League of Dukes »

JGO Overlord


Medals: 744
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #11 - Posted 2012-05-01 16:03:30 »

If you take that 65% and subtract all percentages of the methods it calls, you end up with the percentage that the method itself takes.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline sproingie

JGO Kernel


Medals: 202



« Reply #12 - Posted 2012-05-01 17:12:22 »

If a method takes 65% of your time, all the methods under it add up to 65%.  They're all absolute percentages, not relative to the parent.  Any profiler should have a section when you expand that tells how much of that percentage was spent in the method body itself as opposed to other methods it called.  It is easier to profile when you break things up into smaller methods though.
Offline Porlus

Junior Member





« Reply #13 - Posted 2012-05-02 00:39:57 »

http://i.imgur.com/v5Agk.png

Here's a screenshot of it while it's running. The arrow points at the main render method, which calls all the other render methods, but everything called by that method doesn't seem to add up to 50%
Online Riven
« League of Dukes »

JGO Overlord


Medals: 744
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #14 - Posted 2012-05-02 00:42:22 »

It adds up to 43.5% out of 49.6%.

Close enough.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Porlus

Junior Member





« Reply #15 - Posted 2012-05-02 00:48:19 »

But it adds up to 3.7 D:
Online Riven
« League of Dukes »

JGO Overlord


Medals: 744
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #16 - Posted 2012-05-02 00:49:22 »

self time

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Porlus

Junior Member





« Reply #17 - Posted 2012-05-02 00:56:56 »

Ah, I see. Does anything look worryingly high on there?
Offline sproingie

JGO Kernel


Medals: 202



« Reply #18 - Posted 2012-05-02 00:59:28 »

Impossible to say without seeing the code.  I'd start looking into what in Main.render is taking so much time.
Offline Porlus

Junior Member





« Reply #19 - Posted 2012-05-02 01:10:53 »

Well the main render method calls the level render method, which calls the render methods of all the tiles and mobs within a certain radius. I'd imagine it would take the most time to process. Really what I want to isolate is specifically why the cpu usage fluctuates so erratically.
Offline jammas615

Junior Member


Projects: 1



« Reply #20 - Posted 2012-05-02 03:07:22 »

Not that it'll definitely help, but have you tried stepping through your render method in a debugger?
Sometimes seeing each line of code run can help you see how everything is flowing a what may or may not be unnecessary.

Online Riven
« League of Dukes »

JGO Overlord


Medals: 744
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #21 - Posted 2012-05-02 03:16:49 »

Don't forget that HotSpot will typically inline everything into everything, so that self-time can be the CPU cycles spent in the (inlined) methods it calls.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline sproingie

JGO Kernel


Medals: 202



« Reply #22 - Posted 2012-05-02 05:36:32 »

VisualVM has both sampling and instrumenting profilers; the instrumenting profiler should not be affected by inlining, but does drastically slow down the code being profiled, and if you're doing something like spinning to sync to a framerate, you're unlikely to uncover it when you've slowed down your code.  Always worth trying though if the sampling profiler isn't illuminating the problem.

You may need to enable the JMX agent first using the usual -Dcom.sun.management.jmxremote foofraw in order to use the instrumenting profiler.  Seems to be a windows problem mostly.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (37 views)
2014-07-24 01:59:36

Riven (38 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21

Zero Volt (50 views)
2014-07-17 23:47:54

danieldean (42 views)
2014-07-17 23:41:23

MustardPeter (44 views)
2014-07-16 23:30:00

Cero (60 views)
2014-07-16 00:42:17

Riven (57 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!