A very simple code profiler


  • Posts: 122
"Profiler" is probably a little too grandiose a name for this behavior, but it'll do.

Ever since I upgraded to 2.0 official, I've had a bizarre resource leak problem in a game that was working fine, before. I suspect it may be a Stencyl bug, but I don't want to assume that until I've exhausted all my options. I've spent the last four or five days trying to track down the problem with no real success. So, I am now going to profile every behavior in my game to see where the time is being spent. To that end, I've written a very simple behavior for timing other behaviors. This behavior is seriously alpha-stage, and I wouldn't normally release such a half-assed behavior to the public, but I don't see anything like it on the Forge, so I am going to go ahead and upload share it.

The behavior is called Nomosoft Scene Profiler, and it works like this:

1) Attach Nomosoft Scene Profiler to a scene in your game.
2) Customize the font, font color, and x/y coordinates where you would like the profiling information to be drawn.
3) Inside the behavior(s) you want to profile, drag in the "Start Profiler" custom block from under "Nomosoft Scene Profiler" on the "Custom" palette. Give the profile a name by filling in the text box on the "Start Profiler" block.
4) Drag the "Stop Profiler" custom block into the bahvior and place it in front of any exit point(s) in your behavior. See the attached screenshot for an example. Make sure to use the same name you did when you started the profiler.

You can use more than one profiler per behavior. So, if you want to profile the entire behavior, you might put "Start Profiler [My Behavior]" and "Stop Profiler [My Behavior]" at the very top and bottom of your behavior's update/draw/whatever function. If you want to profile a sub-section of the function, start another profiler, such as "Start Profiler [My Behavior Targeting Loop]." Remember to Stop Profiler, as well, or you will not get accurate numbers.

Profiling data is displayed on screen in this format:
[Name of profile]: [total milliseconds used] [[average milliseconds per call]]
As of right now, no effort is made to adjust the layout to fit everything on the screen. If you profile too many things at once, they will run off the bottom of your game's window.

Please note, in the screenshot, below, I could have simply started the profiler after the "if active" check, but I wanted to demonstrate how you should stop the profiler before any exit point in your behavior.

« Last Edit: May 02, 2012, 07:59:25 pm by Nomosoft »