01. Embedding FlatRedBall Profiler


The FlatRedBall Profiler can be added as part of an existing FlatRedBall PC (desktop) game to provide in-depth, real time performance information. The FlatRedBall Profiler provides the following information:

  • The load time of the last screen (if enabled in Glue)
  • Current render breaks
  • Breakdown of all automatically managed objects.

Adding profiler

The following steps can be used to add the FlatRedBall Profiler to an existing FlatRedBall PC (desktop) project:

Adding FlatRedBall Profiler References

First we’ll need to add the necessary references to the game project:

  1. Right-click on the “References” node in Visual Studio
  2. Select “Add Reference…”
  3. Select the Browse category
  4. Click the Browse button
  5. Navigate to the location of the FlatRedBall Profiler (if you’ve built the profiler from source you will need to select the build folder for the FlatRedBallProfiler instead):
  6. Select “FlatRedBall.PropertyGrid.dll” and “FlatRedBallProfiler.exe” (no need to add FlatRedBall.dll) and click “Add”
  7. Expand the “Assemblies” category and select “Framework”
  8. Select “System.Windows.Forms”
  9. Click OK to close the Reference Manager window

Adding necessary code

Now that the project has the necessary references we’ll add code to launch the FlatRedBall Profiler.

Open Game1.cs and add the following code at the end of Initialize:

Finally, open Program.cs  and add the STAThread attribute to the Main method:

If the STAThread is not added, then your game will throw an exception as shown in the following image:

The profiler will automatically show when the game runs: