Search Unity

How do I debug spikes that happen in the player, without having the profiler interfere?

Discussion in 'Editor & General Support' started by xzbobzx, Dec 14, 2016.

  1. xzbobzx

    xzbobzx

    Joined:
    Apr 7, 2015
    Posts:
    29
    I have a game that runs at a steady 150 fps, vSynced 60 fps. It's perfectly smooth and fine, except for the occasional lag spike that causes a hang that usually lasts between a second and half a second. When running at Vsync, this usually causes the vSync to default to 30fps for another few seconds afterwards.

    Either this is the garbage collector, or it is gfx.waitForPresent (regardless of vSync). They happen randomly and I have absolutely no control over them.

    They happen in the Editor too, and they happen when I autoconnect the profiler to the player build. But the Editor environment is different from the player build, so I'm unsure if what's happening there is correct. And the autoconnected Player profiler makes absolutely sure the game will never run more than 55 fps ever, and all the time jittery and awful, making it very hard to debug and causing whatever I actually find to not be correct. (My game runs at 150 fps, not 55).

    Another thing I tried was having the profiler write to an external file, but this is to no avail, and vSynced or not, it constantly results in it outputting ~150 frames per second. (even when my vSync is running at 30, and even when there are spikes that last a whole second).

    I'm out of options and I'm out of ideas. I can't turn the garbage collector off (not that that would be a good idea), and gfx.waitForPresent always comes absolutely out of nowhere. I have no leads on what causes either of them, let alone how to get rid of them.

    Does anyone know how I'm able to get to the bottom of these spikes, without having the profiler interfere with them? Or does someone know how to fix these spikes?

    I'm clueless, and it's super annoying to constantly run into spikes that ruin gameplay. :(
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    You should profile your game to find exactly what's causing these spikes. This can be a pretty difficult process at times.

    A few guiding questions / suggestions:

    1. Try to find what you're doing that triggers this behaviour - are you performing any special scenario in the game? loading a particular scene or instantiating prefabs ?

    2. If this doesn't happen due to a particular scenario - does it reproduce when you're just idle, e.g: not playing the game and not doing anything special? how often does it happen ?

    3. Did you try to run (in the editor) in "deep profiling" mode? did it show anything interesting ?

    4. Can you post a screenshot (or profiler log capture data) that demonstrate this issue ?

    5. Does the spike last only for 1 slow frame, or occurs for a number of subsequent frames and then goes away ?

    6. Are you generating massive amounts of garbage? (can be seen in the CPU profiler)

    Profiling can sometimes be a slow and painful process but it's the only way of knowing exactly what's going on with your game.