# Simple Profiler profile data

This sub-section discusses how to connect the RwFileSystem SimpleProfiler example code to your game code.

First of all you need to add the SimpleProfiler.h/cpp code files to your project. The SimpleProfiler example code can be found in the RwFileSystem package root under "\examples\profiling" (for RwFileSystem versions 1.06.00 and up.)

(Note that the SimpleProfiler example code is purposely not part of the RwFileSystem core library, because it depends on other packages like RwTimer, and we do not want to have this dependency on the library part of the RwFileSystem package.)

Once you have added the SimpleProfiler.h/.cpp code to your project, the first thing to do is to add the include header:

`#include "SimpleProfiler.h"`

Next you need to create an instance of the SimpleProfiler class. In the example code this instance has been made static, because you have to make sure that the instance still exists even after you have set it to the RwFileSystem manager using the "SetEventProfiler" method. If you create a local variable that is destructed when it goes out of scope, you will encounter a crash as soon as the file system calls back into the SimpleProfiler instance for any profile event.

`// Create the SimpleProfiler
static rw::core::filesys::SimpleProfiler profiler;
manager->SetEventProfiler( &profiler );`

From here on you can use the profiler to set tags. Tags can be used to identify the different stages in the loading phase, because all file operations called after the "SetTag" will carry that tag with them. For example: you could have a "CARS" tag when you load all the cars or a "SOUND" tag when you load sounds. Adding tags makes it easier to group the files in the File Profile Analyzer tool, because you are able to sort based on tags. Note that tags are optional and you could omit the tags and still use the tool. To use tags, you can use the following code:

`// This sets the tag that is shown in the File Profile Analyzer
profiler.SetTag( "MAIN" );`

The SimpleProfiler does not want to be intrusive in the profiling process by writing profile data to disc or iostream, hence it only stores the profile data in memory. At some point this needs to be saved to disk (or stream), which you can do by using the following code:

`// Save the profile data
#if defined EA_PLATFORM_PS3
profiler.Save( "/app_home/profile.xml" );
#elif defined EA_PLATFORM_XENON
profiler.Save( "D:\\profile.xml" );
#elif defined EA_PLATFORM_REVOLUTION
profiler.Save(); // This saves to the stdout stream
#else
profiler.Save( "profile.xml" );
#endif`

After saving the profile data you can load the profile data file you saved to in the tool. If you saved it to a stream then you may need to copy/paste the relevant parts from that stream. For the full example code, please refer to the additional resources.

Feedback? Please provide us with your comments on this topic.
For more help, send us an email
© 2007 Electronic Arts. All rights reserved.