Profiling CPU and GPU time

Great stuff, thanks for working on this.

Is there a wiki page? Documentation is good!

rhoooo, Mr Party Breaker… :wink:
I’ll try to make one

1 Like

@nehon when I attach the profiler, I am getting this error :

SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
java.lang.AbstractMethodError: com.jme3.renderer.lwjgl.LwjglGL.glGenQueries(ILjava/nio/IntBuffer;)V
	at com.jme3.renderer.opengl.GLRenderer.generateProfilingTasks(GLRenderer.java:2858)
	at com.jme3.app.DetailedProfiler.poolTaskIds(DetailedProfiler.java:198)
	at com.jme3.app.DetailedProfiler.setRenderer(DetailedProfiler.java:194)
	at com.jme3.app.DetailedProfilerState.initialize(DetailedProfilerState.java:79)
	at com.jme3.app.state.BaseAppState.initialize(BaseAppState.java:124)
	at com.jme3.app.state.AppStateManager.initializePending(AppStateManager.java:251)
	at com.jme3.app.state.AppStateManager.update(AppStateManager.java:281)
	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:236)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
	at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:197)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:232)
	at java.lang.Thread.run(Thread.java:745) 

Can you please help

Mhh IMO you need a clean and rebuild of the engine

1 Like

Really sorry man, It was my stupidness.
I did not notice you also pushed changes to jme3-lwjgl and jme3-lwjgl3 library at first glance.

I also rebuild those two libraries and reinstalled them to maven local, and error gone.

Thanks for the help and sorry for bothering.

No problem :wink:

1 Like

I’ve discovered that this conflicts with BasicProfilerState.
So you do either:

                stateManager.attach(new DetailedProfilerState());

OR

                stateManager.attach(new BasicProfilerState(true));
1 Like

ha yes probably

Found a bug: I have a thingy that allows me to toggle debug overlays on and off, including your awesome profiler state. But, as soon as I did that multiple times, fonts start to overlap (almost like something isn’t working with the removal). Aka I get multiple different CPU and GPU times right on top of each other.

Action handler is here:

if(name.equals("Debug") && !isPressed)
{
    if(profilerDisplayLevel < 3)
    {
        profilerDisplayLevel++;
    }
    else
    {
       profilerDisplayLevel = 0;
    }
        
    if(profilerDisplayLevel == 1)
    {
        if(!stateManager.hasState(statsState))
        {
            stateManager.attach(statsState);
        }
    }
    else if(profilerDisplayLevel == 2)
    {
        if(!stateManager.hasState(detailedProfilerState))
        {
            stateManager.attach(detailedProfilerState);
        }
    }
    else if(profilerDisplayLevel == 3)
    {
        bulletAppState.setDebugEnabled(true);
    }
    else
    {
        if(stateManager.hasState(statsState))
        {
            stateManager.detach(statsState);
        }
        if(stateManager.hasState(detailedProfilerState))
        {
           stateManager.detach(detailedProfilerState);
       }
       bulletAppState.setDebugEnabled(false);
    }
}

This is at the top of the class:

private StatsAppState statsState;
private DetailedProfilerState detailedProfilerState;

Here’s an image:

Are you attaching them and detaching them or enabling and disabling them?

It sounds like a bug either way but that will help nehon narrow down which method isn’t cleaning itself up properly.

I reproduce the issue if I attach detach and reattach again the profiler state.
I’m gonna fix the issue, some cleanup must be done, but you should definitely consider using setEnable(false) instead of detaching the state. This way the state won’t reinitialize each time you toggle it on.

2 Likes

That disables the display as well? Didn’t know I could do that. I’ll enable and disable it then, thank you!

Yep it detaches the profiler ui node from the GUI Node.
enable re attaches it.

1 Like

Just tested it, that works. Thanks!

Sorry to revive an old topic. I just thought I’d keep all the DetailedProfiler discussion in one place.

I find that I get an exception when I add DetailedProfilerState and enable assertions.

I can reproduce this with the simplest of applications:

@Override
public void simpleInitApp() {
    stateManager.attach(new DetailedProfilerState());
}

Without -ea, it works fine. With -ea, I get the following exception:

org.lwjgl.opengl.OpenGLException: Invalid operation (1282)
	at org.lwjgl.opengl.Util.checkGLError(Util.java:59)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.checkGLError(LwjglAbstractDisplay.java:136)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:157)
	at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:197)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:232)
	at java.lang.Thread.run(Thread.java:748)

From what I can tell looking at the code, LwjglAbstractDisplay.runLoop only calls checkGLError if assertions are enabled:

assert checkGLError();

I found this forum post (glGetError() returning “invalid operation” before I do anything…) where someone says that glGetError() returns 1282 if the GL context is not current or not yet created. I don’t know what that means exactly, but, it implies that something’s being done in the wrong order, rather than something actually being wrong with the graphics.

2 Likes

This is a known issue:

Got it. Thank you. :+1:

1 Like