How to find cause of seemingly random slowdown

designpeg

  • *
  • Posts: 689
I've got a game that seems to run fine, but occasionally starts to slow down, until it's running at 2 or 3 fps. I'm having a hard time working out what causes this, as it starts gradually, and builds up, so I'm never sure what action caused the problem.

Is there some way to see what process is using the cpu or drawing to the screen in the logs?

I've tried turning of certain behaviours, but as quite a few are tied together, this is proving difficult.

any advice would be appreciated

Exportforce

  • *
  • Posts: 90
Try to think when it happens, where the code is on the time stuff happens.
Thats the best tactic.

NOTA

  • Posts: 193
Are you killing off actors that are no longer on the scene?

« Last Edit: July 17, 2015, 10:52:47 am by NOTA »

merrak

  • *
  • Posts: 2473
I can think of two possible culprits: Some kind of collision event that happens infrequently and jams the system, or too many actors in certain circumstances. I've had more encounters with the former. You may need to carefully comb through any "Always" and "On Drawing" events, particularly if they have while / do until loops--check the loop breaking conditions. Also check any collision events in your behaviors.

If it's a collision issue, enabling debug draw may reveal why.

Justin

  • *
  • Posts: 4310
What platform are you exporting to? If it's desktop or mobile, you can use a built-in profiler. I've attached an example below. You could set the profiler to start/stop with a button press.

Go to Settings > Settings > Advanced and add the following line to your haxe flags.
Code: [Select]
-D HXCPP_STACK_TRACE
To start/stop the profiler, use the following lines of code.
Code: [Select]
cpp.vm.Profiler.start("");
cpp.vm.Profiler.stop();

To see the results, run the generated executable from a command prompt, or supply a filename when you run the start command.
Code: [Select]
cpp.vm.Profiler.start("log.txt");
If a filename is supplied, it will generate at [workspace]/games-generated/[game]/Export/[desktop platform]/cpp/bin/[filename]. It may be a little different, but that's what I get when I do it for my Windows export

Here's an example of what the results look like.
Code: [Select]
ApplicationMain.main 100.00%/0.00%
   openfl._v2.Lib.create 100.0%
   (internal) 0.0%
extern::cffi 99.99%/0.00%
   openfl._v2.display.Stage.__processStageEvent 100.0%
   (internal) 0.0%
openfl._v2.display.Stage.__doProcessStageEvent 99.99%/0.00%
   openfl._v2.display.Stage.__pollTimers 100.0%
   openfl._v2.display.Stage.__onMouse 0.0%
   openfl._v2.display.Stage.__updateNextWake 0.0%
   (internal) 0.0%
openfl._v2.display.Stage.__processStageEvent 99.99%/0.00%
   openfl._v2.display.Stage.__doProcessStageEvent 100.0%
   (internal) 0.0%
openfl._v2.Lib.create 99.99%/0.01%
   extern::cffi 100.0%
   (internal) 0.0%
openfl._v2.display.Stage.__pollTimers 99.96%/0.00%
   openfl._v2.display.Stage.__checkRender 100.0%
   haxe.Timer.__checkTimers 0.0%
   (internal) 0.0%
openfl._v2.display.Stage.__checkRender 99.92%/0.01%
   openfl._v2.display.Stage.__render 100.0%
   (internal) 0.0%
openfl._v2.display.DisplayObjectContainer.__broadcast 0.13%/0.00%
   openfl._v2.display.DisplayObject.__broadcast 100.0%
   (internal) 0.0%
openfl._v2.display.DisplayObject.__broadcast 0.13%/0.00%
   openfl._v2.display.DisplayObject.__dispatchEvent 100.0%
   (internal) 0.0%
openfl._v2.display.DisplayObject.__dispatchEvent 0.13%/0.01%
   openfl._v2.events.EventDispatcher.dispatchEvent 90.0%
   (internal) 10.0%
openfl._v2.display.Stage.__render 0.13%/99.79%
   (internal) 99.9%
   openfl._v2.display.DisplayObjectContainer.__broadcast 0.1%
com.stencyl.Engine.onUpdate 0.11%/0.00%
   com.stencyl.Engine.postUpdate 100.0%
   (internal) 0.0%
openfl._v2.events.EventDispatcher.dispatchEvent 0.11%/0.01%
   com.stencyl.Engine.onUpdate 88.9%
   (internal) 11.1%
com.stencyl.Engine.postUpdate 0.10%/0.01%
   com.stencyl.Engine.update 75.0%
   com.stencyl.Engine.draw 12.5%
   (internal) 12.5%
com.stencyl.Engine.update 0.06%/0.03%
   box2D.dynamics.B2World.step 66.7%
   (internal) 33.3%
box2D.dynamics.B2World.step 0.04%/0.01%
   box2D.dynamics.B2World.solve 75.0%
   (internal) 25.0%
*._Function_3_1 0.03%/0.00%
   sys.FileSystem.stat 100.0%
   (internal) 0.0%
haxe.Timer.__checkTimers 0.03%/0.00%
   haxe.Timer.__check 100.0%
   (internal) 0.0%
haxe.Timer.__check 0.03%/0.00%
   *._Function_3_1 100.0%
   (internal) 0.0%
box2D.dynamics.B2World.solve 0.03%/0.01%
   box2D.dynamics.B2Body.setActive 66.7%
   (internal) 33.3%
openfl._v2.display.Stage.__onMouse 0.01%/0.00%
   openfl._v2.display.DisplayObject.__fireEvent 100.0%
   (internal) 0.0%
openfl._v2.display.Graphics.drawTiles 0.01%/0.00%
   openfl._v2.display.Graphics.beginBitmapFill 100.0%
   (internal) 0.0%
com.stencyl.models.Actor.drawImage 0.01%/0.00%
   com.stencyl.graphics.SheetAnimation.draw 100.0%
   (internal) 0.0%
com.stencyl.graphics.SheetAnimation.draw 0.01%/0.00%
   openfl._v2.display.Tilesheet.drawTiles 100.0%
   (internal) 0.0%
openfl._v2.display.DisplayObject.__fireEvent 0.01%/0.00%
   openfl._v2.display.DisplayObject.__dispatchEvent 100.0%
   (internal) 0.0%
*._Function_1_1 0.01%/0.00%
   com.stencyl.models.Actor.drawImage 100.0%
   (internal) 0.0%
com.stencyl.Engine.draw 0.01%/0.00%
   *._Function_1_1 100.0%
   (internal) 0.0%
openfl._v2.display.Tilesheet.drawTiles 0.01%/0.00%
   openfl._v2.display.Graphics.drawTiles 100.0%
   (internal) 0.0%
box2D.dynamics.B2Body.setActive 0.01%/0.01%
   box2D.dynamics.B2Fixture.destroyProxy 50.0%
   (internal) 50.0%
openfl._v2.display.Graphics.beginBitmapFill 0.00%/0.01%
openfl._v2.display.Stage.__updateNextWake 0.00%/0.01%
box2D.dynamics.B2Fixture.destroyProxy 0.00%/0.01%
sys.FileSystem.stat 0.00%/0.03%

If you're running mobile, I think you can see the results by not specifying a filename, and viewing your mobile devices debug output.

For Live Support: Join our discord server and ping me @justin.
I'm most often available between 8am and midnight Japan time. (GMT+9)

Justin

  • *
  • Posts: 4310
If you end up trying to profile the code with the above steps, I'd imagine you'll want to share the results for others to look over. If you want to try reading it yourself, here's some info on what the profiling data means.

http://gamehaxe.com/2012/09/14/hxcpp-built-in-debugging/

For Live Support: Join our discord server and ping me @justin.
I'm most often available between 8am and midnight Japan time. (GMT+9)

designpeg

  • *
  • Posts: 689
some great tips, thanks