The Save function can be used to save a Section instance (and all of its contained sections) to an XML file. Saving a Section can be helpful in a number of situations:
To save a snapshot of performance before making changes so that the effectiveness of the changes can be measured
To send a file to another developer for assistance in improving performance
To save a file from a device (such as Android or iOS) for viewing on a PC
The following code can be used to save on Android:
This will save to the following folder:
This file can be accessed using the FS File Explorer app on Android.
The GetAndStartContextAndTime method can be used to create a new Section instance for timing. If called multiple times, then the newly-created section will be added as a child of the section created on the previous GetAndStartContextAndTime call.
The following code shows how to create multiple sections. This code intentionally sleeps the thread to keep the sample as simple as possible.
This code produces the following string in the result variable:
Notice that GetAndStartContextAndTime is a static method. This method, along with EndTimeAndContext, can be called from the static Section class, so your code does not have to keep track of the created sections. However, the top-level section is used to report the timing information using ToStringVerbose, so the code above preserves a reference to the return value for the first GetAndStartContextAndTime call.
Section internally uses the TimeManager's Stopwatch class to perform timing. Therefore, to use GetAndStartContextAndTime, you must either:
Call this method after FlatRedBallServices.InitializeFlatRedBall
Manually call TimeManager.InitializeStopwatch
Section is a class which can be used to measure and report performance in FlatRedBall. It has the following features/benefits:
Supports a tree structure so that sections can be sub-divided.
Supports a context system so different sections of code can create sections without requiring managing and passing around references
Can be serialized to a compact XML file.
Supports being loaded in the FlatRedBall Profiler.
The following shows the simplest way to time a section and print the result. Add the following using statement:
If you add this code to an Update or Activity function it will be called every frame, so you will want to add it to your game's Initialize or a Screen's CustomInitialize:
ToStringVerbose will return information about the Section that the function is being called on. This can be used to get information about the Section in a human-readable format similar to XML.
You can use the depth parameter to limit how much information is being displayed. The following shows how this works:
For more information on CommandLineWrite, see the CommandLineWrite page.
For an example on how to use ToStringVerbose in combination with Glue, see .